- initSdk
- appId
- onInstallConversionData
- onAppOpenAttribution
- logEvent
- setCustomerUserId
- getAppsFlyerUID
- stop
- logLocation
- setUserEmails
- setAdditionalData
- updateServerUninstallToken
- setCollectIMEI
- setCollectAndroidID
- setAppInviteOneLinkID
- generateInviteLink
- logCrossPromotionImpression
- logCrossPromotionAndOpenStore
- setCurrencyCode
- anonymizeUser
- setOneLinkCustomDomains
- setResolveDeepLinkURLs
- performOnAppAttribution
- setSharingFilterForAllPartners Deprecated!
- setSharingFilter Deprecated!
- disableCollectASA
- disableAdvertisingIdentifier
- validateAndLogInAppPurchase
- sendPushNotificationData
- setHost
- addPushNotificationDeepLinkPath
- disableSKAD
- setCurrentDeviceLanguage
- setSharingFilterForPartners
Initialize the AppsFlyer SDK with the devKey and appID.
The dev key is required for all apps and the appID is required only for iOS.
(you may pass the appID on Android as well, and it will be ignored)
parameter | type | description |
---|---|---|
options | json | init options |
success | function | success callback |
error | function | error callback |
Option | Description |
---|---|
devKey | Your application devKey provided by AppsFlyer (required) |
appId | Your iTunes application ID (iOS only) |
isDebug | Debug mode - set to true for testing only |
onInstallConversionDataListener | Set listener for SDK init response (Optional. default=true) |
onDeepLinkListener | Set listener for DDL response (Optional. default=false) |
Example: |
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import appsFlyer from 'react-native-appsflyer';
appsFlyer.initSdk(
{
devKey: 'K2***********99',
isDebug: false,
appId: '41*****44',
onInstallConversionDataListener: false, //Optional
onDeepLinkListener: true, //Optional
},
(res) => {
console.log(res);
},
(err) => {
console.error(err);
}
);
With Promise:
try {
var res = await appsFlyer.initSdk(options);
} catch (err) {}
AppsFlyer app ID property populated from options
passed in the initSdk
function. Can be used to read appId back later in the app
Example:
var appId = appsFlyer.appId;
Accessing AppsFlyer Attribution / Conversion Data from the SDK (Deferred Deeplinking).
The code implementation for the conversion listener must be made prior to the initialization code of the SDK.
parameter | type | description |
---|---|---|
callback | function | conversion data result |
Example:
this.onInstallConversionDataCanceller = appsFlyer.onInstallConversionData(
(res) => {
if (JSON.parse(res.data.is_first_launch) == true) {
if (res.data.af_status === 'Non-organic') {
var media_source = res.data.media_source;
var campaign = res.data.campaign;
alert('This is first launch and a Non-Organic install. Media source: ' + media_source + ' Campaign: ' + campaign);
} else if (res.data.af_status === 'Organic') {
alert('This is first launch and a Organic Install');
}
} else {
alert('This is not first launch');
}
}
);
appsFlyer.initSdk(/*...*/);
Example onInstallConversionData:
{
"data": {
"af_message": "organic install",
"af_status": "Organic",
"is_first_launch": "true"
},
"status": "success",
"type": "onInstallConversionDataLoaded"
}
Note is_first_launch will be "true" (string) on Android and true (boolean) on iOS. To solve this issue wrap is_first_launch with JSON.parse(res.data.is_first_launch) as in the example above.
appsFlyer.onInstallConversionData
returns a function the will allow us to call NativeAppEventEmitter.remove()
.
Therefore it is required to call the canceller method in the next appStateChange callback.
This is required for both the onInstallConversionData
and onAppOpenAttribution
callbacks.
Example:
_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/active|foreground/) && nextAppState === 'background') {
if (this.onInstallConversionDataCanceller) {
this.onInstallConversionDataCanceller();
this.onInstallConversionDataCanceller = null;
}
if (this.onAppOpenAttributionCanceller) {
this.onAppOpenAttributionCanceller();
this.onAppOpenAttributionCanceller = null;
}
}
parameter | type | description |
---|---|---|
callback | function | deeplink data result |
Example:
this.onAppOpenAttributionCanceller = appsFlyer.onAppOpenAttribution((res) => {
console.log(res);
});
appsFlyer.initSdk(/*...*/);
In-App Events provide insight on what is happening in your app. It is recommended to take the time and define the events you want to measure to allow you to measure ROI (Return on Investment) and LTV (Lifetime Value).
Recording in-app events is performed by calling sendEvent with event name and value parameters. See In-App Events documentation for more details.
Note: An In-App Event name must be no longer than 45 characters. Events names with more than 45 characters do not appear in the dashboard, but only in the raw Data, Pull and Push APIs.
parameter | type | description |
---|---|---|
eventName | string | The name of the event |
eventValues | json | The event values that are sent with the event |
success | function | success callback |
error | function | success callback |
Example:
const eventName = 'af_add_to_cart';
const eventValues = {
af_content_id: 'id123',
af_currency: 'USD',
af_revenue: '2',
};
appsFlyer.logEvent(
eventName,
eventValues,
(res) => {
console.log(res);
},
(err) => {
console.error(err);
}
);
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: This must be set before initSdk
is called.
parameter | type | description |
---|---|---|
userId | string | user ID |
callback | function | success callback |
Example:
appsFlyer.setCustomerUserId('some_user_id', (res) => {
//..
});
AppsFlyer's unique device ID is created for every new install of an app. Use the following API to obtain AppsFlyer’s Unique ID.
parameter | type | description |
---|---|---|
callback | function | returns (error, appsFlyerUID) |
Example:
appsFlyer.getAppsFlyerUID((err, appsFlyerUID) => {
if (err) {
console.error(err);
} else {
console.log('on getAppsFlyerUID: ' + appsFlyerUID);
}
});
In some extreme cases you might want to shut down all SDK functions due to legal and privacy compliance. This can be achieved with the stopSDK API. Once this API is invoked, our SDK no longer communicates with our servers and stops functioning.
There are several different scenarios for user opt-out. We highly recommend following the exact instructions for the scenario, that is relevant for your app.
In any event, the SDK can be reactivated by calling the same API, by passing false.
parameter | type | description |
---|---|---|
isStopped | boolean | True if the SDK is stopped (default value is false). |
callback | function | success callback |
Example:
appsFlyer.stop(true, (res) => {
//...
});
Manually record the location of the user.
parameter | type | description |
---|---|---|
longitude | float | longitude |
latitude | float | latitude |
callback | function | Success / Error Callbacks |
Example:
const latitude = -18.406655;
const longitude = 46.40625;
appsFlyer.logLocation(longitude, latitude, (err, coords) => {
if (err) {
console.error(err);
} else {
//...
}
});
Set the user emails and encrypt them.
parameter | type | description |
---|---|---|
configuration | json | email configuration |
success | function | success callback |
error | function | error callback |
option | type | description |
---|---|---|
emailsCryptType | int | none - 0 (default), SHA1 - 1, MD5 - 2, SHA256 - 3 |
emails | array | comma separated list of emails |
Example:
const options = {
emailsCryptType: 2,
emails: ['[email protected]', '[email protected]'],
};
appsFlyer.setUserEmails(
options,
(res) => {
//...
},
(err) => {
console.error(err);
}
);
The setAdditionalData API is required to integrate on the SDK level with several external partner platforms, including Segment, Adobe and Urban Airship. Use this API only if the integration article of the platform specifically states setAdditionalData API is needed.
parameter | type | description |
---|---|---|
additionalData | json | additional data |
callback | function | success callback |
Example:
appsFlyer.setAdditionalData(
{
val1: 'data1',
val2: false,
val3: 23,
},
(res) => {
//...
}
);
(Android only)
Manually pass the Firebase / GCM Device Token for Uninstall measurement.
parameter | type | description |
---|---|---|
token | string | FCM Token |
callback | function | success callback |
Example:
appsFlyer.updateServerUninstallToken('token', (res) => {
//...
});
❗(Android only)
Opt-out of collection of IMEI.
If the app does NOT contain Google Play Services, device IMEI is collected by the SDK.
However, apps with Google play services should avoid IMEI collection as this is in violation of the Google Play policy.
parameter | type | description |
---|---|---|
isCollect | boolean | opt-in boolean |
callback | function | success callback |
Example:
if (Platform.OS == 'android') {
appsFlyer.setCollectIMEI(false, (res) => {
//...
});
}
❗(Android only)
Opt-out of collection of Android ID.
If the app does NOT contain Google Play Services, Android ID is collected by the SDK.
However, apps with Google play services should avoid Android ID collection as this is in violation of the Google Play policy.
parameter | type | description |
---|---|---|
isCollect | boolean | opt-in boolean |
callback | function | success callback |
Example:
if (Platform.OS == 'android') {
appsFlyer.setCollectAndroidID(true, (res) => {
//...
});
}
Set the OneLink ID that should be used for User-Invite-API.
The link that is generated for the user invite will use this OneLink ID as the base link ID.
parameter | type | description |
---|---|---|
oneLinkID | string | oneLinkID |
callback | function | success callback |
Example:
appsFlyer.setAppInviteOneLinkID('abcd', (res) => {
//...
});
parameter | type | description |
---|---|---|
parameters | json | parameters for Invite link |
success | function | success callback (generated link) |
error | function | error callback |
Example:
appsFlyer.generateInviteLink(
{
channel: 'gmail',
campaign: 'myCampaign',
customerID: '1234',
userParams: {
myParam: 'newUser',
anotherParam: 'fromWeb',
amount: 1,
},
},
(link) => {
console.log(link);
},
(err) => {
console.log(err);
}
);
A complete list of supported parameters is available here. Custom parameters can be passed using a userParams{} nested object, as in the example above.
To attribute an impression use the following API call.
Make sure to use the promoted App ID as it appears within the AppsFlyer dashboard.
parameter | type | description |
---|---|---|
appId | string | promoted application ID |
campaign | string | Promoted Campaign |
params | json | additional parameters |
Example:
if (Platform.OS == 'ios') {
appsFlyer.logCrossPromotionImpression('456789456', 'cross_promotion_and_store', {
custom_param: 'just_an_impression',
});
}else{
appsFlyer.logCrossPromotionImpression('com.cool.RNApp', 'cross_promotion_and_store', {
custom_param: 'just_an_impression',
});
}
For more details about Cross-Promotion logging please see the relevent doc here.
Use the following API to attribute the click and launch the app store's app page.
parameter | type | description |
---|---|---|
appId | string | promoted application ID |
campaign | string | promoted campaign |
params | json | additional parameters |
Example:
let crossPromOptions = {
customerID: '1234',
myCustomParameter: 'newUser',
};
if(Platform.OS == 'ios'){
appsFlyer.logCrossPromotionAndOpenStore('456789456', 'myCampaign', crossPromOptions);
}else {
appsFlyer.logCrossPromotionAndOpenStore('com.cool.RNApp', 'myCampaign', crossPromOptions);
}
Setting user local currency code for in-app purchases.
The currency code should be a 3 character ISO 4217 code. (default is USD).
You can set the currency code for all events by calling the following method.
parameter | type | description |
---|---|---|
currencyCode | string | currencyCode |
callback | function | success callback |
Example:
appsFlyer.setCurrencyCode(currencyCode, () => {});
It is possible to anonymize specific user identifiers within AppsFlyer analytics.
This complies with both the latest privacy requirements (GDPR, COPPA) and Facebook's data and privacy policies.
To anonymize an app user:
parameter | type | description |
---|---|---|
shouldAnonymize | boolean | True if want Anonymize user Data (default value is false). |
callback | function | success callback |
Example:
appsFlyer.anonymizeUser(true, () => {});
Set Onelink custom/branded domains
Use this API during the SDK Initialization to indicate branded domains.
For more information please refer to the documentation
parameter | type | description |
---|---|---|
domains | array | Comma separated array of branded domains |
successC | function | success callback |
errorC | function | error callback |
Example:
appsFlyer.setOneLinkCustomDomains(["click.mybrand.com"],
(res) => {
console.log(res);
}, (error) => {
console.log(error);
});
Set domains used by ESP when wrapping your deeplinks.
Use this API during the SDK Initialization to indicate that links from certain domains should be resolved in order to get original deeplink
For more information please refer to the documentation
parameter | type | description |
---|---|---|
urls | array | Comma separated array of ESP domains requiring resolving |
successC | function | success callback |
errorC | function | error callback |
Example:
appsFlyer.setResolveDeepLinkURLs(["click.esp-domain.com"],
(res) => {
console.log(res);
}, (error) => {
console.log(error);
});
This function allows developers to manually re-trigger onAppOpenAttribution with a specific link (URI or URL), without recording a new re-engagement.
This method may be required if the app needs to redirect users based on the given link, or resolve the AppsFlyer short URL while staying in the foreground/opened. This might be needed because regular onAppOpenAttribution callback is only called if the app was opened with the deep link.
parameter | type | description |
---|---|---|
url | string | String representing the URL that needs to be resolved/returned in the onAppOpenAttribution callback |
success callback | function | Result callback |
failure callback | function | error callback |
Example:
appsFlyer.performOnAppAttribution(url, res => console.log(res) , err => console.error(err));
Deprecated! Start from version 6.4.0 please use setSharingFilterForPartners
Used by advertisers to exclude all networks/integrated partners from getting data. Learn more here
Example:
appsFlyer.setSharingFilterForAllPartners()
Deprecated! Start from version 6.4.0 please use setSharingFilterForPartners
Used by advertisers to exclude specified networks/integrated partners from getting data. Learn more here
parameter | type | description |
---|---|---|
partners | array | Comma separated array of partners that need to be excluded |
successC | function | success callback |
errorC | function | error callback |
Example: |
let partners = ["facebook_int","googleadwords_int","snapchat_int","doubleclick_int"]
appsFlyer.setSharingFilterForAllPartners(partners,
(res) => {
console.log(res);
}, (error) => {
console.log(error);
})
❗(iOS only)
Disables Apple Search Ads collecting
parameter | type | description |
---|---|---|
shouldDisable | boolean | Flag to disable/enable Apple Search Ads data collection |
Example:
if (Platform.OS == 'ios') {
appsFlyer.disableCollectASA(true);
}
Disables IDFA collection in iOS and Advertising ID in Android. should be called before initSdk
.
parameter | type | description |
---|---|---|
isDisable | boolean | Flag to disable/enable IDFA/Advertising ID collection |
Example:
appsFlyer.disableAdvertisingIdentifier(true);
Receipt validation is a secure mechanism whereby the payment platform (e.g. Apple or Google) validates that an in-app purchase indeed occurred as reported.
Learn more - https://support.appsflyer.com/hc/en-us/articles/207032106-Receipt-validation-for-in-app-purchases
❗Important❗ for iOS - set SandBox to true
appsFlyer.setUseReceiptValidationSandbox(true);
parameter | type | description |
---|---|---|
purchaseInfo | json | In-App Purchase parameters |
successC | function | success callback (generated link) |
errorC | function | error callback |
Example:
let info = {};
if (Platform.OS == 'android') {
info = {
publicKey: 'key',
currency: 'biz',
signature: 'sig',
purchaseData: 'data',
price: '123',
additionalParameters: {'foo': 'bar'},
};
} else if (Platform.OS == 'ios') {
info = {
productIdentifier: 'identifier',
currency: 'USD',
transactionId: '1000000614252747',
price: '0.99',
additionalParameters: {'foo': 'bar'},
};
}
appsFlyer.validateAndLogInAppPurchase(info, res => console.log(res), err => console.log(err));
Push-notification campaigns are used to create fast re-engagements with existing users.
AppsFlyer supplies an open-for-all solution, that enables measuring the success of push-notification campaigns, for both iOS and Android platforms.
Learn more - https://support.appsflyer.com/hc/en-us/articles/207364076-Measuring-Push-Notification-Re-Engagement-Campaigns
parameter | type | description |
---|---|---|
pushPayload | json | push notification payload |
Example:
const pushPayload = {
af:{
c:"test_campaign",
is_retargeting:true,
pid:"push_provider_int",
},
aps:{
alert:"Get 5000 Coins",
badge:"37",
sound:"default"
}
};
appsFlyer.sendPushNotificationData(pushPayload);
Set a custom host
parameter | type | description |
---|---|---|
hostPrefix | string | the host prefix |
hostName | string | the host name |
successC | function | success callback |
Example:
appsFlyer.setHost('foo', 'bar.appsflyer.com', res => console.log(res));
The addPushNotificationDeepLinkPath method provides app owners with a flexible interface for configuring how deep links are extracted from push notification payloads.
for more information: https://support.appsflyer.com/hc/en-us/articles/207032126-Android-SDK-integration-for-developers#core-apis-65-configure-push-notification-deep-link-resolution
❗Important❗ addPushNotificationDeepLinkPath
must be called before calling initSDK
parameter | type | description |
---|---|---|
path | strings array | the desired path separated into an array |
successC | function | success callback |
errorC | function | error callback |
Example:
appsFlyer.addPushNotificationDeepLinkPath(["deeply", "nested", "deep_link"], res => console.log(res), error => console.log(error));
❗Important❗ disableSKAD
must be called before calling initSDK
and for iOS ONLY!
parameter | type | description |
---|---|---|
disableSkad | boolean | true if you want to disable SKADNetwork |
Example:
if (Platform.OS == 'ios') {
appsFlyer.disableSKAD(true);
}
Set the language of the device. The data will be displayed in Raw Data Reports
If you want to clear this property, set an empty string. ("")
parameter | type | description |
---|---|---|
language | string | language of the device |
Example:
if (Platform.OS == 'ios') {
appsFlyer.setCurrentDeviceLanguage("EN");
}
Used by advertisers to exclude networks/integrated partners from getting data.
parameter | type | description |
---|---|---|
partners | array | Comma separated array of partners that need to be excluded |
Example:
appsFlyer.setSharingFilterForPartners([]); // Reset list (default)
appsFlyer.setSharingFilterForPartners(null); // Reset list (default)
appsFlyer.setSharingFilterForPartners(['facebook_int']); // Single partner
appsFlyer.setSharingFilterForPartners(['facebook_int', 'googleadwords_int']); // Multiple partners
appsFlyer.setSharingFilterForPartners(['all']); // All partners
appsFlyer.setSharingFilterForPartners(['googleadwords_int', 'all']); // All partners