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:
You need to add the attribution callback to your config instance before you start the SDK.
- Java
- Javascript
AdTraceConfig config = new AdTraceConfig(this, appToken, environment);
config.setOnAttributionChangedListener(new OnAttributionChangedListener() {
@Override
public void onAttributionChanged(AdTraceAttribution attribution) {
//...
}
});
AdTrace.onCreate(config);
function attributionCallback(attribution) {}
// ...
let adtraceConfig = new AdTraceConfig(yourAppToken, environment);
adtraceConfig.setAttributionCallback(attributionCallback);
AdTrace.onCreate(adtraceConfig);
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:
trackerTokenthe tracker token string of the current attribution.trackerNamethe tracker name string of the current attribution.networkthe network grouping level string of the current attribution.campaignthe campaign grouping level string of the current attribution.adgroupthe ad group grouping level string of the current attribution.creativethe creative grouping level string of the current attribution.clickLabelthe click label string of the current attribution.adidthe Adtrace device identifier string.
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:
- Java
- Javascript
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);
function eventSuccessCallback(eventSuccessResponseData) {}
function eventFailureCallback(eventFailureResponseData) {}
function sessionSuccessCallback(sessionSuccessResponseData) {}
function sessionFailureCallback(sessionFailureResponseData) {}
// ...
let adtraceConfig = new AdTraceConfig(yourAppToken, environment);
adtraceConfig.setEventSuccessCallback(eventSuccessCallback);
adtraceConfig.setEventFailureCallback(eventFailureCallback);
adtraceConfig.setSessionSuccessCallback(sessionSuccessCallback);
adtraceConfig.setSessionFailureCallback(sessionFailureCallback);
AdTrace.onCreate(adtraceConfig);
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:
messagemessage string from the server (or the error logged by the SDK).timestamptimestamp string from the server.adida unique string device identifier provided by Adtrace.jsonResponsethe JSON object with the response from the server.
And both event and session failed objects also contain:
willRetryboolean which indicates whether there will be a later attempt to resend the package.
Deep Link Callback
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.
- Java
- Javascript
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);
let adtraceConfig = new AdTraceConfig(yourAppToken, environment);
adtraceConfig.setDeferredDeeplinkCallback(function (deeplink) {
// ...
});
AdTrace.onCreate(adtraceConfig);
Remember that if you do not set the callback, the Adtrace SDK will always attempt to launch the URL by default.