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.
Property | Data type | Description |
---|---|---|
Message | String | The message from the server or the error logged by the SDK. |
Timestamp | String | The timestamp from Adjust’s servers. |
Adid | String | A unique device identifier provided by Adjust. |
JsonResponse | Dictionary <string, object> | The JSON object with the response from the server. |
WillRetry | Boolean | Indicates whether there will be an attempt to resend a failed package. |
Success callbacks
void setSessionSuccessCallback(void(*sessionSuccessCallback)(AdjustSessionSuccess2dx sessionSuccess));
Set up success callbacks to trigger functions when the SDK records a session.
#include "Adjust/Adjust2dx.h"
static void sessionSuccessCallbackMethod(AdjustSessionSuccess2dx sessionSuccess) { //...}
bool AppDelegate::applicationDidFinishLaunching() { std::string appToken = "{YourAppToken}"; std::string environment = AdjustEnvironmentSandbox2dx;
AdjustConfig2dx adjustConfig = AdjustConfig2dx(appToken, environment); adjustConfig.setLogLevel(AdjustLogLevel2dxVerbose); adjustConfig.setSessionSuccessCallback(sessionSuccessCallbackMethod); Adjust2dx::start(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.
#include "Adjust/Adjust2dx.h"
static void sessionSuccess(AdjustSessionSuccess2dx sessionSuccess) { CCLOG("Session recorded at %s", sessionSuccess.getTimestamp().c_str());}
bool AppDelegate::applicationDidFinishLaunching() { std::string appToken = "{YourAppToken}"; std::string environment = AdjustEnvironmentSandbox2dx;
AdjustConfig2dx adjustConfig = AdjustConfig2dx(appToken, environment); adjustConfig.setLogLevel(AdjustLogLevel2dxVerbose); adjustConfig.setSessionSuccessCallback(sessionSuccess); Adjust2dx::start(adjustConfig);}
Failure callbacks
void setSessionFailureCallback(void(*sessionFailureCallback)(AdjustSessionFailure2dx sessionFailure));
Set up failure callbacks to trigger functions when the SDK fails to record a session.
#include "Adjust/Adjust2dx.h"
static void sessionFailureCallbackMethod(AdjustSessionFailure2dx sessionFailure) { //...}
bool AppDelegate::applicationDidFinishLaunching() { std::string appToken = "{YourAppToken}"; std::string environment = AdjustEnvironmentSandbox2dx;
AdjustConfig2dx adjustConfig = AdjustConfig2dx(appToken, environment); adjustConfig.setLogLevel(AdjustLogLevel2dxVerbose); adjustConfig.setSessionFailureCallback(sessionFailureCallbackMethod); Adjust2dx::start(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.
#include "Adjust/Adjust2dx.h"
static void sessionFailure(AdjustSessionFailure2dx sessionFailure) { CCLOG("Session recording failed. Response: %s", sessionFailure.getMessage().c_str());}
bool AppDelegate::applicationDidFinishLaunching() { std::string appToken = "{YourAppToken}"; std::string environment = AdjustEnvironmentSandbox2dx;
AdjustConfig2dx adjustConfig = AdjustConfig2dx(appToken, environment); adjustConfig.setLogLevel(AdjustLogLevel2dxVerbose); adjustConfig.setSessionFailureCallback(sessionFailure); Adjust2dx::start(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.
Property | Data type | Description |
---|---|---|
Message | String | The message from the server or the error logged by the SDK. |
Timestamp | String | The timestamp from Adjust’s servers. |
Adid | String | A unique device identifier provided by Adjust. |
EventToken | String | The event token |
CallbackId | String | The custom callback ID set on the event object |
JsonResponse | Dictionary <string, object> | The JSON object with the response from the server. |
WillRetry | Boolean | Indicates whether there will be an attempt to resend a failed package. |
Success callbacks
void setEventSuccessCallback(void(*eventSuccessCallback)(AdjustEventSuccess2dx eventSuccess));
Set up success callbacks to trigger functions when the SDK records an event.
#include "Adjust/Adjust2dx.h"
static void eventSuccessCallbackMethod(AdjustEventSuccess2dx eventSuccess) { //...}
bool AppDelegate::applicationDidFinishLaunching() { std::string appToken = "{YourAppToken}"; std::string environment = AdjustEnvironmentSandbox2dx;
AdjustConfig2dx adjustConfig = AdjustConfig2dx(appToken, environment); adjustConfig.setLogLevel(AdjustLogLevel2dxVerbose); adjustConfig.setEventSuccessCallback(eventSuccessCallbackMethod); Adjust2dx::start(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.
#include "Adjust/Adjust2dx.h"
static void eventSuccess(AdjustEventSuccess2dx eventSuccess) { CCLOG("Event recorded at %s", eventSuccess.getTimestamp().c_str());}
bool AppDelegate::applicationDidFinishLaunching() { std::string appToken = "{YourAppToken}"; std::string environment = AdjustEnvironmentSandbox2dx;
AdjustConfig2dx adjustConfig = AdjustConfig2dx(appToken, environment); adjustConfig.setLogLevel(AdjustLogLevel2dxVerbose); adjustConfig.setEventSuccessCallback(eventSuccess); Adjust2dx::start(adjustConfig);}
Failure callbacks
void setEventFailureCallback(void(*eventFailureCallback)(AdjustEventFailure2dx eventFailure));
Set up failure callbacks to trigger functions when the SDK fails to record an event.
#include "Adjust/Adjust2dx.h"
static void eventFailureCallbackMethod(AdjustEventFailure2dx eventFailure) { //...}
bool AppDelegate::applicationDidFinishLaunching() { std::string appToken = "{YourAppToken}"; std::string environment = AdjustEnvironmentSandbox2dx;
AdjustConfig2dx adjustConfig = AdjustConfig2dx(appToken, environment); adjustConfig.setLogLevel(AdjustLogLevel2dxVerbose); adjustConfig.setEventFailureCallback(eventFailureCallbackMethod); Adjust2dx::start(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.
#include "Adjust/Adjust2dx.h"
static void eventFailure(AdjustEventFailure2dx eventFailure) { CCLOG("Event recording failed. Response: %s", eventFailure.getMessage().c_str());}
bool AppDelegate::applicationDidFinishLaunching() { std::string appToken = "{YourAppToken}"; std::string environment = AdjustEnvironmentSandbox2dx;
AdjustConfig2dx adjustConfig = AdjustConfig2dx(appToken, environment); adjustConfig.setLogLevel(AdjustLogLevel2dxVerbose); adjustConfig.setEventFailureCallback(eventFailure); Adjust2dx::start(adjustConfig);}