Tracking Events 11.x.x

Tracking events is how you record any actions your users perform, along with any properties that describe the action. Every trackEvent 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 trackEvent with the event name and its characteristics (attributes/properties).

Every event has 2 attributes, action name, and key, value pairs which represent additional information about the action. 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, a category that describes the event we are tracking.

Kotlin Java
    val properties = Properties()
    properties
        // tracking integer
        .addAttribute("quantity", 2)
        // tracking string
        .addAttribute("product", "iPhone")
        // tracking date
        .addAttribute("purchaseDate", Date())
        // tracking double
        .addAttribute("price", 5999.99)
        // tracking location
        .addAttribute("userLocation", GeoLocation(40.77, 73.98))
    MoEHelper.getInstance(context).trackEvent("Purchase", properties)

context - context instance, change the name accordingly.

Ensure that you are tracking event attributes without changing the data types. For example, in the purchase event, amount and quantity are tracked in numeric form. MoEngage detects the data type automatically unless you explicitly specify it as a string.

The SDK by default tracks a certain set of commonly used events, make sure you use those events instead of tracking similar events again. Refer to the documentation to know more about the default events tracked by the SDK.

Analytics

MoEngage SDK version 9.7.01 and later tracks user session and application traffic source.

For more information, refer to Sessions in MoEngage Analytics and Source Analysis in MoEngage Analytics.

User session tracking provides the flexibility to selectively mark events as non-interactive.

Non-interactive event

Events that do not affect the session duration calculation in MoEngage Analytics are marked as Non-Interactive events.

The following are considered non-interactive 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

An event is marked as non-interactive using the setNonIteractive() in the PayloadBuilder provided by the SDK to build event attributes.

For example,

Kotlin Java
    val properties = Properties()
    properties.addAttribute("quantity", 2)
        .addAttribute("product", "iPhone")
        .addAttribute("purchaseDate", Date())
        .addAttribute("price", 5999.99)
        .addAttribute("currency", "dollar")
        .setNonInteractive()
    MoEHelper.getInstance(context).trackEvent("Purchase", properties)

Track Custom Event for Exit Intent

MoEngage SDK optionally notifies the application whenever the goes to the background. The application can track the custom event in this callback for exit intent. To get notified implement the AppBackgroundListener.
Register the listener in the onCreate() of your Application class using MoECallbacks.getInstance().addAppBackgroundListener().

Was this article helpful?
0 out of 0 found this helpful