
  
<img src="https://raw.githubusercontent.com/AppsFlyerSDK/appsflyer-capacitor-plugin/main/assets/AFLogo_primary.png"  width="600">  
  
# Cordova AppsFlyer plugin for Android and iOS.   
[![npm version](https://badge.fury.io/js/cordova-plugin-appsflyer-sdk.svg)](https://badge.fury.io/js/cordova-plugin-appsflyer-sdk)  
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)   
[![Downloads](https://img.shields.io/npm/dm/cordova-plugin-appsflyer-sdk.svg)](https://www.npmjs.com/package/cordova-plugin-appsflyer-sdk)  
  ----------  
🛠 In order for us to provide optimal support, please contact AppsFlyer support through the Customer Assistant Chatbot for assistance with troubleshooting issues or product guidance. </br>
To do so, please follow [this article](https://support.appsflyer.com/hc/en-us/articles/23583984402193-Using-the-Customer-Assistant-Chatbot)
  
----------  
###  <a id="capacitornote"> <img src="https://cdn.icon-icons.com/icons2/2107/PNG/512/file_type_capacitor_icon_130703.png"  width="30">    <img src="https://cdn.icon-icons.com/icons2/2107/PNG/512/file_type_capacitor_icon_130703.png"  width="30"> ⚠️ Note for Capacitor users  ⚠️  <img src="https://cdn.icon-icons.com/icons2/2107/PNG/512/file_type_capacitor_icon_130703.png" width="30">  <img src="https://cdn.icon-icons.com/icons2/2107/PNG/512/file_type_capacitor_icon_130703.png"  width="30">  <br>  
**Please check out our brand new [Capacitor plugin](https://github.com/AppsFlyerSDK/appsflyer-capacitor-plugin).** <br>  
This plugin is not 100% compatible for use with Capacitor! To use this plugin with Capacitor, you have to make changes and customize the code by yourself. (Feel free to fork the project)

----------  
**❗️Important** <br>  
- Cordova AppsFlyer plugin version **4.4.0** and higher are meant to be used with **cordova-android@7.0.0** and up <br>  
For lower versions of cordova-android please use plugin version 4.3.3 available @ https://github.com/AppsFlyerSDK/cordova-plugin-appsflyer-sdk/tree/4.3.3 <br>  
- From version **6.1.10** the plugin uses cocoapods(NOT StaticLib) in order to support iOS app-kids Strict mode. <br>  
You can read more [here](https://support.appsflyer.com/hc/en-us/articles/207032066#integration-strict-mode-sdk)
- From version **6.10.2** the plugin requires using the implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.6.20' in Android.
- From version **6.14.3** the plugin requires Target version 12 and higher in iOS.
- From version **6.15.11** the plugin requires adding the value '/usr/lib/swift' to Build Settings 'RunPath Search Paths' key in iOS.
----------  

  
## Table of content  
  
- [SDK versions](#plugin-build-for)  
- [V7 Breaking Changes](#breakingChangesV7)  
- [V6 Breaking Changes](#breakingChanges)  
- [Installation](#installation)  
- [Strict mode for app-kids](#appKids)  
- [Guides](#guides)  
- [Setup](#setup)  
- [API](#api)   
- [Demo](#demo)    
- [Ionic](#ionic)  
  
  
### <a id="plugin-build-for"> This plugin is built for  
  
- iOS AppsFlyerSDK **v7.0.41** (AppsFlyerRPC **v7.0.41**)
- Android AppsFlyerSDK **v7.0.4** (af-android-plugin-bridge **v7.0.13**)

### <a id="breakingChangesV7"> ❗v7 Breaking Changes — no backward compatibility

Plugin **v7.0.2** moves onto AppsFlyer's shared RPC core (`AppsFlyerRPC` on iOS,
`af-android-plugin-bridge` on Android, `@appsflyer-sdk/js-core-plugin` in JS). This is a **major,
intentionally breaking release** — old method names, callback-style calls, and a few methods with
no equivalent in the new schema are gone, not deprecated. There is no compatibility shim; update
every call site. Full method-by-method mapping: [RELEASENOTES.md](/RELEASENOTES.md#702) /
[API.md](/docs/API.md).

- **Every method is now Promise-based.** `fn(args, successCB, errorCB)` → `await AppsFlyer.fn(params)`.
  Failures throw (`AppsFlyerRpcError` for transport failures, `AppsFlyerError` for SDK failures)
  instead of calling an error callback.
- **Renamed:** `initSdk`→`init`, `startSdk`→`start`, `setAppUserId`→`setCustomerUserId`,
  `Stop`→`stop`, `logCrossPromotionAndOpenStore`→`logAndOpenStore`,
  `setPhoneNumber`→`setUserPhone` (now requires `countryCode`), `setUserEmails`→`setUserEmail`
  (single email, not an array), and more — see [API.md](/docs/API.md) for every signature.
- **Removed, no replacement:** `registerOnAppOpenAttribution` (folded into
  `registerDeepLinkListener`), `registerUninstall`, `setSharingFilter`/`setSharingFilterForAllPartners`
  (already deprecated, superseded by `setSharingFilterForPartners`), the `AppsFlyerConsent` and
  `AFPurchaseDetails` classes (pass a plain object instead).
- **`start()` is no longer implicit after `init()`** — call it from inside
  `registerSessionReadyListener`'s callback. See the updated example below.
- **Dependencies:** iOS pod is now `AppsFlyerRPC` (was `AppsFlyerFramework`). Android needs
  **JDK 21** to build (was 17). See [Installation.md](/docs/Installation.md).

### <a id="breakingChanges"> ❗v6.15.11 Breaking Changes

iOS platform:
The plugin requires adding the value '/usr/lib/swift' to Build Settings 'RunPath Search Paths' key in iOS, Otherwise there might be some compilation errors.
  
### <a id="breakingChanges"> ❗v6.14.3 Breaking Changes  

Android platform: 
In order to receive data regarding install-referrer from AppGallery now, there is a need to add implementation to the gradle file. <br>
following the instructions in [this](https://dev.appsflyer.com/hc/docs/install-android-sdk#huawei-install-referrer) link. <br>
please follow also these Cordova doc guidlines [here](https://cordova.apache.org/docs/en/11.x/guide/platforms/android/#extending-buildgradle).


### <a id="breakingChanges"> ❗v6 Breaking Changes  
  
We have renamed the following APIs:  
  
| Old API | New API |  
|---------|---------|  
|trackEvent      |  logEvent|  
|stopTracking      |  Stop|  
|trackCrossPromotionImpression |  logCrossPromotionImpression|  
|trackAndOpenStore      |  logCrossPromotionAndOpenStore|  
|setDeviceTrackingDisabled      |  anonymizeUser|  
  
  
## <a id="installation">📲Installation  
  
```  
$ cordova plugin add cordova-plugin-appsflyer-sdk  
```  
To install cordova manually check out the doc [here](/docs/Installation.md).  
  
> **_NOTE:_** for Ionic installation see [this](#ionic) section  

  
## ⚠️ Adding AD_ID permission for Android ⚠️
In v6.8.0 of the AppsFlyer SDK, we added the normal permission `com.google.android.gms.permission.AD_ID` to the SDK's AndroidManifest, 
to allow the SDK to collect the Android Advertising ID on apps targeting API 33.
If your app is targeting children, you need to revoke this permission to comply with Google's Data policy.
You can read more about it [here](https://dev.appsflyer.com/hc/docs/install-android-sdk#the-ad_id-permission). </br>

## <a id="appKids">👨‍👩‍👧‍👦 Strict mode for app-kids  
Use strict mode to completely remove IDFA and Advertising ID collection (for example, when developing apps for kids under COPPA or Google Play Families policy).

### Enabling strict mode

Add the `AppsFlyerStrictMode` preference to your app's `config.xml`:

```xml
<preference name="AppsFlyerStrictMode" value="true" />
```

During `cordova prepare`, the plugin automatically:
- **iOS:** Switches the CocoaPods dependency to `AppsFlyerRPC/Strict` (which pulls `AppsFlyerFramework/Strict`) and runs `pod install`.
- **Android:** Removes the `com.google.android.gms.permission.AD_ID` permission from the prepared `AndroidManifest.xml`.

To disable strict mode, remove the preference or set its value to `"false"`. The hook restores the standard dependencies on the next `cordova prepare`.  
  
  ## <a id="guides"> 📖 Guides  
  
Great installation and setup guides can be viewed [here](/docs/Guides.md).  
- [init SDK Guide](/docs/Guides.md#init-sdk)  
- [Deeplinking Guide](/docs/Guides.md#deeplinking)  
- [Uninstall Guide](/docs/Guides.md#uninstall)  
- [Set plugin for IOS 14](/docs/Guides.md#ios14)  
- [Send SKAN postback copies for IOS 15](/docs/Guides.md#skanPostback)  
  
  
## <a id="setup"> 🚀 Setup  
  
####  Set your App_ID (iOS only), Dev_Key and enable AppsFlyer to detect installations, sessions (app opens) and updates. > This is the minimum requirement to start tracking your app installs and is already implemented in this plugin. You **MUST** modify this call and provide:    
 **devKey** - Your application devKey provided by AppsFlyer.<br>  
**appId**  - ***For iOS only.*** Your iTunes Application ID.<br>  

  
Add the following lines to your code to be able to initialize tracking with your own AppsFlyer dev key:  
  
  
```javascript  
document.addEventListener('deviceready', async function() {  

  const AppsFlyer = window.plugins.appsFlyer;

  // Register the deep-link listener before init().
  await AppsFlyer.registerDeepLinkListener({
    onDeepLinking: (data) => console.log(data),
  });

  await AppsFlyer.init({
    devKey: 'K2***************99', // your AppsFlyer devKey
    appId: '41*****44', // your iOS appID
  });

  // start() is no longer implicit after init() — call it once the session is ready.
  await AppsFlyer.registerSessionReadyListener(() => {
    AppsFlyer.start().catch((error) => console.error(error));
  });

}, false);  
```  
---  
  
  
## <a id="api"> 📑 API  
  See the full [API](/docs/API.md) available for this plugin.  
  
  
## <a id="demo"> 📱 Demo  
Clone this Git repository to use the demo apps; the npm package doesn't include `examples/`. The repository contains two demos, each with its own `Makefile`:  
- [`examples/cordovatestapp`](/examples/cordovatestapp): plain Cordova (JavaScript)  
- [`examples/ionic-cordova`](/examples/ionic-cordova): Angular + Ionic  

In either folder, copy `.env.example` to `.env` and fill in your `DEV_KEY` and `APP_ID`, then run:  
```sh  
make ios      # build and run on an iOS simulator  
make android  # build and run on an Android emulator  
```  
`make help` lists the available targets, and `make clean` removes the synced-out build copy.  
Check out our Sample-App  **Let's cook!** [here](https://github.com/AppsFlyerSDK/appsflyer-cordova-app) if you want to implement our SDK inside React-Cordova app  
## <a id="ionic"> 📍 Ionic  
***NOTICE!*** In AppsFlyer Cordova plugin version 6.x.x we replaced the word ``track`` with ``log`` from all our api but Ionic-Navite Appsflyer plugin still uses ``track``<br>  
So the latest version that can work with Ionic-Native for now is **5.4.30**<br>  
  
###  Using the `window` object directly  
Install the cordova plugin:  
```  
$ ionic cordova plugin add cordova-plugin-appsflyer-sdk  
```  
In your main ts file, declare a window variable:  
```javascript  
declare var window;  
```  
Now you can use the AppsFlyer plugin directly from cordova:  
```javascript  
import {Component} from '@angular/core';  
import {Platform} from '@ionic/angular';  
  
declare var window;  
...  
export class HomePage {  
  constructor(public platform: Platform) {  
  this.platform.ready().then(async () => {  
  const AppsFlyer = window.plugins.appsFlyer;
  await AppsFlyer.registerDeepLinkListener({ onDeepLinking: (data) => console.log(data) });
  await AppsFlyer.init({ devKey, appId });
  await AppsFlyer.registerSessionReadyListener(() => {
    AppsFlyer.start().catch((error) => console.error(error));
  });
 }); }}  
```  
  

Check out the full [API](/docs/API.md) for more information
