Callbacks
Attribution callbacks
You can register a delegate callback to notify you of tracker attribution changes. The Adtrace SDK cannot provide this information synchronously. This is due to the different sources considered for attribution.
Follow the steps in this article to implement the optional delegate protocol in your app.
To set up the delegate callback, you need to configure it in your ADJConfig instance.
This means you will need to add the setDelegate call before you call the appDidLaunch method.
- If you are not using web views, add the
AdtraceDelegatedeclaration to yourAppDelegateheader file.
- Objective-C
- Swift
In your AppDelegate.h file:
@interface AppDelegate : UIResponder <UIApplicationDelegate, AdtraceDelegate>
In your AppDelegate.swift file:
class AppDelegate: UIResponder, UIApplicationDelegate, AdtraceDelegate {
// ...
}
- If you are not using web views, add the delegate callback function to your app delegate implementation.
- Objective-C
- Swift
In your AppDelegate.h file:
- (void)adtraceAttributionChanged:(ADJAttribution *)attribution {
// ...
}
In your AppDelegate.swift file:
func adtraceAttributionChanged(_ attribution: ADJAttribution?) {
// ...
}
- Set the delegate with your Adtrace config instance.
- Objective-C
- Swift
- Javascript
In your AppDelegate.h file:
[adtraceConfig setDelegate:self];
In your AppDelegate.swift file:
adtraceConfig?.delegate = self
adtraceConfig.setAttributionCallback(function(attribution) {
// In this example, we're just displaying alert with attribution content.
alert('Tracker token = ' + attribution.trackerToken + '\n' +
'Tracker name = ' + attribution.trackerName + '\n' +
'Network = ' + attribution.network + '\n' +
'Campaign = ' + attribution.campaign + '\n' +
'Adgroup = ' + attribution.adgroup + '\n' +
'Creative = ' + attribution.creative + '\n' +
'Click label = ' + attribution.clickLabel + '\n' +
'Adid = ' + attribution.adid);
});
The SDK will call the delegate function after receiving its final attribution data. Within the delegate function, you will have access to the attribution object.
All properties are returned as a JSON object. Any values that are not populated will be sent back as nil.
| Values | Data type | Description |
|---|---|---|
trackerToken | String | The token of the tracker to which the device is currently attributed. |
trackerName | String | The name of the tracker to which the device is currently attributed. |
network | String | The name of the network to which the device is currently attributed. |
campaign | String | The name of the campaign to which the device is currently attributed. |
adgroup | String | The name of the adgroup to which the device is currently attributed. |
creative | String | The name of the creative to which the device is currently attributed. |
adid | String | The unique Adtrace ID assigned to the device. |
Event and session callbacks
You can register a delegate callback to notify you of the status of event and session tracking.
The Adtrace SDK uses the optional AdtraceDelegate protocol used for the attribution callback.
Add the following delegate callback function for successfully tracked events:
- Objective-C
- Swift
- Javascript
- (void)adtraceEventTrackingSucceeded:(ADJEventSuccess *)eventSuccessResponseData {
// ...
}
func adtraceEventTrackingSucceeded(_ eventSuccessResponseData: ADJEventSuccess?) {
// ...
}
adtraceConfig.setEventSuccessCallback(function(eventSuccess) {
// ...
});
Add the following delegate callback function for failed tracked events:
- Objective-C
- Swift
- Javascript
- (void)adtraceEventTrackingFailed:(ADJEventFailure *)eventFailureResponseData {
// ...
}
func adtraceEventTrackingFailed(_ eventFailureResponseData: ADJEventFailure?) {
// ...
}
adtraceConfig.setEventFailureCallback(function(eventFailure) {
// ...
});
Add the following delegate callback function for successfully tracked sessions:
- Objective-C
- Swift
- Javascript
- (void)adtraceSessionTrackingSucceeded:(ADJSessionSuccess *)sessionSuccessResponseData {
// ...
}
func adtraceSessionTrackingSucceeded(_ sessionSuccessResponseData: ADJSessionSuccess?) {
// ...
}
adtraceConfig.setSessionSuccessCallback(function(sessionSuccess) {
// ...
});
Add the following delegate callback function for failed tracked sessions:
- Objective-C
- Swift
- Javascript
- (void)adtraceSessionTrackingFailed:(ADJSessionFailure *)sessionFailureResponseData {
// ...
}
func adtraceSessionTrackingFailed(_ sessionFailureResponseData: ADJSessionFailure?) {
// ...
}
adtraceConfig.setSessionFailureCallback(function(sessionFailure) {
// ...
});
The SDK will call the delegate functions after it tries to send a package to the Adtrace backend. You have access to a response data object within the delegate callback. This object contains information about the status of the callback. Here is a summary of the returned properties:
Event Parameters
| Property | Data type | Description |
|---|---|---|
message | NSString | The message from the server or the error logged by the SDK. |
timeStamp | NSString | The timestamp from the Adtrace backend. |
adid | NSString | A unique device identifier provided by Adtrace. |
jsonResponse | NSDictionary | The JSON object with the response from the server. |
eventToken | NSString | The event token. |
callbackId | NSString | The custom defined callback ID set on event object. |
willRetry | BOOL | Returned if the event object failed. Indicates whether there will be an attempt to resend the package at a later time. |
Session Parameters
| Property | Data type | Description |
|---|---|---|
message | NSString | The message from the server or the error logged by the SDK. |
timeStamp | NSString | The timestamp from the Adtrace backend. |
adid | NSString | A unique device identifier provided by Adtrace. |
jsonResponse | NSDictionary | The JSON object with the response from the server. |
willRetry | BOOL | Returned if the session object failed. Indicates whether there will be an attempt to resend the package at a later time. |