Tracking Events 7.x.x

Event tracking is used to track user behavior in an app. And later based on the same tracked behavior you can target those users for sending relevant notifications. Make sure to track all the events relevant to your business, so that your product managers and marketers can segment your app users and create targeted campaigns. For eg. You can track what a user is purchasing, whether a user added an item to the cart etc.


Default SDK Events

We track certain events by default in our SDK, so please make sure to use the default events instead of tracking a new event for the same scenarios. Find the list of default events tracked by SDK here.

How to track events?

Every event has 2 parts to it, the "name" of the event and the properties/attributes of the event. You have to make use of MOProperties to track events and their attributes.

For eg. The following code tracks an Successful Purchase event. We are including attributes like the Product Name, a Brand Name that describes the event we are tracking.

Swift Objective-C
let eventAttrDict = NSMutableDictionary()
eventAttrDict["ProductName"] = "iPhone XS Max"
eventAttrDict["BrandName"] = "Apple"
eventAttrDict["Items In Stock"] = 109

let eventProperties = MOProperties.init(attributes: eventAttrDict)

eventProperties.addAttribute(87000.00, withName: "price")
eventProperties.addAttribute("Rupees", withName: "currency")
eventProperties.addAttribute(true, withName: "in_stock")
eventProperties.addDateEpochAttribute(1439322197, withName: "Time added to cart")
eventProperties.addDateISOStringAttribute("2020-02-22T12:37:56Z", withName: "Time of checkout")
eventProperties.addDateAttribute(Date(), withName: "Time of purchase")

eventProperties.addLocationAttribute(MOGeoLocation.init(latitude: 12.23, andLongitude: 9.23), withName: "Pickup Location")
MoEngage.sharedInstance().trackEvent("Successful Purchase", with: eventProperties)

Non-Interactive Events

Events that should not affect the session duration calculation in anyways in MoEngage Analytics should be marked as a Non-Interactive events. Refer to this for more info on the same.

Ensure that you are tracking event attributes without changing their data types. Also, make sure the attributes have the same data type across platforms. For instance, in the above purchase event, price is tracked in the numeric form, therefore when the same event is tracked in Android SDK make sure to track it as a number and not a string. Our system detects the data type automatically unless you explicitly specify it as a string.



  • Event names and attributes should not contain any special characters other than "_". It can contain spaces and underscore.
  • In the SDK we reject events with invalid event attributes. Event attribute values can only have Strings, Numbers & an array(strings or numbers), or else events might get rejected.

If you don’t have any attributes, just pass nil as the second argument. For eg.

Swift Objective-C
MoEngage.sharedInstance().trackEvent("Event Name", with: nil)

Manual Sync

For syncing the tracked events instantaneously, use the syncNow: method as shown below:

Swift Objective-C

Change Periodic Flush Interval

By default, SDK performs a periodic flush(syncing the events tracked in the SDK) once every 60 sec. In case if you want to update the periodic flush interval, use setFlushInterval: method as shown below to provide a new interval in the number of seconds:

Swift Objective-C

Disable Periodic Flush

To disable periodic flush made every 60 sec from the SDK use disablePeriodicFlush: method as shown below:

Swift Objective-C

Testing events after integration

Login to the MoEngage account with the credentials provided for your app.

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

After adding event tracking in the app, as shown above, you can visit MoEngage Dashboard > For Developers >  Recent Events to check whether the events are being tracked.

Events can take up to 20 minutes to show up in the dashboard

While testing it is recommended to enable logs in Debug Mode.

SDK prints a list of all events which are synced in the current flush, so you can always refer to the logs to check if the events tracked by you are being sent to the backend or not. Also, logs provide info about if the sync with the backend was successful or not. (In case it is unsuccessful, SDK saves all the tracked events and attempts to sync again in the next flush attempt)



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

How can we improve this article?