AMP Analytics
Step-by-step guide to send your event data from your AMP page to RudderStack.
Last updated
Was this helpful?
Step-by-step guide to send your event data from your AMP page to RudderStack.
Last updated
Was this helpful?
The RudderStack AMP component makes it easy to send the event data from your AMP page to your specified destinations via RudderStack. Now you don't need to implement or test multiple components for different destinations for your event data. This component collects the default properties and sends a page
event to RudderStack.
Since the AMP source sends the data directly to the RudderStack backend, it supports only the cloud mode destinations. For more information on the cloud mode, refer to the guide.
To use the AMP component, the following prerequisites must be met:
You must have signed up for a .
You need a data plane URL. Follow for more information on the data plane URL and where to get it.
Learn more about the AMP project from their . To get started and set up your AMP project, check out their .
After completing the initial setup of your AMP project, follow these steps to start sending your event data to RudderStack:
Add an AMP source in your RudderStack .
Note the Write Key. This will be required later when using the AMP Analytics component.
Include the RudderStack AMP component before the closing </head>
tag, as shown:
Start sending the event data to RudderStack by adding the following script inside of your <body>
tag.
You can fetch the AMP config JSON from our . The following snippet shows you how to do this:
You can record the page views on your website using the page
request. To add custom properties to your page request, you can use the extraUrlParams
object.
RudderStack's AMP analytics component includes an automatic page view. You can set the name of the automatic page view through pageName
, as shown in the following snippet:
If you fail to provide the value for the pageName
variable, RudderStack automatically sets the page name to Unknown Page
.
You can send extra properties for your page
or track
events to add more information along with the event request. Once you mention the properties as extraUrlParams
in the amp-analytics
tag of your implementation, they will be passed to RudderStack for further processing.
RudderStack collects the following properties with each track
and page
view:
You can choose to send custom properties by adding the extraUrlParams
object. Every property name should be prefixed with properties.
.
A sample call with the custom properties is shown below:
Any property set at the top-level extraUrlParams
object will be sent with each request. For example, the property article_id
will be sent for all the requests triggered by this snippet.
If you want to add custom properties to a specific event or a page
call, you need to add an extraUrlParams
object within your trigger configuration. The following code snippet shows how to do so:
The property clickType
will be sent only for the track
request, whereas the property article_id
will be sent for both the requests (the automatic page
and track
call).
RudderStack does not collect the UTM information from the SDK. Instead, we encourage you to send the properties as extraUrlParams
.
An example of using extraUrlParams
is as shown:
Once this cookie is set, both AMP and Non-AMP pages on your domain use this cookie to identify the user uniquely. This way, the same AMP Client ID (set by the cached AMP page) can be used to identify the user in all contexts.
The following code snippet demonstrates how to enable this feature:
Refer to the section on for more details.
You can record any user event on your website using the track
request, or create a to do so. You need to set the event's name in the trigger's variables, as shown in the code snippet below:
Prepend properties.
to the property name within the extraUrlParams
object so that it can be parsed as the property value in RudderStack. For more information, refer to the section below.
You can use the feature to ensure a merged session for users navigating from cached AMP pages (on an AMP cache) to AMP pages on your domain. When a user navigates from a cached AMP page to an AMP page on your domain, the linker sends the current AMP ClientID
by adding a URL parameter to the outgoing link. The AMP page on your domain receives this parameter and uses it to set a first-party cookie.
You can also use the query parameter from the decorated outgoing link from an AMP cache page to a non-AMP page on your domain by using the .
For queries on any of the sections covered in this guide, you can or start a conversation in our community.