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.
jsonResponsestringThe JSON string with the response from the server.
willRetrybooleanIndicates whether there will be an attempt to resend a failed package.

Success callbacks

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

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

const adjustConfig = new AdjustConfig(
"{YourAppToken}",
AdjustConfig.EnvironmentSandbox,
);
adjustConfig.setSessionTrackingSucceededCallback(function (sessionSuccess) {
// Printing all session success properties.
console.log("Session recording succeeded!");
console.log(sessionSuccess.message);
console.log(sessionSuccess.timestamp);
console.log(sessionSuccess.jsonResponse);
});
Adjust.initSdk(adjustConfig);

Example

This example shows how to create a callback function sessionSuccess and register it as a success callback. The function logs the timestamp at which the SDK recorded the session.

const adjustConfig = new AdjustConfig(
"{YourAppToken}",
AdjustConfig.EnvironmentSandbox,
);
adjustConfig.setSessionTrackingSucceededCallback(function (sessionSuccess) {
console.log(sessionSuccess.timestamp);
});
Adjust.initSdk(adjustConfig);

Failure callbacks

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

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

const adjustConfig = new AdjustConfig(
"{YourAppToken}",
AdjustConfig.EnvironmentSandbox,
);
adjustConfig.setSessionTrackingFailedCallback(function (sessionFailure) {
// Printing all session failure properties.
console.log("Session recording failed!");
console.log(sessionFailure.message);
console.log(sessionFailure.timestamp);
console.log(sessionFailure.willRetry);
console.log(sessionFailure.jsonResponse);
});
Adjust.initSdk(adjustConfig);

Example

This example shows how to create a callback function sessionFailure and register it as a failure callback. The function logs the session failure message.

const adjustConfig = new AdjustConfig(
"{YourAppToken}",
AdjustConfig.EnvironmentSandbox,
);
adjustConfig.setSessionTrackingFailedCallback(function (sessionFailure) {
console.log(sessionFailure.message);
});
Adjust.initSdk(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.
eventTokenstringThe event token
callbackIdstringThe custom callback ID set on the event object
jsonResponsestringThe JSON string with the response from the server.
willRetrybooleanIndicates whether there will be an attempt to resend a failed package.

Success callbacks

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

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

const adjustConfig = new AdjustConfig(
"{YourAppToken}",
AdjustConfig.EnvironmentSandbox,
);
adjustConfig.setEventTrackingSucceededCallbackListener(function (eventSuccess) {
// Printing all event success properties.
console.log("Event recording succeeded!");
console.log(eventSuccess.message);
console.log(eventSuccess.timestamp);
console.log(eventSuccess.eventToken);
console.log(eventSuccess.callbackId);
console.log(eventSuccess.jsonResponse);
});
Adjust.initSdk(adjustConfig);

Example

This example shows how to create a callback function eventSuccess and register it as a success callback. The function logs the timestamp at which the SDK recorded the event.

const adjustConfig = new AdjustConfig(
"{YourAppToken}",
AdjustConfig.EnvironmentSandbox,
);
adjustConfig.setEventTrackingSucceededCallbackListener(function (eventSuccess) {
console.log(eventSuccess.timestamp);
});
Adjust.initSdk(adjustConfig);

Failure callbacks

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

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

const adjustConfig = new AdjustConfig(
"{Your App Token}",
AdjustConfig.EnvironmentSandbox,
);
adjustConfig.setLogLevel(AdjustLogLevel.Verbose);
adjustConfig.setEventTrackingFailedCallback(function (eventFailure) {
// Printing all event failure properties.
console.log("Event recording failed!");
console.log(eventFailure.message);
console.log(eventFailure.timestamp);
console.log(eventFailure.eventToken);
console.log(eventFailure.callbackId);
console.log(eventFailure.willRetry);
console.log(eventFailure.jsonResponse);
});
Adjust.initSdk(adjustConfig);

Example

This example shows how to create a callback function eventFailure and register it as a failure callback. The function logs the event failure message.

const adjustConfig = new AdjustConfig(
"{YourAppToken}",
AdjustConfig.EnvironmentSandbox,
);
adjustConfig.setEventTrackingFailedCallback(function (eventFailure) {
console.log(eventFailure.message);
});
Adjust.initSdk(adjustConfig);