Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

appsflyer

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

appsflyer

Cordova AppsFlyer Plugin

  • 4.2.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

Cordova/PhoneGap AppsFlyer plugin for Android and iOS. npm version Build Status

Supported Platforms

  • Android
  • iOS 8+

Cordova >= 4.3.x.

This plugin is built for

  • iOS AppsFlyerSDK v4.5.9
  • Android AppsFlyerSDK v4.6.0

Installation using CLI:

$ cordova plugin add appsflyer

or directly from git:

$ cordova plugin add https://github.com/AppsFlyerSDK/PhoneGap.git

Manual installation:

1. Add the following xml to your config.xml in the root directory of your www folder:

<!-- for iOS -->
<feature name="AppsFlyerPlugin">
  <param name="ios-package" value="AppsFlyerPlugin" />
</feature>
<!-- for Android -->
<feature name="AppsFlyerPlugin">
  <param name="android-package" value="com.appsflyer.cordova.plugin.AppsFlyerPlugin" />
</feature>

2. For Android, add the following xml to your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

3. Copy appsflyer.js to www/js/plugins and reference it in index.html:

<script type="text/javascript" src="js/plugins/appsflyer.js"></script>

4. Download the source files and copy them to your project.

#####iOS: Copy:

  • AppsFlyerPlugin.h
  • AppsFlyerPlugin.m
  • AppsFlyerTracker.h
  • libAppsFlyerLib.a to platforms/ios/<ProjectName>/Plugins

#####Android: Copy AppsFlyerPlugin.java to platforms/android/src/com/appsflyer/cordova/plugins (create the folders)

Usage:

1. 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. -appId - For iOS only. Your iTunes Application ID.

Add the following lines to your code to be able to initialize tracking with your own AppsFlyer dev key:

for pure Cordova:

document.addEventListener("deviceready", function(){
    
   var options = {
             devKey:  'xxXXXXXxXxXXXXxXXxxxx8'// your AppsFlyer devKey               
           };

    var userAgent = window.navigator.userAgent.toLowerCase();
                          
    if (/iphone|ipad|ipod/.test( userAgent )) {
        options.appId = "123456789";            // your ios app id in app store        
    }
    window.plugins.appsFlyer.initSdk(options);
}, false);

For Ionic

  $ionicPlatform.ready(function() {      
    
    var options = {
           devKey:  'xxXXXXXxXxXXXXxXXxxxx8'// your AppsFlyer devKey               
         };
                              
    if (ionic.Platform.isIOS()) {
        options.appId = "123456789";            // your ios app id in app store 
    }

      window.plugins.appsFlyer.initSdk(options);      
  });

API Methods


initSdk(options, onSuccess, onError): void

initialize the SDK.

parametertypedescription
optionsObjectSDK configuration
onSuccess(message: string)=>voidSuccess callback - called after successfull SDK initialization. (optional)
onError(message: string)=>voidError callback - called when error occurs during initialization. (optional)

options

nametypedefaultdescription
devKeystringAppsflyer Dev key
appIdstringApple Application ID (for iOS only)
isDebugbooleantruedebug mode (optional)

Example:

var onSuccess = function(result) {
     //handle result
};

function onError(err) {
    // handle error
}
var options = {
               devKey:  'd3Ac9qPnrpVYZxfWmCspwL',
               appId: '123456789',
               isDebug: false
             };
window.plugins.appsFlyer.initSdk(options, onSuccess, onError);

trackEvent(eventName, eventValues): void (optional)

  • These in-app events help you track how loyal users discover your app, and attribute them to specific campaigns/media-sources. Please take the time define the event/s you want to measure to allow you to track ROI (Return on Investment) and LTV (Lifetime Value).
  • The trackEvent method allows you to send in-app events to AppsFlyer analytics. This method allows you to add events dynamically by adding them directly to the application code.
parametertypedescription
eventNameStringcustom event name, is presented in your dashboard. See the Event list HERE
eventValueObjectevent details

Example:

var eventName = "af_add_to_cart";
var eventValues = {
           "af_content_id": "id123",
           "af_currency":"USD",
           "af_revenue": "2"
           };
window.plugins.appsFlyer.trackEvent(eventName, eventValues);

setCurrencyCode(currencyId): void

parametertypeDefaultdescription
currencyIdStringUSDISO 4217 Currency Codes

Examples:

window.plugins.appsFlyer.setCurrencyCode("USD");
window.plugins.appsFlyer.setCurrencyCode("GBP"); // British Pound

setAppUserId(customerUserId): void

Setting your own Custom ID enables you to cross-reference your own unique ID with AppsFlyer’s user ID and the other devices’ IDs. This ID is available in AppsFlyer CSV reports along with postbacks APIs for cross-referencing with you internal IDs.

Note: The ID must be set during the first launch of the app at the SDK initialization. The best practice is to call this API during the deviceready event, where possible.

parametertypedescription
customerUserIdString

Example:

window.plugins.appsFlyer.setAppUserId(userId);

setGCMProjectID(GCMProjectID): void

Set the GCM API key. AppsFlyer requires a Google Project Number and GCM API Key to enable uninstall tracking.

parametertypedescription
GCMProjectIDString

registerUninstall(token): void

AEnables tracking app. uninstalls.

parametertypedescription
tokenString

getAppsFlyerUID(successCB): void (Advanced)

Get AppsFlyer’s proprietary Device ID. The AppsFlyer Device ID is the main ID used by AppsFlyer in Reports and APIs.

function getUserIdCallbackFn(id){/* ... */} 
window.plugins.appsFlyer.getAppsFlyerUID(getUserIdCallbackFn);

Example:

var getUserIdCallbackFn = function(id) {
    alert('received id is: ' + id);
}
window.plugins.appsFlyer.getAppsFlyerUID(getUserIdCallbackFn);
parametertypedescription
getUserIdCallbackFn() => voidSuccess callback

onInstallConversionDataLoaded(conversionData): void

Accessing AppsFlyer Attribution / Conversion Data from the SDK (Deferred Deeplinking). Read more: Android, iOS
Note: AppsFlyer plugin will fire onInstallConversionDataLoaded event with attribution data. You must implement onInstallConversionDataLoaded listener to receive the data.

parametertypedescription
conversionDataObject

Example:

document.addEventListener('onInstallConversionDataLoaded', function(e){
    var attributionData = (JSON.stringify(e.detail));
    alert(attributionData);
}, false);

Deeplinking Tracking

Android

In ver. 4.2.5 deeplinking metadata (scheme/host) is sent automatically

iOS

Open in Xcode AppDelegate.m, add #import "AppsFlyerTracker.h" and add the following method under application: openURL :

[[AppsFlyerTracker sharedTracker] handleOpenURL:url sourceApplication:sourceApplication withAnnotation:annotation];

It appears as follows:

-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    
    [[AppsFlyerTracker sharedTracker] handleOpenURL:url sourceApplication:sourceApplication withAnnotation:annotation];
    return YES;
}

Sample app:

We have posted af-cordova-ionic-demo as s separate repo in github, you can download and run it.

Keywords

FAQs

Package last updated on 13 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc