Apple Update Token
The Apple Update Token allows you to update Apple's Ads Attribution token for enhanced tracking on iOS devices in Expo applications.
What is Apple Update Token?
Apple's Ads Attribution token helps maintain user attribution across app updates and reinstalls, ensuring continuous tracking and data continuity.
Library Reference
react-native-attribution-token
React Native module for fetching attribution token on iOS.
Requirements:
- AdServices framework (iOS)
Repository: react-native-attribution-token
Installation
First, install the react-native-attribution-token
library to get the Apple Ads token:
npm install react-native-attribution-token
Usage:
import { getAttributionToken } from 'react-native-attribution-token';
const getToken = async () => {
try {
const token = await getAttributionToken();
console.log(token);
} catch (error) {
console.log(error);
}
};
Documentation:
getAttributionToken()
- Fetches the attribution token from the AdServices framework on iOS. Returns a promise that resolves to the attribution token.- On Android, this method will return a promise that resolves to null.
Complete Example with SDK Initialization
import React, { useEffect } from 'react';
import { TrackierSDK, TrackierConfig } from 'trackier-expo-sdk';
import { getAttributionToken } from 'react-native-attribution-token';
const App = () => {
const getAppleAdsToken = async () => {
try {
const token = await getAttributionToken();
console.log('Apple Ads Token:', token);
return token;
} catch (error) {
console.log('Error getting Apple Ads token:', error);
return null;
}
};
useEffect(() => {
const initializeSDK = async () => {
// Initialize SDK
const config = new TrackierConfig('YOUR_APP_TOKEN', 'production');
// Get Apple Ads token before initializing SDK
const appleAdsToken = await getAppleAdsToken();
if (appleAdsToken) {
TrackierSDK.updateAppleAdsToken(appleAdsToken);
}
// Initialize SDK after updating token
TrackierSDK.initialize(config);
};
initializeSDK();
}, []);
return (
// Your app component
);
};
Function Reference
Method | Description | Parameters | Returns |
---|---|---|---|
updateAppleAdsToken(token) | Update Apple Ads token | String | void |
Where to Add
- App Launch: Update token when your app starts
- Token Refresh: Update when you receive a new token from your server
- Deep Link Handling: Update token before processing deep links
Best Practices
- Validate Token: Ensure token is not empty and has proper format
- Error Handling: Wrap in try-catch for network errors
- Storage: Store token securely for future use
- Platform Check: Only call on iOS devices
- Async Handling: Use async/await for token retrieval
Support
For issues with Apple Update Token implementation, refer to our Support page.