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
NoteEnsure to replace Your_Workspace_ID with the actual Workspace Id from MoEngage Dashboard -> Settings -> App -> General SettingsFor dataCenter, please contact our support team to know more.
NoteTo 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"]
Tracking User Login and Logout
Previous way of logging-in users has been changed. The below method follows the User Identity Resolution feature of MoEngage. Learn More. Ensure log in and log out of users are implemented correctly during the visit to your website and users are authenticated.Track Login
uid is ID and u_em is Email (Standard) attributes. Please refer to the below table for key names which need to be used to set standard user attributes as identities.
If we want to identify the user with just mobile number (for example)-
NoteHere, we do not have to send the value of mobile number in
identifiers -> moe_user_id as Mobile and ID are two different attributes of a user. Only while adding/updating ID, the value of the ID has to be sent in moe_user_id as well as in user_identities.Track Identities Update
When updating the value of an identity, send the changed identities inidentifiers -> previous_identities.
For example, let’s assume you first set ID and Email as identities of the user.
NoteIn the above example, we updated ID. You can update more than one identities but you have to mandatorily send all the changing identities in
previous_identities.