API Methods - DevDmitryHub/cordova-plugin-appsflyer GitHub Wiki
initSdk(options, onSuccess, onError): void
initialize the SDK.
| parameter | type | description |
|---|---|---|
options |
Object |
SDK configuration |
onSuccess |
(message: string)=>void |
Success callback - called after successful SDK initialization. (optional) |
onError |
(message: string)=>void |
Error callback - called when error occurs during initialization. (optional) |
options
| name | type | default | description |
|---|---|---|---|
devKey |
string |
Appsflyer Dev key | |
appId |
string |
Apple Application ID (for iOS only) | |
isDebug |
boolean |
false |
debug mode (optional) |
collectIMEI |
boolean |
false |
opt-out of collection of IMEI |
collectAndroidID |
boolean |
false |
opt-out of collection of collectAndroidID |
onInstallConversionDataListener |
boolean |
false |
Accessing AppsFlyer Attribution / Conversion Data from the SDK (Deferred Deeplinking). Read more: Android, iOS. AppsFlyer plugin will return attribution data in onSuccess callback. |
Example:
var onSuccess = function(result) {
//handle result
/*
{
"status": "success",
"type": "onInstallConversionDataLoaded",
"data": {
"af_dp": "https://ionic.fess.onelink.me",
"af_click_lookback": "7d",
"install_time": "2018-07-05 08:06:50.828",
"cost_cents_USD": "0",
"iscache": "true",
"media_source": "someMedia",
"click_time": "2018-07-05 08:06:02.956",
"orig_cost": "0.0",
"campaign": "boo",
"key": "val",
"af_status": "Non-organic",
"is_first_launch": "false"
}
}
*/
};
function onError(err) {
// handle error
}
var options = {
devKey: 'd3Ac9qPardVYZxfWmCspwL',
appId: '123456789',
isDebug: false,
onInstallConversionDataListener: true
};
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
trackEventmethod 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 |
eventValue |
Object |
event 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);
deviceTrackingDisabled(bool): void
End User Opt-Out (Optional) AppsFlyer provides you a method to opt‐out specific users from AppsFlyer analytics. This method complies with the latest privacy requirements and complies with Facebook data and privacy policies. Default is FALSE, meaning tracking is enabled by default.
Examples:
window.plugins.appsFlyer.setDeviceTrackingDisabled(true);
setCurrencyCode(currencyId): void
| parameter | type | Default | description |
|---|---|---|---|
currencyId |
String |
USD |
ISO 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.
| parameter | type | description |
|---|---|---|
customerUserId |
String |
Example:
window.plugins.appsFlyer.setAppUserId(userId);
stopTracking(isStopTracking): 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.
| parameter | type | description |
|---|---|---|
isStopTracking |
boolean |
In some extreme cases you might want to shut down all SDK tracking due to legal and privacy compliance. This can be achieved with the isStopTracking API. Once this API is invoked, our SDK will no longer communicate with our servers and stop functioning. |
Example:
window.plugins.appsFlyer.stopTracking(true);
In any event, the SDK can be reactivated by calling the same API, but to pass false.
registerOnAppOpenAttribution(onSuccess, onError): void
| parameter | type | description |
|---|---|---|
onSuccess |
(message: stringifed JSON)=>void |
Success callback - called after receiving data on App Open Attribution. |
onError |
(message: stringifed JSON)=>void |
Error callback - called when error occurs. |
Example:
window.plugins.appsFlyer.registerOnAppOpenAttribution(function
onAppOpenAttributionSuccess(res){
/*
{
"data": {
"af_deeplink": "true",
"campaign": "boo",
"key": "val",
"media_source": "someMedia",
"install_time": "2018-07-12 13:20:19",
"af_status": "Non-organic",
"path": "",
"scheme": "https",
"host": "ionic.fess.onelink.me"
},
"type": "onAppOpenAttribution",
"status": "success"
}
*/
},
function onAppOpenAttributionError(err){
//...
});
enableUninstallTracking(token, onSuccess, onError): void
Enables app uninstall tracking. More Information
| parameter | type | description |
|---|---|---|
FCM/GCM ProjectNumber |
String |
GCM/FCM ProjectNumber |
onSuccess |
(message: string)=>void |
Success callback - called after successful register uninstall. (optional) |
onError |
(message: string)=>void |
Error callback - called when error occurs during register uninstall. (optional) |
updateServerUninstallToken("token"): void
Allows to pass GCM/FCM Tokens that where collected by third party plugins to the AppsFlyer server. Can be used for Uninstall Tracking.
| parameter | type | description |
|---|---|---|
token |
String |
GCM/FCM Token |
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);
| parameter | type | description |
|---|---|---|
getUserIdCallbackFn |
() => void |
Success callback |
setAppInviteOneLinkID(OneLinkID): void (User Invite / Cross Promotion)
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:
window.plugins.appsFlyer.setAppInviteOneLinkID("Ab1C");
| parameter | type | description |
|---|---|---|
OneLinkID |
String |
OneLink ID |
generateInviteLink(options, onSuccess, onError): void (User Invite)
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:
var inviteOptions {
channel: "gmail",
campaign: "myCampaign",
customerID: "1234",
userParams {
myParam : "newUser",
anotherParam : "fromWeb",
amount : 1
}
};
var onInviteLinkSuccess = function(link) {
console.log(link); // Handle Generated Link Here
}
function onInviteLinkError(err) {
console.log(err);
}
window.plugins.appsFlyer.generateInviteLink(inviteOptions, onInviteLinkSuccess, onInviteLinkError);
| 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.
trackCrossPromotionImpression("appID", "campaign"): void (Cross Promotion)
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:
window.plugins.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.
trackAndOpenStore("appID","campaign", options): void (Cross Promotion)
Use this call to track the click and launch the app store's app page (via Browser)
Example:
var crossPromOptions {
customerID: "1234",
myCustomParameter: "newUser"
};
window.plugins.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.