Skip to main content

Event Tracking

Requirements

Remember

Before sending any event ensure that the “install” has been successfully tracked. If an “install” is not recorded for the app on a device, Adtrace will receive and store your events, but they will NOT appear in the panel statistics.

Simple event

You can use Adtrace to track any event in your app. Suppose you want to track every tap on a button. To do so, you'll create a new event token in your panel. Let's say that the event token is abc123. In your button's onClick method, add the following lines to track the click:

let event = ADTEvent(eventToken: "abc123")
Adtrace.trackEvent(event)
tip

use event TOKEN in your code not event name.

Event with revenue

If your users can generate revenue by tapping on advertisements or making in-app purchases, you can track those revenues with events too. Let's say a tap is worth 1000 IRR. You can track the revenue event like this:

let event = ADTEvent(eventToken: "abc123")
event?.setRevenue(1000.0, currency: "IRR")
Adtrace.trackEvent(event)
Important

If you want to track in-app purchases, please make sure to call trackEvent only if the purchase is "finished" and the item has been purchased. This is important in order avoid tracking revenue that was not actually generated.

Event value parameters

When you want to send any value with an event you can add event parameters.

You can send any key value pairs one by one, by calling the addEventParameter method to your event instance.

let event = ADTEvent(eventToken: "abc123")
event?.addEventValueParameter("key","value")
event?.addEventValueParameter("foo","bar")
Adtrace.trackEvent(event)

Revenue deduplication

You can also add an optional order ID (or any id that unifies the generated revenue) to avoid tracking duplicate revenues. By doing so, the last 10 order IDs will be remembered and revenue events with duplicate order IDs are skipped. This is especially useful for tracking in-app purchases. You can see an example below.

AdTraceEvent adtraceEvent = new AdTraceEvent("abc123");
adtraceEvent.setRevenue(1000, "IRR");
adtraceEvent.setOrderId("{OrderId}");
AdTrace.trackEvent(adtraceEvent);