Method 1: Use the <amp-analytics>
tag with the "adobeanalytics"
template
The "adobeanalytics"
tracking template uses the <amp-analytics>
HTML tag to construct a tracking request directly. You can specify hit requests that fire on specific page events, like the page becoming visible or on a click. Click events can be customized to apply to certain element IDs or classes by specifying a selector. You can load the template by adding type="adobeanalytics"
to the amp-analytics tag.
In the following code example, there are two triggers defined: pageLoad
and click
. The pageLoad
trigger fires when the document becomes visible and includes the pageName
variable as defined in the vars
section. The second trigger click
fires when a button is clicked. The eVar1
variable is set for this event with the value button clicked
.
<amp-analytics type="adobeanalytics">
<script type="application/json">
{
"requests": {
"myClick": "${click}&v1=${eVar1}",
},
"vars": {
"host": "example.data.adobedc.net",
"reportSuites": "reportSuiteID1,reportSuiteID2",
"pageName": "Adobe Analytics Using amp-analytics tag"
},
"triggers": {
"pageLoad": {
"on": "visible",
"request": "pageview"
},
"click": {
"on": "click",
"selector": "button",
"request": "myClick",
"vars": {
"eVar1": "button clicked"
}
}
}
}
</script>
</amp-analytics>
The <amp-analytics>
tag supports variable substitutions so that AMP can provide data values that it is aware of. See variables supported in amp-analytics
on GitHub for more information.
Adobe identifies visitors using a built-in AMP function, and sets the cookie adobe_amp_id
. This visitor ID is unique to any other ID set by Adobe Analytics. A different unique visitor is counted for each CDN that a visitor retrieves content from, which can inflate unique visitor count. Using a separate report suite for AMP pages is highly recommended because of how AMP identifies unique visitors. The Adobe Experience Cloud ID Service is not supported.
This solution requires that the tracking server you specify in the host
property matches the tracking server on your main site, so that your existing privacy policy controls are respected. Otherwise, create a separate privacy policy for pages using AMP.