Te list of available methods for this plugin is described below.
method name | params | description |
---|---|---|
initSdk |
(Object options, function success, function error) |
SDK configuration |
trackAppLaunch |
() |
Tracking session |
setCustomerUserId |
(String customerUserId, function callback) |
Cross-reference your own unique ID |
stopTracking |
(Boolean isStopTracking, function successCallback) |
Shut down all SDK tracking |
setCollectIMEI |
(Boolean isCollect, function successCallback) |
Collect IMEI for the SDK |
setCollectAndroidID |
(Boolean isCollect, function successCallback) |
Collect Android Id for the SDK |
trackEvent |
(String eventName, Object eventValues, function successC, function errorC) |
Track rich in-app events |
track-app-uninstalls |
Track app uninstalls | |
updateServerUninstallToken |
(String token, Callback callback) |
Pass Firebase device token for uninstall measurement on Android |
senddeeplinkdata-android-only |
(String url) |
Report Deep Links for Re-Targeting Attribution (Android) |
onInstallConversionData |
(function callback) |
Conversion Data from the SDK |
getAppsFlyerUID |
(String error, String appsFlyerUID) |
Get AppsFlyer’s proprietary Device ID |
tracklocation |
(float longitude, float latitute, error, function callback) |
Track location of the device |
senddeeplinkdata-android-only |
(fString url) |
Re-Targeting Attribution(Android) |
setAdditionalData |
(Object customDataMap, function callback) |
Integrate with external partner platforms |
setUserEmails |
(Object options) |
report device's associated email addresses |
setAppInviteOneLinkID |
(String OneLinkIDfunction, function callback |
Set AppsFlyer’s OneLink ID |
generateInviteLink |
(Object args, function success, function error) |
Invite new user from the app and track the new install |
trackCrossPromotionImpression |
(String appId, String campaign) |
Track cross promotion impression |
trackAndOpenStore |
(String appId, String campaign, Object options) |
Launch the app store's app page (via Browser) |
setCurrencyCode |
(String currencyCode, function callback) |
set the Currency Code for purchases |
The list of available methods for this plugin is described below.
initializes the SDK.
parameter | type | description |
---|---|---|
options |
Object |
SDK configuration |
options
name | type | default | description |
---|---|---|---|
devKey |
string |
Appsflyer Dev key | |
appId |
string |
Apple Application ID (for iOS only) | |
isDebug |
boolean |
false |
debug mode (optional) |
Example:
const options = {
devKey: '<AF_DEV_KEY>',
isDebug: true,
};
if (Platform.OS === 'ios') {
options.appId = '123456789';
}
appsFlyer.initSdk(
options,
(result) => {
console.log(result);
},
(error) => {
console.error(error);
}
);
With Promise:
try {
var result = await appsFlyer.initSdk(options);
} catch (error) {}
Necessary for tracking sessions and deep link callbacks in iOS on background-to-foreground transitions. Should be used with the relevant AppState logic.
Example:
state = {
appState: AppState.currentState,
};
componentDidMount();
{
AppState.addEventListener('change', this._handleAppStateChange);
}
componentWillUnmount();
{
AppState.removeEventListener('change', this._handleAppStateChange);
}
_handleAppStateChange = (nextAppState) => {
if (
this.state.appState.match(/inactive|background/) &&
nextAppState === 'active'
) {
if (Platform.OS === 'ios') {
appsFlyer.trackAppLaunch();
}
}
this.setState({appState: nextAppState});
};
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.
parameter | type | description |
---|---|---|
customerUserId |
String |
Example:
const userId = 'some_user_id';
appsFlyer.setCustomerUserId(userId, (response) => {
//..
});
The stopTracking
API for opting out users as part of the GDPR compliance.
parameter | type | description |
---|---|---|
isStopTracking |
boolean |
opt-out of launch and track in-app-event |
Example:
appsFlyer.stopTracking(true, (result) => {
console.log('stopTracking ...');
});
By default, IMEI and Android ID are not collected by the SDK if the OS version is higher than KitKat (4.4) and the device contains Google Play Services (on SDK versions 4.8.8 and below the specific app needed GPS).
parameter | type | description |
---|---|---|
isCollect |
boolean |
opt-out of collection of IMEI |
Example:
appsFlyer.setCollectIMEI(false, (result) => {
console.log('setCollectIMEI ...');
});
By default, IMEI and Android ID are not collected by the SDK if the OS version is higher than KitKat (4.4) and the device contains Google Play Services (on SDK versions 4.8.8 and below the specific app needed GPS).
parameter | type | description |
---|---|---|
isCollect |
boolean |
opt-out of collection of Android ID |
Example:
appsFlyer.setCollectAndroidID(false, (result) => {
console.log('setCollectAndroidID ... ');
});
- 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.
parameter | type | description |
---|---|---|
eventName |
String |
custom event name, is presented in your dashboard. See the Event list HERE |
eventValues |
Object |
event details (optional) |
Example:
const eventName = 'af_add_to_cart';
const eventValues = {
af_content_id: 'id123',
af_currency: 'USD',
af_revenue: '2',
};
appsFlyer.trackEvent(
eventName,
eventValues,
(result) => {
console.log(result);
},
(error) => {
console.error(error);
}
);
With Promise:
try {
var result = await appsFlyer.trackEvent(eventName, eventValues);
} catch (error) {}
AppsFlyer enables you to track app uninstalls. To handle notifications it requires to modify your AppDelegate.m
. Use didRegisterForRemoteNotificationsWithDeviceToken to register to the uninstall feature.
Example:
@import AppsFlyerLib;
...
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// notify AppsFlyerTracker
[[AppsFlyerTracker sharedTracker] registerUninstall:deviceToken];
}
Read more about Uninstall register: Appsflyer SDK support site
appsFlyer.updateServerUninstallToken(token, callback): void
(Android only)
Updates Firebase device token so it can be sent to AppsFlyer
parameter | type | description |
---|---|---|
token |
String |
|
callback |
(successString) => void |
Required at the moment, inject a string as parameter upon hook registration success. |
Example:
appsFlyer.updateServerUninstallToken(newFirebaseToken, (success) => {
//...
});
Read more about Android Uninstall Tracking: Appsflyer SDK support site
Accessing AppsFlyer Attribution / Conversion Data from the SDK (Deferred Deeplinking). Read more: Android, iOS
parameter | type | description |
---|---|---|
callback |
function |
returns object |
status
:"success"
or"failure"
if SDK returned error ononInstallConversionData
event handlertype
:"onAppOpenAttribution"
- returns deep linking data (non-organic)"onInstallConversionDataLoaded"
- called on each launch"onAttributionFailure"
"onInstallConversionFailure"
data
: some metadata,
Example of onInstallConversionDataLoaded
:
{
status: 'success',
type: 'onInstallConversionDataLoaded',
data: {
af_status: 'Organic',
af_message: 'organic install',
},
}
Example of onAppOpenAttribution
:
{
status: 'success',
type: 'onAppOpenAttribution',
data: {
af_sub1: 'some custom data',
link: 'https://rndemotest.onelink.me/7y5s/f78c46d5',
c: 'my campaign',
pid: 'my media source',
},
}
The code implementation for the conversion listener must be made prior to the initialization code of the SDK
Example:
this.onInstallConversionDataCanceller = appsFlyer.onInstallConversionData((data) => {
console.log(data);
});
this.onAppOpenAttributionCanceller = appsFlyer.onAppOpenAttribution((data) => {
console.log(data);
});
appsFlyer.initSdk(/*...*/);
//...
The appsFlyer.onInstallConversionData
returns function to unregister this event listener. Actually it calls NativeAppEventEmitter.remove()
Example:
state = {
appState: AppState.currentState,
};
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}
_handleAppStateChange = (nextAppState) => {
if (
this.state.appState.match(/active|foreground/) &&
nextAppState === 'background'
) {
if (this.onInstallConversionDataCanceller) {
this.onInstallConversionDataCanceller();
console.log('unregister onInstallConversionDataCanceller');
}
if (this.onAppOpenAttributionCanceller) {
this.onAppOpenAttributionCanceller();
console.log('unregister onAppOpenAttributionCanceller');
}
}
this.setState({appState: nextAppState});
};
Get AppsFlyer’s proprietary Device ID. The AppsFlyer Device ID is the main ID used by AppsFlyer in Reports and APIs.
parameter | type | description |
---|---|---|
error |
String |
Error callback - called on getAppsFlyerUID failure |
appsFlyerUID |
string |
The AppsFlyer Device ID |
Example:
appsFlyer.getAppsFlyerUID((error, appsFlyerUID) => {
if (error) {
console.error(error);
} else {
console.log('on getAppsFlyerUID: ' + appsFlyerUID);
}
});
Track the location (lat,long) of the device / user.
parameter | type | description |
---|---|---|
longitude |
float |
Longitude |
latitude |
float |
Latitude |
callback |
Object |
Success / Error Callbacks |
Example:
const latitude = -18.406655;
const longitude = 46.40625;
appsFlyer.trackLocation(longitude, latitude, (error, coords) => {
if (error) {
console.error(error);
} else {
this.setState({...this.state, trackLocation: coords});
}
});
Report Deep Links for Re-Targeting Attribution (Android). This method should be called when an app is opened using a deep link.
Example:
componentDidMount() {
Linking.getInitialURL()
.then((url) => {
if (appsFlyer) {
appsFlyer.sendDeepLinkData(url); // Report Deep Link to AppsFlyer
// Additional Deep Link Logic Here ...
}
})
.catch((err) => console.error('An error occurred', err));
}
More about Deep Links in React-Native: React-Native Linking More about Deep Links in Android: Android Deep Linking , Adding Filters
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 |
---|---|---|
customDataMap |
Object |
setUserEmails configuration |
Example:
appsFlyer.setAdditionalData(
{
val1: 'data1',
val2: false,
val3: 23,
},
(result) => {
//... SUCCESS
}
);
AppsFlyer enables you to report one or more of the device’s associated email addresses. You must collect the email addresses and report it to AppsFlyer according to your required encryption method. More info you can find on AppsFlyer-SDK-Integration-Android and AppsFlyer-SDK-Integration-iOS
parameter | type | description |
---|---|---|
options |
Object |
setUserEmails configuration |
options
name | type | default | description |
---|---|---|---|
emailsCryptType |
int |
0 | NONE - 0 (default), SHA1 - 1 , MD5 - 2 |
emails |
array |
comma separated list of emails |
Example:
const options = {
emailsCryptType: 2,
emails: ['[email protected]', '[email protected]'],
};
appsFlyer.setUserEmails(
options,
(response) => {
this.setState({...this.state, setUserEmailsResponse: response});
},
(error) => {
console.error(error);
}
);
Set AppsFlyer’s OneLink ID. Setting a valid OneLink ID will result in shortened User Invite links, when one is generated. The OneLink ID can be obtained on the AppsFlyer Dashboard.
Example:
appsFlyer.setAppInviteOneLinkID('oneLinkID', (success) => {
console.log(success);
});
parameter | type | description |
---|---|---|
OneLinkID |
String |
OneLink ID |
callback |
function |
returns object |
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. AppsFlyer allows you to track and attribute new installs originating from user invites within your app.
Example:
appsFlyer.generateInviteLink(
{
channel: 'gmail',
campaign: 'myCampaign',
customerID: '1234',
userParams: {
myParam: 'newUser',
anotherParam: 'fromWeb',
amount: 1,
},
},
(link) => {
console.log(link);
},
(err) => {
console.log(err);
}
);
parameter | type | description |
---|---|---|
inviteOptions |
Object |
Parameters for Invite link |
onInviteLinkSuccess |
() => void |
Success callback (generated link) |
onInviteLinkError |
() => void |
Error callback |
A complete list of supported parameters is available here.
Custom parameters can be passed using a userParams{}
nested object, as in the example above.
Use this call to track an impression use the following API call. Make sure to use the promoted App ID as it appears within the AppsFlyer dashboard.
Example:
appsFlyer.trackCrossPromotionImpression("com.myandroid.app", "myCampaign");
parameter | type | description |
---|---|---|
appID |
String |
Promoted Application ID |
campaign |
String |
Promoted Campaign |
For more details about Cross-Promotion tracking please see here.
Use this call to track the click and launch the app store's app page (via Browser)
Example:
var crossPromOptions = {
customerID: '1234',
myCustomParameter: 'newUser',
};
appsFlyer.trackAndOpenStore(
'com.myandroid.app',
'myCampaign',
crossPromOptions
);
parameter | type | description |
---|---|---|
appID |
String |
Promoted Application ID |
campaign |
String |
Promoted Campaign |
options |
Object |
Additional Parameters to track |
For more details about Cross-Promotion tracking please see here.
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 this method.
Example:
appsFlyer.setCurrencyCode(currencyCode, () => {});
parameter | type | description |
---|---|---|
currencyCode |
String |
currencyCode |