Skip to main content

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 typeMechanismWhen it runs
AttributionAdtraceDelegateAfter the SDK receives final or updated attribution data
Event success / failureAdtraceDelegateAfter the SDK tries to send an event package
Session success / failureAdtraceDelegateAfter the SDK tries to send a session package
Deferred deep linkAdtraceDelegateBefore the SDK opens a deferred deep link. See Deep linking
Delegate vs URL callback parameters

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.

Important

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

AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate, AdtraceDelegate>
@end

2. Register the delegate on ADTConfig

Call setDelegate: before appDidLaunch:

AppDelegate.m
NSString *appToken = @"{YourAppToken}";
NSString *environment = ADTEnvironmentSandbox;
ADTConfig *adtraceConfig = [ADTConfig configWithAppToken:appToken
environment:environment];
[adtraceConfig setDelegate: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

- (void)adtraceAttributionChanged:(ADTAttribution *)attribution {
NSLog(@"Tracker token: %@", attribution.trackerToken);
NSLog(@"Network: %@", attribution.network);
}

ADTAttribution properties

Any value that is not set for the user is returned as nil.

PropertyTypeDescription
trackerTokenNSStringToken of the tracker the device is currently attributed to.
trackerNameNSStringName of the tracker the device is currently attributed to.
networkNSStringNetwork the device is currently attributed to.
campaignNSStringCampaign the device is currently attributed to.
adgroupNSStringAd group the device is currently attributed to.
creativeNSStringCreative the device is currently attributed to.
clickLabelNSStringClick label tagged on the install.
adidNSStringUnique Adtrace device identifier.
costTypeNSStringCampaign pricing model (for example cpi). Requires cost data in attribution.
costAmountNSNumberCost of the install. Requires cost data in attribution.
costCurrencyNSStringISO 4217 currency code for the cost. Requires cost data in attribution.
tip

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

PropertyTypeDescription
messageNSStringMessage from the server, or an error logged by the SDK.
timeStampNSStringTimestamp from Adtrace servers.
adidNSStringUnique Adtrace device identifier.
jsonResponseNSDictionaryJSON object with the server response.
willRetryBOOLOn failure only. YES if the SDK will try to resend the package later.

Session success

- (void)adtraceSessionTrackingSucceeded:(nullable ADTSessionSuccess *)sessionSuccessResponseData;
- (void)adtraceSessionTrackingSucceeded:(ADTSessionSuccess *)sessionSuccessResponseData {
NSLog(@"Session recorded at %@", sessionSuccessResponseData.timeStamp);
}

Session failure

- (void)adtraceSessionTrackingFailed:(nullable ADTSessionFailure *)sessionFailureResponseData;
- (void)adtraceSessionTrackingFailed:(ADTSessionFailure *)sessionFailureResponseData {
NSLog(@"Session recording failed: %@", sessionFailureResponseData.message);
}

Event callbacks

Response data

PropertyTypeDescription
messageNSStringMessage from the server, or an error logged by the SDK.
timeStampNSStringTimestamp from Adtrace servers.
adidNSStringUnique Adtrace device identifier.
eventTokenNSStringThe event token.
callbackIdNSStringCustom callback ID set on the event with setCallbackId, if any.
jsonResponseNSDictionaryJSON object with the server response.
willRetryBOOLOn failure only. YES if the SDK will try to resend the package later.

Event success

- (void)adtraceEventTrackingSucceeded:(nullable ADTEventSuccess *)eventSuccessResponseData;
- (void)adtraceEventTrackingSucceeded:(ADTEventSuccess *)eventSuccessResponseData {
NSLog(@"Event %@ recorded at %@", eventSuccessResponseData.eventToken, eventSuccessResponseData.timeStamp);
}

Event failure

- (void)adtraceEventTrackingFailed:(nullable ADTEventFailure *)eventFailureResponseData;
- (void)adtraceEventTrackingFailed:(ADTEventFailure *)eventFailureResponseData {
NSLog(@"Event recording failed: %@", eventFailureResponseData.message);
}