MoEngage Docs

Track Event

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 it's characteristics (attributes/properties). Make sure you have implemented Activity Tracking before you can track an event.

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, category which describe the event we are tracking.

PayloadBuilder builder = new PayloadBuilder();
builder.putAttrInt("quantity", 2)
  .putAttrString("product", "iPhone")
  .putAttrDate("purchaseDate", new Date())
  .putAttrDouble("price", 5999.99)
  .putAttrString("currency", "dollar");
MoEHelper.getInstance(mCurrentContext).trackEvent("Purchase", builder.build());

mCurrentContext - context instance, please change the name accordingly

Naming Restrictions

Event names should not contain any special characters other than "_". It can contain just spaces and underscore

Also it should not contain “between”, “greater”, “less”, “in_the_last”, “in_the_next”, “equal”, “contains”, “starts”, “is_not", "action".

Please make sure that you are tracking event 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.

Tracking User Location

PayloadBuilder builder = new PayloadBuilder();
builder.putAttrLocation("userLocation", 40.77, 73.98);

MoEHelper.getInstance(mCurrentContext).trackEvent("lastSeen", builder.build());

Testing Events

Login to the MoEngage dashboard

Look at top left and Switch to Test environment. Ensure that your testing is done on the test environment to keep the test data separate from the Live data.

After adding event tracking in the app as shown above, you can visit Recent Events link and check whether the events are being tracked.

Events are sent as a batch when your app goes to background.