Add AMP Analytics Script
Ensure to include the script in all of your AMP pages in the<head> section of your .amp file where you want to use AMP analytics and track user attributes and events.
Add Anywhere in your HTML
Note Ensure to replace Your_Workspace_ID with the actual Workspace Id from MoEngage Dashboard -> Settings -> Account -> General Settings For dataCenter, please contact our support team to know more.
Note To redirect data to test environment, append ‘_DEBUG’ to appId. For example, if your appId is
YOUR_WORKSPACE_ID then for test environment, it would be YOUR_WORKSPACE_ID_DEBUG
YOUR_WORKSPACE_ID then for test environment, it would be YOUR_WORKSPACE_ID_DEBUG
Tracking Users
All the users visiting your AMP pages will be tracked automatically once you followed the above steps.But these users will be anonymous users by default.
However, if any user of your website who visited your normal HTML pages earlier and has not deleted their cookies, will be treated as the same user in AMP pages also.
Tracking Events
Page Viewed event is tracked by default if you followed the above steps.However with AMP framework limitations on event tracking, only a few kinds of events can be tracked such as
Page Viewed, Element Clicked, Page Scroll.
For more information on the list of events, refer to AMP Analytics Examples.
Example 1: Element Click Event
You can track a Click Event when an HTML element with idtest is clicked as described:
Example 2: Page Scroll Event
scrollSpec object, that contains verticalBoundaries and horizontalBoundaries. At least one of the two properties is required for a scroll event to fire. The values for both of the properties should be arrays of numbers containing the boundaries on which a scroll event is generated. For instance, in the following code snippet, the scroll event will be fired when the page is scrolled vertically by 25%, 50% and 90%. The attributes sent here is scrolledUpto which holds an inbuilt variable scrollTop that provides the number of pixels that the user has scrolled from the top.
For more information about the list of all supported variables, refer to Supported Variables.
Example 3: Form Submit Event
Tracking User Attributes
You can track user attributes using the “EVENT_ACTION_USER_ATTRIBUTE” event. For example, you have this button on your website:["blue","green","red"]