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.
JsonResponseobject<string, object>The JSON object with the response from the server.
WillRetrybooleanIndicates whether there will be an attempt to resend a failed package.

Success callbacks

Method signature
setSessionTrackingSucceededCallbackListener(
sessionTrackingSucceededCallback: (session: AdjustSessionSuccess) => void
)

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

var adjustConfig = new AdjustConfig(appToken, environment);
adjustConfig.setSessionTrackingSucceededCallbackListener(
function (sessionSuccess) {
// Printing all session success properties.
console.log("Session tracking succeeded!");
console.log(sessionSuccess.message);
console.log(sessionSuccess.timestamp);
console.log(sessionSuccess.adid);
console.log(sessionSuccess.jsonResponse);
},
);
Adjust.create(adjustConfig);

Example

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

var adjustConfig = new AdjustConfig(appToken, environment);
adjustConfig.setSessionTrackingSucceededCallbackListener(
function (sessionSuccess) {
console.log(`Session recorded at ${sessionSuccess.timestamp}`);
},
);
Adjust.create(adjustConfig);

Failure callbacks

Method signature
setSessionTrackingFailedCallbackListener(sessionTrackingFailedCallback: (session: AdjustSessionFailure) => void)

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

var adjustConfig = new AdjustConfig(appToken, environment);
adjustConfig.setSessionTrackingFailedCallbackListener(
function (sessionFailure) {
// Printing all session failure properties.
console.log("Session tracking failed!");
console.log(sessionFailure.message);
console.log(sessionFailure.timestamp);
console.log(sessionFailure.adid);
console.log(sessionFailure.willRetry);
console.log(sessionFailure.jsonResponse);
},
);
Adjust.create(adjustConfig);

Example

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

var adjustConfig = new AdjustConfig(appToken, environment);
adjustConfig.setSessionTrackingFailedCallbackListener(
function (sessionFailure) {
console.log(
`SDK failed to record session due to ${sessionFailure.message}`,
);
},
);
Adjust.create(adjustConfig);

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.
JsonResponseobject<string, object>The JSON object with the response from the server.
EventTokenstringThe event token
CallbackIdstringThe custom callback ID set on the event object
WillRetrybooleanIndicates whether there will be an attempt to resend a failed package.

Success callbacks

Method signature
setEventTrackingSucceededCallbackListener(eventTrackingSucceededCallback: (event: AdjustEventSuccess) => void)

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

var adjustConfig = new AdjustConfig(appToken, environment);
adjustConfig.setEventTrackingSucceededCallbackListener(function (eventSuccess) {
// Printing all event success properties.
console.log("Event tracking succeeded!");
console.log(eventSuccess.message);
console.log(eventSuccess.timestamp);
console.log(eventSuccess.eventToken);
console.log(eventSuccess.callbackId);
console.log(eventSuccess.adid);
console.log(eventSuccess.jsonResponse);
});
Adjust.create(adjustConfig);

Example

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

var adjustConfig = new AdjustConfig(appToken, environment);
adjustConfig.setEventTrackingSucceededCallbackListener(function (eventSuccess) {
console.log(`Event recorded at ${eventSuccess.timestamp}`);
});
Adjust.create(adjustConfig);

Failure callbacks

Method signature
setEventTrackingFailedCallbackListener(eventTrackingFailedCallback: (event: AdjustEventFailure) => void)

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

var adjustConfig = new AdjustConfig(appToken, environment);
adjustConfig.setEventTrackingFailedCallbackListener(function (eventFailure) {
// Printing all event failure properties.
console.log("Event tracking failed!");
console.log(eventFailure.message);
console.log(eventFailure.timestamp);
console.log(eventFailure.eventToken);
console.log(eventFailure.callbackId);
console.log(eventFailure.adid);
console.log(eventFailure.willRetry);
console.log(eventFailure.jsonResponse);
});
Adjust.create(adjustConfig);

Example

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

var adjustConfig = new AdjustConfig(appToken, environment);
adjustConfig.setEventTrackingFailedCallbackListener(function (eventFailure) {
console.log(`SDK failed to record event due to ${eventFailure.message}`);
});
Adjust.create(adjustConfig);