Set up callbacks to trigger functions when the SDK sends information to Adjust. You can define callbacks for sessions and events.
Session callbacks
Session callbacks trigger functions when the SDK sends session information. You can define success callbacks and failure callbacks:
- Success callback runs when the SDK successfully sends session data to Adjust’s servers.
- Failure callback runs when the SDK encounters a problem sending session data.
Session callbacks receive a response data object, which you can access 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. |
jsonResponse | string | The JSON string with the response from the server. |
willRetry | boolean | Indicates whether there will be an attempt to resend a failed package. |
Session success callback
Define a success callback to trigger when the SDK records a session:
local adjust = require "plugin.adjust"
-- make sure to set callback before calling initSdk methodadjust.setSessionSuccessCallback(function(event) local json_session_success = json.decode(event.message) print("Session tracking success!") print("Message: " .. (json_session_success.message or "N/A")) print("Timestamp: " .. (json_session_success.timestamp or "N/A")) print("Adid: " .. (json_session_success.adid or "N/A")) print("JSON response: " .. (json.encode(json_session_success.jsonResponse) or "N/A"))end)
adjust.initSdk({ appToken = "YourAppToken", environment = "SANDBOX"})
Session failure callback
Define a failure callback to trigger when the SDK fails to record a session:
local adjust = require "plugin.adjust"
-- make sure to set callback before calling initSdk methodadjust.setSessionFailureCallback(function(event) local json_session_failure = json.decode(event.message) print("Session tracking failure!") print("Message: " .. (json_session_failure.message or "N/A")) print("Timestamp: " .. (json_session_failure.timestamp or "N/A")) print("Adid: " .. (json_session_failure.adid or "N/A")) print("Will retry: " .. (json_session_failure.willRetry or "N/A")) print("JSON response: " .. (json.encode(json_session_failure.jsonResponse) or "N/A"))end)
adjust.initSdk({ appToken = "YourAppToken", environment = "SANDBOX"})
Event callbacks
Event callbacks trigger functions when the SDK sends event information. You can define success callbacks and failure callbacks:
- Success callback runs when the SDK successfully sends event data to Adjust’s servers.
- Failure callback runs when the SDK encounters a problem sending event data.
Event callbacks receive a response data object, which you can access 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. |
jsonResponse | string | The JSON string with the response from the server. |
eventToken | string | The event token |
callbackId | string | The custom callback ID set on the event object |
willRetry | boolean | Indicates whether there will be an attempt to resend a failed package. |
Event success callback
Define a success callback to trigger when the SDK records an event:
local adjust = require "plugin.adjust"
-- make sure to set callback before calling initSdk methodadjust.setEventSuccessCallback(function(event) local json_event_success = json.decode(event.message) print("Event tracking success!") print("Event token: " .. (json_event_success.eventToken or "N/A")) print("Message: " .. (json_event_success.message or "N/A")) print("Timestamp: " .. (json_event_success.timestamp or "N/A")) print("Adid: " .. (json_event_success.adid or "N/A")) print("JSON response: " .. (json.encode(json_event_success.jsonResponse) or "N/A"))end)
adjust.initSdk({ appToken = "YourAppToken", environment = "SANDBOX"})
Event failure callback
Define a failure callback to trigger when the SDK fails to record an event:
local adjust = require "plugin.adjust"
-- make sure to set callback before calling initSdk methodadjust.setEventFailureCallback(function(event) local json_event_failure = json.decode(event.message) print("Event tracking failure!") print("Event token: " .. (json_event_failure.eventToken or "N/A")) print("Message: " .. (json_event_failure.message or "N/A")) print("Timestamp: " .. (json_event_failure.timestamp or "N/A")) print("Adid: " .. (json_event_failure.adid or "N/A")) print("Will retry: " .. (json_event_failure.willRetry or "N/A")) print("JSON response: " .. (json.encode(json_event_failure.jsonResponse) or "N/A"))end)
adjust.initSdk({ appToken = "YourAppToken", environment = "SANDBOX"})