Skip to main content

Callbacks

In order to observe SDKs states and data, there are several listeners that you can register to via AdTraceConfig.

Attribution Callback

You can register a listener to be notified of tracker attribution changes. Due to the different sources we consider for attribution, we cannot provide this information synchronously.

With the config instance, add the attribution callback before you start the SDK:

Note

You need to add the attribution callback to your config instance before you start the SDK.

AdTraceConfig config = new AdTraceConfig(this, appToken, environment);
config.setOnAttributionChangedListener(new OnAttributionChangedListener() {
@Override
public void onAttributionChanged(AdTraceAttribution attribution) {
//...
}
});

AdTrace.onCreate(config);

The listener function is called after the SDK receives the final attribution data. Within the listener function, you'll have access to the attribution parameter. Here is a quick summary of its properties:

  • trackerToken the tracker token string of the current attribution.
  • trackerName the tracker name string of the current attribution.
  • network the network grouping level string of the current attribution.
  • campaign the campaign grouping level string of the current attribution.
  • adgroup the ad group grouping level string of the current attribution.
  • creative the creative grouping level string of the current attribution.
  • clickLabel the click label string of the current attribution.
  • adid the Adtrace device identifier string.
Note

The cost data - costType, costAmount & costCurrency are only available when configured in AdTraceConfig by calling setNeedsCost method. If not configured or configured, but not being part of the attribution, these fields will have value null. This feature is available in SDK v2+ and above.

Session and Event Tracking Callbacks

You can register a listener to be notified when events or sessions are tracked. There are four listeners: one for tracking successful events, one for tracking failed events, one for tracking successful sessions, and one for tracking failed sessions. Add as many listeners as you need after creating the config object like so:

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

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

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

// Set session success tracking delegate.
config.setOnSessionTrackingSucceededListener(new OnSessionTrackingSucceededListener() {
@Override
public void onFinishedSessionTrackingSucceeded(AdTraceSessionSuccess sessionSuccessResponseData) {
// ...
}
});

// Set session failure tracking delegate.
config.setOnSessionTrackingFailedListener(new OnSessionTrackingFailedListener() {
@Override
public void onFinishedSessionTrackingFailed(AdTraceSessionFailure sessionFailureResponseData) {
// ...
}
});

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. Here is a quick summary of the success session response data object fields:

  • message message string from the server (or the error logged by the SDK).
  • timestamp timestamp string from the server.
  • adid a unique string device identifier provided by Adtrace.
  • jsonResponse the JSON object with the response from the server.

And both event and session failed objects also contain:

  • willRetry boolean which indicates whether there will be a later attempt to resend the package.
Note

this is only the usage of the method,follow implementing deep link for complete implementation.

If you wish to control if the Adtrace SDK will open the deferred deep link, you can do it with a callback method in the config object.

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

// Evaluate the deeplink to be launched.
config.setOnDeeplinkResponseListener(new OnDeeplinkResponseListener() {
@Override
public boolean launchReceivedDeeplink(Uri deeplink) {
// ...
if (shouldAdTraceSdkLaunchTheDeeplink(deeplink)) {
return true;
} else {
return false;
}
}
});
AdTrace.onCreate(config);