Code sample for AppDelegate.swift: Example:
import UIKit
import Capacitor
import AppsFlyerLib
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 10, *) {
UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in }
application.registerForRemoteNotifications()
}
else if #available(iOS 9, *) {
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
UIApplication.shared.registerForRemoteNotifications()
}
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
AppsFlyerLib.shared().registerUninstall(deviceToken)
}
}
Note : If you use this method you will need to collect the APNs token using a third party platform of your choice.
AppsFlyer.updateServerUninstallToken({token: 'replace_with_token'});
Read more about Uninstall register: Appsflyer SDK support site
There are 2 main approaches of enabling uninstall measurement for Android:
- Use FirebaseMessagingService from AppsFlyer SDK - only needs change to AndroidManifest
- Manually pass token to SDK - should be used if you have custom logic in place when token us updated.
For more info on Android Uninstall setup check out the guide here.
If the sole purpose of integrating FCM is to measure uninstalls in AppsFlyer, use appsFlyer.FirebaseMessagingServiceListener
service, embedded in the SDK. This extends the FirebaseFirebaseMessagingService class, used to receive the FCM Device Token.
To add appsFlyer.FirebaseMessagingServiceListener
service to the app, place the following in your AndroidManifest.xml
:
<application
<!-- ... -->
<service
android:name="com.appsflyer.FirebaseMessagingServiceListener">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<!-- ... -->
</application>
Note : If you use this method you will need to collect the FCM's token using a third party platform of your choice.
AppsFlyer.updateServerUninstallToken({token: 'replace_with_token'});
Read more about Android Uninstall Tracking: Appsflyer SDK support site
AppsFlyer allows you to attribute and record installs originating from user invites within your app. Allowing your existing users to invite their friends and contacts as new users to your app can be a key growth factor for your app.
Example:
AppsFlyer.generateInviteLink({
addParameters: {code: '1256abc', page: '152'},
campaign: 'appsflyer_plugin',
channel: 'sms'
})
.then(r => alert('user invite link: ' + r.link))
.catch(e => alert('user invite error: ' + e));
- Add the
AppTrackingTransparency
framework to your xcode project. - In the
Info.plist
:- Add an entry to the list: Press + next to
Information Property List
. - Scroll down and select
Privacy - Tracking Usage Description
. - Add as the value the wording you want to present to the user when asking for permission to collect the IDFA.
- Add an entry to the list: Press + next to
- Set a value to the
waitForATTUserAuthorization
property in the initialization options - In the
CAPBridgeViewController.swift
file, add:
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { (status) in }
}
}
For more info visit our Support integration guide Here
You can use this plugin: capacitor-plugin-app-tracking-transparency
import {AppsFlyer ,AFInit} from 'appsflyer-capacitor-plugin';
constructor(public platform: Platform) {
this.platform.ready().then(() => {
......
......
AppsFlyer.initSDK(options).then(res => alert(JSON.stringify(res))).catch(e =>alert(e));
AppTrackingTransparency.requestPermission().then(res => alert('ATT status: ' + res.status));
});
}