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:

AdTraceEvent adtraceEvent = new AdTraceEvent("abc123");
AdTrace.trackEvent(adtraceEvent);
warning

NOTE: only 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:

AdTraceEvent adtraceEvent = new AdTraceEvent("abc123");
adtraceEvent.setRevenue(1000, "IRR");
AdTrace.trackEvent(adtraceEvent);
note

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.

AdTraceEvent adtraceEvent = new AdTraceEvent("abc123");
adtraceEvent.addEventParameter("key", "value");
adtraceEvent.addEventParameter("foo", "bar");
AdTrace.trackEvent(adtraceEvent);

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);

Callbacks

You can register a listener to be notified when events are tracked. note that successful event necessarily does not mean that you should see it on panel. only after successful install for the device you can track data.

Successful event

AdTraceConfig config = new AdTraceConfig(this, appToken, environment);

// Set event failure tracking delegate.
config.setOnEventTrackingFailedListener(new OnEventTrackingFailedListener() {
@Override
public void onFinishedEventTrackingFailed(AdTraceEventFailure eventFailureResponseData) {
// ...
}
});

AdTrace.onCreate(config);

The listener function is called after the SDK tries to send a package to the server. Within the listener function you have access to a response data object specifically for the listener.

Failed event

AdTraceConfig config = new AdTraceConfig(this, appToken, environment);

// Set event success tracking delegate.
config.setOnEventTrackingSucceededListener(new OnEventTrackingSucceededListener() {
@Override
public void onFinishedEventTrackingSucceeded(AdTraceEventSuccess eventSuccessResponseData) {
// ...
}
});

AdTrace.onCreate(config);

Validation

Before sending any event, make sure that "install" was successfully sent to the server.

tip

you can also check latest events on panel: Settings > Testing Console.

Callback identifier (Experimental)

Caution

This feature is not fully integrated to Adtrace panel!

You can add a custom string identifier to each event you want to track. The Adtrace backend can report on this identifier in event callbacks. This enables you to keep track of which events have been successfully tracked. You can set up this identifier by calling the setCallbackId method on your event.

AdTraceEvent adtraceEvent = new AdTraceEvent("abc123");
adtraceEvent.setCallbackId("Your-Custom-Id");
AdTrace.trackEvent(adtraceEvent);

S2S event

As an alternative option to sending events, you can directly send events from your servers to Adtrace servers. this is usually used for cases where there are sensitive information or sending event from server is more justifiable than SDK.

There is no difference between S2S and SDK events on panel. However, handling queues, retrying etc. done properly inside SDK and all the traffic is on SDK client, therefore it is recommended to send events through SDK.

Not useless to mention, before sending S2S events, make sure that "install" was successfully sent for your app on the device you want to send events to.