adjust-icon

Set up callbacks

Set up callbacks to trigger functions when the SDK sends information to Adjust. You can set up callbacks for sessions and events.

Session callbacks

Set up session callbacks to trigger functions when the SDK sends session information. You can create success callbacks and failure callbacks. Success callbacks trigger when the SDK sends information to Adjust’s servers. Failure callbacks trigger when the SDK encounters a problem while sending the information.

Session callbacks have access to a response data object. You can use its properties in your callback function.

PropertyData typeDescription
MessageStringThe message from the server or the error logged by the SDK.
TimestampStringThe timestamp from Adjust’s servers.
AdidStringA unique device identifier provided by Adjust.
JsonResponseMap<String, Object>The JSON object with the response from the server.
WillRetryboolIndicates whether there will be an attempt to resend a failed package.

Success callbacks

Property declaration
typedef void SessionSuccessCallback(AdjustSessionSuccess successData);
SessionSuccessCallback? sessionSuccessCallback;

Set up success callbacks to trigger functions when the SDK records a session.

AdjustConfig adjustConfig = new AdjustConfig(yourAppToken, environment);
config.sessionSuccessCallback = (AdjustSessionSuccess sessionSuccessData) {
print('[Adjust]: Session recording success!');
if (sessionSuccessData.message != null) {
print('[Adjust]: Message: ' + sessionSuccessData.message);
}
if (sessionSuccessData.timestamp != null) {
print('[Adjust]: Timestamp: ' + sessionSuccessData.timestamp);
}
if (sessionSuccessData.adid != null) {
print('[Adjust]: Adid: ' + sessionSuccessData.adid);
}
if (sessionSuccessData.jsonResponse != null) {
print('[Adjust]: JSON response: ' + sessionSuccessData.jsonResponse);
}
};
Adjust.start(adjustConfig);

Example

This example shows how to register a sessionSuccessCallback that prints the timestamp at which the SDK sent the session data to Adjust.

AdjustConfig myConfig = new AdjustConfig('{Your App Token}', AdjustEnvironment.sandbox);
//...
myConfig.sessionSuccessCallback = (AdjustSessionSuccess sessionSuccessData) {
print('Session measured at ' + sessionSuccessData.timestamp);
}
//...
Adjust.start(myConfig);

Failure callbacks

Property declaration
typedef void SessionFailureCallback(AdjustSessionFailure failureData);
SessionFailureCallback? sessionFailureCallback;

Set up failure callbacks to trigger functions when the SDK fails to record a session.

AdjustConfig adjustConfig = new AdjustConfig(yourAppToken, environment);
config.sessionFailureCallback = (AdjustSessionFailure sessionFailureData) {
print('[Adjust]: Session recording failure!');
if (sessionFailureData.message != null) {
print('[Adjust]: Message: ' + sessionFailureData.message);
}
if (sessionFailureData.timestamp != null) {
print('[Adjust]: Timestamp: ' + sessionFailureData.timestamp);
}
if (sessionFailureData.adid != null) {
print('[Adjust]: Adid: ' + sessionFailureData.adid);
}
if (sessionFailureData.willRetry != null) {
print('[Adjust]: Will retry: ' + sessionFailureData.willRetry.toString());
}
if (sessionFailureData.jsonResponse != null) {
print('[Adjust]: JSON response: ' + sessionFailureData.jsonResponse);
}
};
Adjust.start(adjustConfig);

Example

This example shows how to register a sessionFailureCallback that prints the reason the SDK failed to send the session data.

AdjustConfig myConfig = new AdjustConfig('{Your App Token}', AdjustEnvironment.sandbox);
//...
myConfig.sessionFailureCallback = (AdjustSessionFailure sessionFailureData) {
print('Session failure due to ' + sessionFailureData.message);
}
//...
Adjust.start(myConfig);

Event callbacks

Set up event callbacks to trigger functions when the SDK sends event information. You can create success callbacks and failure callbacks. Success callbacks trigger when the SDK sends information to Adjust’s servers. Failure callbacks trigger when the SDK encounters a problem while sending the information.

