Send callback information
Set up callbacks to run your own code when the Adtrace SDK sends information to Adtrace. You can set up callbacks for sessions and events.
Register these listeners on your AdTraceConfig instance before you call AdTrace.onCreate(). See Configuration for how to create the config.
For attribution listeners, see Get attribution information. For deferred deep link callbacks, see Deferred deep linking. For callback URL key-value data sent with every session and event, see Set session callback parameters.
You must register your callbacks before initializing the SDK.
A successful callback means the SDK sent the package. It does not always mean the data appears in panel statistics. Events only show in the panel after the install was successfully tracked for that device.
Session callbacks
Set up session callbacks when the SDK sends session information.
- Success callbacks run when the SDK sends the session successfully.
- Failure callbacks run when sending fails.
Response data
| Property | Type | Description |
|---|---|---|
message | String | Message from the server, or an error logged by the SDK. |
timestamp | String | Timestamp from Adtrace servers. |
adid | String | Unique Adtrace device identifier. |
jsonResponse | JSONObject | JSON object with the server response. |
willRetry | boolean | On failure only. true if the SDK will try to resend the package later. |
Success callbacks
Method signature
public void setOnSessionTrackingSucceededListener(OnSessionTrackingSucceededListener listener)
This example logs the timestamp when the SDK recorded the session.
- Java
- Kotlin
- Javascript
import android.util.Log;
import io.adtrace.sdk.AdTrace;
import io.adtrace.sdk.AdTraceConfig;
import io.adtrace.sdk.AdTraceSessionSuccess;
import io.adtrace.sdk.OnSessionTrackingSucceededListener;
AdTraceConfig config = new AdTraceConfig(this, appToken, environment);
config.setOnSessionTrackingSucceededListener(new OnSessionTrackingSucceededListener() {
@Override
public void onFinishedSessionTrackingSucceeded(AdTraceSessionSuccess sessionSuccessResponseData) {
Log.v("AdTrace", "Session recorded at " + sessionSuccessResponseData.timestamp);
}
});
AdTrace.onCreate(config);
import android.util.Log
import io.adtrace.sdk.AdTrace
import io.adtrace.sdk.AdTraceConfig
import io.adtrace.sdk.OnSessionTrackingSucceededListener
val config = AdTraceConfig(this, appToken, environment)
config.setOnSessionTrackingSucceededListener(OnSessionTrackingSucceededListener { sessionSuccessResponseData ->
Log.v("AdTrace", "Session recorded at ${sessionSuccessResponseData.timestamp}")
})
AdTrace.onCreate(config)
function sessionSuccess(sessionSuccessResponseData) {
console.log("Session recorded at " + sessionSuccessResponseData.timestamp);
}
let config = new AdTraceConfig(appToken, environment);
config.setSessionSuccessCallback(sessionSuccess);
AdTrace.onCreate(config);