Skip to main content
MoEngage AMP event analytics plugin helps in track user attributes and events, and run third-party javascript. MoEngage AMP event analytics plugin ensures to address the differences in AMP pages and HTML page restriction for tracking user attributes and events. The MoEngage AMP event analytics plugin is different from the AMP analytics module.
ImportantFrom Web SDK v2.81.01, set request to eventV2 in your triggers. The legacy event request is deprecated and will be removed in a future update. Migrate your existing triggers to eventV2: move the event name from e to viewsInfo[].EVENT_ACTION, and move the attributes from a to viewsInfo[].EVENT_ATTRS.On Web SDK versions below v2.81.01, continue to use event.
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.
To add event tracking and user attribute tracking to your AMP pages follow these steps-

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

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.
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 id test is clicked as described:

Example 2: Page Scroll Event

The scroll event needs 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

In the above example, we are setting the id of the form as the selector value (#testForm). Inside 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

ImportantIf any user attribute is configured as an identity for your account, then track it as part of login instead of simply tracking it as a user attribute as it is shown in this section. Refer to this document to learn more.
You can track user attributes using the EVENT_ACTION_USER_ATTRIBUTE event. For example, you have this button on your website:
Then, track the first name (considering it to be the user’s first name) like this:
Similarly, to track the user’s email upon clicking the below button
In the same way, you can track other pre-defined user attributes
Here, USER_ATTRIBUTE_NAME has to be replaced with one of the following
To track a custom user attribute, in place of USER_ATTRIBUTE_NAME you have to use your own custom attribute name. For example-
In the above example, we are tracking a custom attribute named “colors”. This attribute’s value is an array- ["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. 
ImportantIf the user log in and log out is not handled correctly, user data may get corrupted. Refer this section for more details.

Track Login

Here, we want to track ID “someUniqueId” and Email “[email protected]” as the identities for the user.
ImportantIf you are setting the ID, make sure to add/update its value in both identifiers -> moe_user_id as well as inside identifiers -> user_identities
Here, 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.
ImportantAfter you track the login, include the identifiers object (with moe_user_id and/or user_identities) in every subsequent trigger’s extraUrlParams, until you perform a logout. The vendor config sends identifiers: {} (empty) by default, so you must override it with the user’s actual identities in each post-login trigger. Otherwise, MoEngage does not associate those events with the logged-in user in your dashboard.
For example, if we want to track an event after identities have been set for the user-

Track Identities Update

When updating the value of an identity, send the changed identities in identifiers -> previous_identities. For example, let’s assume you first set ID and Email as identities of the user.
Now, let’s say you want to update the ID 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

ImportantAfter you perform the MoEngage logout event, do not include a custom identifiers object in any further trigger. The vendor config continues to send the default empty identifiers: {}, which correctly disassociates subsequent events from the logged-out user. Adding a custom identifiers block after logout risks associating events with the wrong user.

Batching Events

You can send multiple events in a single HTTP request by placing them all inside one trigger’s viewsInfo 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.
In this example, ${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
Automatic Cross-Trigger Batching Not SupportedAMP’s built-in batchInterval collects firings from separate triggers and flushes them as a top-level JSON array, with one object per firing. The MoEngage /v2/sdk/report endpoint does not accept a top-level array body — it expects a single JSON object. Do not use batchInterval, since it results in rejected requests. Use the manual multi-event trigger pattern above instead for events that always co-occur.