Skip to main content

Event tracking guide

You need to be aware of your users' behaviour on your platforms in order to understand them. Some behaviour is automatically detectable, other events need work from the app developer to track.

Many of these methods have analogous events in a server-to-server API called the Ometria Data API, and through a separate JavaScript API.

Be aware

If your business already integrates with Ometria in any way, it is very important that the values sent here correspond to those in other integrations.

E.g., the customer identified event takes a customer ID - that ID must be the same here as it is in the data API.

The events are merged on Ometria's side into one big cross-channel view of your customer behaviour, which will otherwise get very messy.

Manually tracked events

Once the SDK is initialised, you can track an event by calling its dedicated method:

let myItem = OmetriaBasketItem(
productId: "product-1",
variantId: "variant-product-1",
sku: "sku-product-1",
quantity: 1,
price: 12.0)
let myItems = [myItem]
let myBasket = OmetriaBasket(id: "basket-id", totalPrice: 12.0, currency: "USD", items: myItems, link: "http://sample.link.com")

Ometria.sharedInstance().trackBasketUpdatedEvent(basket: myBasket)

See the following guides for details on each event type:

For the Deep link opened event, see Deep Linking.

Automatically tracked events

The following events are automatically tracked by the SDK.

Linking and initialising the SDK is enough to take advantage of these; no further integration is required.

EventDescription
Application installedThe app was just installed. Usually can't be sent when the app is actually installed, but instead only sent the first time the app is launched.
Application launchedSomeone has just launched the app.
Application foregroundedThe app was already launched, but it was in the background. It has just been brought to the foreground.
Application backgroundedThe app was in active use and has just been sent to the background.
Push token refreshedThe push token generated by Firebase has been updated.
Notification receivedA Push notification was received by the system.
Notification interactedThe user has just clicked on / tapped on / opened a notification.
Error occurredAn error occurred on the client side. We try to detect any problems with actual notification payload on our side, so we don't expect any errors which need to be fed back to end users.

Flush tracked events

In order to reduce power and bandwidth consumption, the Ometria library doesn't send the events one by one unless you request it to do so.

Instead, it composes batches of events that are sent to the backend during application runtime when the one of the following happened:

  • it has collected 10 events or
  • there was a firebase token refresh (pushtokenRefreshed event)
  • a notificationReceived event (this is not reliable on iOS as the OS prevents the app from knowing about this)
  • an appForegrounded event
  • an appBackgrounded event

You can request the library to send all remaining events to the backend whenever you want by calling:

Ometria.sharedInstance().flush()

Clear tracked events

You can completely clear all the events that have been tracked and not yet flushed.

To do this, call the following method:

Ometria.sharedInstance().clear()

Debugging events

To see what events were captured, you can check the logs coming from the Ometria SDK, if logging is enabled. You can filter for the word "Ometria". The SDK logs all events as they happen, and also logs the flushing i.e. when they are sent to the Ometria mobile events API. Any potential errors with the sending (API issues or event validation issues) would be visible here too.