Apple Update Token
The Apple Update Token allows you to update Apple's Ads Attribution token for enhanced tracking on iOS devices in Flutter 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
flutter_asa_attribution
Flutter plugin for fetching Apple Search Ads attribution token on iOS.
Requirements:
- iOS 14.3 or later
- AdServices framework
Repository: flutter_asa_attribution
Installation
For Flutter applications, you can use the flutter_asa_attribution
plugin to get the Apple Ads token.
dependencies:
flutter_asa_attribution: ^1.0.0 # Add this to your pubspec.yaml
Usage:
import 'package:flutter_asa_attribution/flutter_asa_attribution.dart';
Future<void> getToken() async {
try {
final token = await FlutterAsaAttribution.getAttributionToken();
print(token);
} catch (error) {
print(error);
}
}
Documentation:
FlutterAsaAttribution.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 null.
Complete Example with SDK Initialization
import 'package:flutter/material.dart';
import 'package:trackier_sdk_flutter/trackier_sdk_flutter.dart';
import 'package:flutter_asa_attribution/flutter_asa_attribution.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void initState() {
super.initState();
initializeSDK();
}
Future<void> initializeSDK() async {
// Initialize SDK
final config = TrackerSDKConfig(
appToken: 'YOUR_APP_TOKEN',
environment: 'production',
);
// Send Token before sdk initialize
if (Platform.isIOS) {
try {
final token = await FlutterAsaAttribution.getAttributionToken();
if (token != null && token.isNotEmpty) {
print('Apple Ads Token: $token');
Trackierfluttersdk.updateAppleAdsToken(token);
} else {
print('Apple Ads Token is empty or null');
}
} catch (error) {
print('Error getting Apple Ads token: $error');
}
}
Trackierfluttersdk.initializeSDK(config);
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Flutter App')),
body: Center(child: Text('Apple Ads Token Example')),
);
}
}
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
- Null Safety: Handle null values properly in Dart
Support
For issues with Apple Update Token implementation, refer to our Support page.