Integrations that reference the Web SDK by major version (
sdkVersion = "2") receive eventV2 support automatically. Integrations that pin a specific release require v2.81.01 or above. For more information, see Upgrading the SDK.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.
The MoEngage vendor config automatically includes
identifiers and meta in every request. You do not need to add them to your trigger configurations. Only add a custom identifiers object when tracking login events, to associate the request with a specific logged-in user.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
viewsInfo, EVENT_ACTION is the event name and EVENT_ATTRS contains the key and the value which we want to track for this event.
Tracking User Attributes
You can track user attributes using theEVENT_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.Track Logout
Batching Events
You can send multiple events in a single HTTP request by placing them all inside one trigger’sviewsInfo array. Set viewsCount to the number of events and add each event object to viewsInfo. Use this pattern for events that always co-occur — for example, when one click should track both Add To Cart and Product Clicked in one request.
NoteThis approach works because you author both events inside a single trigger at config time. AMP fires the trigger once and sends all events together. This differs from automatic cross-trigger batching (grouping separate trigger firings into one request), which MoEngage does not support — see the note below.
${productId}, ${price}, and ${category} resolve from the data-vars-product-id, data-vars-price, and data-vars-category attributes on the clicked element.
MoEngage receives the following request body:
JSON