Send callback information
Set up callbacks to run your own code when the Adtrace SDK sends information to Adtrace or when attribution changes.
On iOS, most callbacks use the optional AdtraceDelegate protocol. Register the delegate on your ADTConfig instance before you call [Adtrace appDidLaunch:] / Adtrace.appDidLaunch(...).
| Callback type | Mechanism | When it runs |
|---|---|---|
| Attribution | AdtraceDelegate | After the SDK receives final or updated attribution data |
| Event success / failure | AdtraceDelegate | After the SDK tries to send an event package |
| Session success / failure | AdtraceDelegate | After the SDK tries to send a session package |
| Deferred deep link | AdtraceDelegate | Before the SDK opens a deferred deep link. See Deep linking |
This page covers delegate callbacks in your app code. For key-value data appended to callback URLs on every session and event, see Set session callback parameters.
You must set the delegate before initializing the SDK.
A successful callback means the SDK sent the package. It does not always mean the data appears in panel statistics. Events only show in the panel after the install was successfully tracked for that device.
Set up the delegate
1. Adopt AdtraceDelegate
- Objective-C
- Swift
@interface AppDelegate : UIResponder <UIApplicationDelegate, AdtraceDelegate>
@end
class AppDelegate: UIResponder, UIApplicationDelegate, AdtraceDelegate {
// ...
}
2. Register the delegate on ADTConfig
Call setDelegate: before appDidLaunch:
- Objective-C
- Swift
NSString *appToken = @"{YourAppToken}";
NSString *environment = ADTEnvironmentSandbox;
ADTConfig *adtraceConfig = [ADTConfig configWithAppToken:appToken
environment:environment];
[adtraceConfig setDelegate:self];
[Adtrace appDidLaunch:adtraceConfig];
let appToken = "{YourAppToken}"
let environment = ADTEnvironmentSandbox
let adtraceConfig = ADTConfig(appToken: appToken, environment: environment)
adtraceConfig?.delegate = self
Adtrace.appDidLaunch(adtraceConfig)
3. Implement the delegate methods you need
Implement only the optional methods you care about. Unimplemented methods are simply not called.
Attribution callbacks
Register a delegate callback to be notified when tracker attribution changes. The SDK cannot provide attribution synchronously because it comes from multiple sources.
To read attribution on demand (without waiting for a change), see Get attribution information.
Delegate method
- (void)adtraceAttributionChanged:(nullable ADTAttribution *)attribution;
The SDK calls this method after it receives final attribution data. Implement it on your AdtraceDelegate conforming class.
Example
- Objective-C
- Swift
- Javascript
- (void)adtraceAttributionChanged:(ADTAttribution *)attribution {
NSLog(@"Tracker token: %@", attribution.trackerToken);
NSLog(@"Network: %@", attribution.network);
}
func adtraceAttributionChanged(_ attribution: ADTAttribution?) {
print("Tracker token: \(attribution?.trackerToken ?? "")")
print("Network: \(attribution?.network ?? "")")
}
adtraceConfig.setAttributionCallback(function(attribution) {
console.log('Tracker token = ' + attribution.trackerToken);
console.log('Network = ' + attribution.network);
});
ADTAttribution properties
Any value that is not set for the user is returned as nil.
| Property | Type | Description |
|---|---|---|
trackerToken | NSString | Token of the tracker the device is currently attributed to. |
trackerName | NSString | Name of the tracker the device is currently attributed to. |
network | NSString | Network the device is currently attributed to. |
campaign | NSString | Campaign the device is currently attributed to. |
adgroup | NSString | Ad group the device is currently attributed to. |
creative | NSString | Creative the device is currently attributed to. |
clickLabel | NSString | Click label tagged on the install. |
adid | NSString | Unique Adtrace device identifier. |
costType | NSString | Campaign pricing model (for example cpi). Requires cost data in attribution. |
costAmount | NSNumber | Cost of the install. Requires cost data in attribution. |
costCurrency | NSString | ISO 4217 currency code for the cost. Requires cost data in attribution. |
Cost fields are only available when you enable them with setNeedsCost: on ADTConfig before appDidLaunch. If cost is not enabled or not part of the attribution, these fields are nil.
Event and session callbacks
Register delegate callbacks to be notified when the SDK successfully or unsuccessfully sends event and session packages. Use the same AdtraceDelegate setup as attribution callbacks.
The SDK calls these methods after it tries to send a package to the server.
Session callbacks
Response data
| Property | Type | Description |
|---|---|---|
message | NSString | Message from the server, or an error logged by the SDK. |
timeStamp | NSString | Timestamp from Adtrace servers. |
adid | NSString | Unique Adtrace device identifier. |
jsonResponse | NSDictionary | JSON object with the server response. |
willRetry | BOOL | On failure only. YES if the SDK will try to resend the package later. |
Session success
- (void)adtraceSessionTrackingSucceeded:(nullable ADTSessionSuccess *)sessionSuccessResponseData;
- Objective-C
- Swift
- Javascript
- (void)adtraceSessionTrackingSucceeded:(ADTSessionSuccess *)sessionSuccessResponseData {
NSLog(@"Session recorded at %@", sessionSuccessResponseData.timeStamp);
}
func adtraceSessionTrackingSucceeded(_ sessionSuccessResponseData: ADTSessionSuccess?) {
print("Session recorded at \(sessionSuccessResponseData?.timeStamp ?? "")")
}
adtraceConfig.setSessionSuccessCallback(function(sessionSuccess) {
console.log('Session recorded at ' + sessionSuccess.timeStamp);
});
Session failure
- (void)adtraceSessionTrackingFailed:(nullable ADTSessionFailure *)sessionFailureResponseData;
- Objective-C
- Swift
- Javascript
- (void)adtraceSessionTrackingFailed:(ADTSessionFailure *)sessionFailureResponseData {
NSLog(@"Session recording failed: %@", sessionFailureResponseData.message);
}
func adtraceSessionTrackingFailed(_ sessionFailureResponseData: ADTSessionFailure?) {
print("Session recording failed: \(sessionFailureResponseData?.message ?? "")")
}
adtraceConfig.setSessionFailureCallback(function(sessionFailure) {
console.log('Session recording failed: ' + sessionFailure.message);
});
Event callbacks
Response data
| Property | Type | Description |
|---|---|---|
message | NSString | Message from the server, or an error logged by the SDK. |
timeStamp | NSString | Timestamp from Adtrace servers. |
adid | NSString | Unique Adtrace device identifier. |
eventToken | NSString | The event token. |
callbackId | NSString | Custom callback ID set on the event with setCallbackId, if any. |
jsonResponse | NSDictionary | JSON object with the server response. |
willRetry | BOOL | On failure only. YES if the SDK will try to resend the package later. |
Event success
- (void)adtraceEventTrackingSucceeded:(nullable ADTEventSuccess *)eventSuccessResponseData;
- Objective-C
- Swift
- Javascript
- (void)adtraceEventTrackingSucceeded:(ADTEventSuccess *)eventSuccessResponseData {
NSLog(@"Event %@ recorded at %@", eventSuccessResponseData.eventToken, eventSuccessResponseData.timeStamp);
}
func adtraceEventTrackingSucceeded(_ eventSuccessResponseData: ADTEventSuccess?) {
print("Event \(eventSuccessResponseData?.eventToken ?? "") recorded at \(eventSuccessResponseData?.timeStamp ?? "")")
}
adtraceConfig.setEventSuccessCallback(function(eventSuccess) {
console.log('Event recorded at ' + eventSuccess.timeStamp);
});
Event failure
- (void)adtraceEventTrackingFailed:(nullable ADTEventFailure *)eventFailureResponseData;
- Objective-C
- Swift
- Javascript
- (void)adtraceEventTrackingFailed:(ADTEventFailure *)eventFailureResponseData {
NSLog(@"Event recording failed: %@", eventFailureResponseData.message);
}
func adtraceEventTrackingFailed(_ eventFailureResponseData: ADTEventFailure?) {
print("Event recording failed: \(eventFailureResponseData?.message ?? "")")
}
adtraceConfig.setEventFailureCallback(function(eventFailure) {
console.log('Event recording failed: ' + eventFailure.message);
});