Skip to main content
SDK Version Selection

Choose your SDK version below:

  • Apptrove SDK → Recommended for all projects (Latest: v2.x.x)
  • Trackier SDK → Will be deprecated in August 2026 (Latest legacy: v1.x.xx)

Use the tabs below for SDK-specific snippets.

Apple Update Token

Update Apple's Ads Attribution token before initializing the SDK for enhanced attribution on iOS devices.

Purpose

The main goal is to send the Apple token to the Apptrove SDK using the updateAppleAdsToken(token) method. This enables:

  • Enhanced Attribution: Better tracking of user acquisition from Apple Search Ads
  • Improved Analytics: More accurate campaign performance data
  • Cross-Platform Tracking: Seamless user journey tracking across iOS devices
note

End Goal: Call updateAppleAdsToken(token) on your SDK plugin (Apptrove: apptroveCordovaPlugin.updateAppleAdsToken(token) / Trackier legacy: trackierCordovaPlugin.updateAppleAdsToken(token)).

Requirements

  • iOS 14.3 or later
  • Cordova 9.0 or later

Implementation (Custom Cordova Plugin)

Cordova projects typically require a small custom plugin to fetch Apple's Ads Attribution token via the iOS AdServices framework (iOS 14.3+). Use the plugin below and then pass the returned token to updateAppleAdsToken(token).

Since there are no existing Cordova plugins for Apple Ads attribution, you need to create a custom plugin:

Step 1: Create Custom Plugin

Create a minimal custom plugin for Apple Ads attribution:

<!-- plugin.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-apple-ads-attribution" version="1.0.0">
<name>Apple Ads Attribution</name>
<platform name="ios">
<config-file target="config.xml" parent="/*">
<framework src="AdServices.framework" />
</config-file>
<header-file src="src/ios/AppleAdsAttribution.h" />
<source-file src="src/ios/AppleAdsAttribution.m" />
<js-module src="www/AppleAdsAttribution.js" name="AppleAdsAttribution">
<clobbers target="AppleAdsAttribution" />
</js-module>
</platform>
</plugin>

Step 2: iOS Native Implementation

// src/ios/AppleAdsAttribution.h
#import <Cordova/CDV.h>
#import <AdServices/AdServices.h>

@interface AppleAdsAttribution : CDVPlugin
- (void)getAttributionToken:(CDVInvokedUrlCommand*)command;
@end
// src/ios/AppleAdsAttribution.m
#import "AppleAdsAttribution.h"

@implementation AppleAdsAttribution

- (void)getAttributionToken:(CDVInvokedUrlCommand*)command {
if (@available(iOS 14.3, *)) {
NSError *error = nil;
NSString *token = [AAAttribution attributionTokenWithError:&error];

if (token && !error) {
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:token];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
} else {
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No token available"];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
} else {
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"iOS 14.3+ required"];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
}

@end

Step 3: JavaScript Interface

// www/AppleAdsAttribution.js
cordova.define("cordova-plugin-apple-ads-attribution.AppleAdsAttribution", function(require, exports, module) {
var exec = require('cordova/exec');

var AppleAdsAttribution = {
getAttributionToken: function(successCallback, errorCallback) {
exec(successCallback, errorCallback, 'AppleAdsAttribution', 'getAttributionToken', []);
}
};

module.exports = AppleAdsAttribution;
});

Installation

For Pure Cordova

cordova plugin add ./cordova-plugin-apple-ads-attribution

For Ionic/Capacitor

cordova plugin add ./cordova-plugin-apple-ads-attribution
npx cap sync ios

Usage

Get Token Before SDK Initialization

document.addEventListener('deviceready', function() {
initializeSDK();
});

async function initializeSDK() {
// Get Apple Ads token first
await updateAppleAdsToken();

// Initialize SDK
const config = {
appToken: 'YOUR_APP_TOKEN',
environment: 'production'
};

AppTroveCordovaPlugin.initializeSDK(config);
}

async function updateAppleAdsToken() {
try {
let token = null;

// For custom Cordova plugin
if (window.AppleAdsAttribution) {
token = await new Promise((resolve, reject) => {
AppleAdsAttribution.getAttributionToken(
(token) => resolve(token),
(error) => reject(error)
);
});
}

if (token) {
AppTroveCordovaPlugin.updateAppleAdsToken(token);
}
} catch (error) {
console.error('Error getting Apple Ads token:', error);
}
}

Function Reference

MethodDescriptionParametersReturns
updateAppleAdsToken(token)Update Apple Ads token in the SDKStringPromise

Important Notes

  • iOS Only: Apple Ads token is available on iOS 14.3+
  • Before Initialization: Always get token before initializing the SDK
  • Physical Device: Test on physical device, not simulator
  • SDK Method: Use AppTroveCordovaPlugin.updateAppleAdsToken() / TrackierCordovaPlugin.updateAppleAdsToken() for Cordova, or the corresponding injected plugin instance for Ionic Native.

Support