Skip to content

Latest commit

 

History

History
148 lines (109 loc) · 5.63 KB

AdvancedAPI.md

File metadata and controls

148 lines (109 loc) · 5.63 KB

Advanced API

Option 1 - Send the token as Data to AppsFlyer natively

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)
    }
    
}

Option 2 - Pass the token as a String to AppsFlyer in the ts code

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:

  1. Use FirebaseMessagingService from AppsFlyer SDK - only needs change to AndroidManifest
  2. 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.

Option 1 - AppsFlyer native service

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>

Option 2 - Pass the token as a String to AppsFlyer in the ts code

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));

option 1 (Native):

  1. Add the AppTrackingTransparency framework to your xcode project.
  2. In the Info.plist:
    1. Add an entry to the list: Press + next to Information Property List.
    2. Scroll down and select Privacy - Tracking Usage Description.
    3. Add as the value the wording you want to present to the user when asking for permission to collect the IDFA.
  3. Set a value to the waitForATTUserAuthorization property in the initialization options
  4. 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

Option 2 (3rd party plugin):

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));
  });  
}