Event callbacks have access to a response data object. You can use its properties in your callback function.

PropertyData typeDescription
MessageStringThe message from the server or the error logged by the SDK.
TimestampStringThe timestamp from Adjust’s servers.
AdidStringA unique device identifier provided by Adjust.
JsonResponseMap<String, Object>The JSON object with the response from the server.
EventTokenStringThe event token
CallbackIdStringThe custom callback ID set on the event object
WillRetryboolIndicates whether there will be an attempt to resend a failed package.

Success callbacks

Property declaration
typedef void EventSuccessCallback(AdjustEventSuccess successData);
EventSuccessCallback? eventSuccessCallback;

Set up success callbacks to trigger functions when the SDK records an event.

AdjustConfig adjustConfig = new AdjustConfig(yourAppToken, environment);
config.eventSuccessCallback = (AdjustEventSuccess eventSuccessData) {
print('[Adjust]: Event recording success!');
if (eventSuccessData.eventToken != null) {
print('[Adjust]: Event token: ' + eventSuccessData.eventToken);
}
if (eventSuccessData.message != null) {
print('[Adjust]: Message: ' + eventSuccessData.message);
}
if (eventSuccessData.timestamp != null) {
print('[Adjust]: Timestamp: ' + eventSuccessData.timestamp);
}
if (eventSuccessData.adid != null) {
print('[Adjust]: Adid: ' + eventSuccessData.adid);
}
if (eventSuccessData.callbackId != null) {
print('[Adjust]: Callback ID: ' + eventSuccessData.callbackId);
}
if (eventSuccessData.jsonResponse != null) {
print('[Adjust]: JSON response: ' + eventSuccessData.jsonResponse);
}
};
Adjust.start(adjustConfig);

Example

This example shows how to register a eventSuccessCallback that prints the timestamp at which the SDK sent the event data to Adjust.

AdjustConfig myConfig = new AdjustConfig('{Your App Token}', AdjustEnvironment.sandbox);
//...
myConfig.eventSuccessCallback = (AdjustEventSuccess eventSuccessData) {
print('Session measured at ' + eventSuccessData.timestamp);
}
//...
Adjust.start(myConfig);

Failure callbacks

Property declaration
typedef void EventFailureCallback(AdjustEventFailure failureData);
EventFailureCallback? eventFailureCallback;

Set up failure callbacks to trigger functions when the SDK fails to record an event.

AdjustConfig adjustConfig = new AdjustConfig(yourAppToken, environment);
config.eventFailureCallback = (AdjustEventFailure eventFailureData) {
print('[Adjust]: Event recording failure!');
if (eventFailureData.eventToken != null) {
print('[Adjust]: Event token: ' + eventFailureData.eventToken);
}
if (eventFailureData.message != null) {
print('[Adjust]: Message: ' + eventFailureData.message);
}
if (eventFailureData.timestamp != null) {
print('[Adjust]: Timestamp: ' + eventFailureData.timestamp);
}
if (eventFailureData.adid != null) {
print('[Adjust]: Adid: ' + eventFailureData.adid);
}
if (eventFailureData.callbackId != null) {
print('[Adjust]: Callback ID: ' + eventFailureData.callbackId);
}
if (eventFailureData.willRetry != null) {
print('[Adjust]: Will retry: ' + eventFailureData.willRetry.toString());
}
if (eventFailureData.jsonResponse != null) {
print('[Adjust]: JSON response: ' + eventFailureData.jsonResponse);
}
};
Adjust.start(adjustConfig);

Example

This example shows how to register a eventFailureCallback that prints the reason the SDK failed to send the event data.

AdjustConfig myConfig = new AdjustConfig('{Your App Token}', AdjustEnvironment.sandbox);
//...
myConfig.eventFailureCallback = (AdjustEventFailure eventFailureData) {
print('Session failure due to ' + eventFailureData.message);
}
//...
Adjust.start(myConfig);