Tracking Events

Tracking events is how you record any actions your users perform, along with any properties that describe the action. Every track_event call records a single user action. We recommend that you make your event names human-readable, so that everyone on your team can know what they mean instantly.

You can track an event using track_event with the event name and it's characteristics (attributes/properties).

Track Event

Moengage.track_event("EVENT_NAME_1");       // This event has no attributes

// Track events with additional attributes
Moengage.track_event("EVENT_NAME_2", {
    "attribute_1": "value_1",               // string value
    "attribute_2": 2,                       // numeric value
    "attribute_3": 3.4,                     // numeric value
    "attribute_4": new Date(2017, 0, 31),   // datetime value. Example value represents 31 January, 2017. 
});

Add all the additional information which you think would be useful for segmentation while creating campaigns. For eg. the following code tracks a purchase event of a product. We are including attributes like amount, quantity, category which describe the event we are tracking.

Moengage.track_event("Purchase", {
  "quantity":2,
  "product_name":"Ipad mini",
  "price": 599.99,
  "currency": "USD"
});

Please make sure that you are tracking event and user attributes without changing their data types. For instance, in the above purchase event, amount and quantity are tracked in the numeric form. Our system detects the data type automatically unless you explicitly specify it as a string.

In case you are using Google Tag Manager, refer to this section.

You can now proceed to track user attributes for your Website users.

Event tracking via Google Tag Manager (GTM)

You can also place the above function as a Custom HTML Tag inside GTM. This Tag can be fired once per event and triggered on the elements where you wish to track website events. The event attributes can be picked up from GTM Data Layer.

Non-Interactive Event

Events that should not affect the session duration calculation in anyways in MoEngage Analytics should be marked as a Non-Interactive event.

These events:

  • Do not start a new session, even when the app is in the foreground
  • Do not extend the session
  • Do not have information on source and session

For example, events that are tracked when the app is in the background to refresh the app content, these are not initiated by users and hence can be marked as non-interactive. To mark an event as non-interactive send moe_non_interactive: 1 while tracking the event as shown below:

Moengage.track_event("App Content Refreshed", {"NewsCategory": "Politics", "moe_non_interactive": 1})

📘

Default Data

These are the default data collected by SDK. Please go through this before adding any events:

https://help.moengage.com/hc/en-us/articles/360042954831-Default-Web-SDK-Data-Collection