At a glance: Integrate AppsFlyer SDK into iOS/Android games developed with Unity to measure installs, in-app events, media sources, and more.
Unity V6 support for iOS 14
The Unity plugin V6 includes support for iOS 14 and has significant API method changes from previous versions. Migrating to Unity V6 from a previous version causes breaking changes. These changes include new APIs, different classes and package names, and the removal of: com.appsflyer.GetDeepLinkingActivity
To update your plugin from an earlier (V5) version, see our guide on migrating to the V6 beta (requires updating the Unity package).
Note
Unity plugin V4 is deprecated. The V4 integration guide is available for download in PDF format (link below).
Unity plugin V6
The Unity plugin V6 enables the development of iOS and Android apps using the Unity real-time platform. Based on the AppsFlyer mobile SDKs, it implements the same methods and supports the equivalent functionality of the platform-specific (iOS and Android) SDKs. The plugin is open-source and available on GitHub. In this article, the terms plugin and SDK are used interchangeably.
1. Overview—Unity V6
Mobile apps developed on the Unity platform use a common AppsFlyer plugin for both the Android and iOS platforms.
Tab | Content | Result |
---|---|---|
[Mandatory] Integration |
Add and configure the plugin |
App dashboard shows:
|
[Recommended] |
Use the plugin core APIs to:
|
App dashboard shows:
Ready to:
|
Additional APIs |
Implement and use optional APIs for:
|
Ready to:
|
API reference |
Quick SDK API reference for developers |
After you implement and initialize the plugin, the marketer/advertiser will be able to see two installs in the app Overview dashboard—one organic, one non-organic.
2. Add the plugin to your app
Important!
AppsFlyer Unity SDK doesn't support Unity Internal Build System.
2.1 Download the AppsFlyer Unity plugin
Download the plugin from GitHub.
2.2 Install the plugin
The External Dependency Manager for Unity (EDM4U) is distributed with the AppsFlyer Unity plugin by default. This eases the integration process by resolving dependency conflicts between your plugin and other plugins in your project.
To install the plugin:
Add appsflyer-unity-plugin.v*.unitypackage to automatically import all the assets required for both the AppsFlyer plugin and the EDM4U.
To install the plugin without the EDM4U:
- Import appsflyer-unity-plugin.v*.unitypackage to your project, but make sure to clear the selection of EDM4U dependencies.
- Download and add the required Android dependencies to the Assets/Plugins/Android folder:
- Download and add the required iOS dependencies to the Assets/Plugins/iOS/AppsFlyer folder:
2.3 Set up Android
To set up the required Android permissions:
Set the following permissions in AndroidManifest.xml
:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Optional : -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
3. Initialize the plugin
This section describes how to implement and initialize the plugin.
3.1 Retrieve the dev key
- The key is unique and identifies the account. It some cases there is an app-level key.
- Dev key is mandatory.
To get the dev key:
- In AppsFlyer, go to Configuration > App Settings.
- Get the dev key.
3.2 Initialize the plugin
To initialize the plugin using the prefab:
- Go to Assets > AppsFlyer.
- Drag AppsFlyerObject.prefab to your scene.
- Set the following fields:
Setting Remarks Dev key Paste the dev key that you retrieved previously. App ID iOS: Enter the iOS app ID (no
id
prefix).Android: Leave blank.
Get conversion data If the app implements AppsFlyer deep linking, set to "True". The default is "False', meaning deep linking by default is NOT implemented. Is debug To view debug logs during development: Set to true.
Note: Ensure to disable (set to false) before releasing the app to production.
- Update the code in Assets > AppsFlyer > AppsFlyerObjectScript.cs with other available APIs.
To integrate manually:
Create a game object and add the following init code:
using AppsFlyerSDK;
public class AppsFlyerObjectScript : MonoBehaviour , IAppsFlyerConversionData
{
void Start()
{
/* AppsFlyer.setDebugLog(true); */
AppsFlyer.initSDK("devkey", "appID", this);
AppsFlyer.startSDK();
}
public void onConversionDataSuccess(string conversionData)
{
AppsFlyer.AFLog("onConversionDataSuccess", conversionData);
Dictionary<string, object> conversionDataDictionary = AppsFlyer.CallbackStringToDictionary(conversionData);
// add deferred deeplink logic here
}
public void onConversionDataFail(string error)
{
AppsFlyer.AFLog("onConversionDataFail", error);
}
public void onAppOpenAttribution(string attributionData)
{
AppsFlyer.AFLog("onAppOpenAttribution", attributionData);
Dictionary<string, object> attributionDataDictionary = AppsFlyer.CallbackStringToDictionary(attributionData);
// add direct deeplink logic here
}
public void onAppOpenAttributionFailure(string error)
{
AppsFlyer.AFLog("onAppOpenAttributionFailure", error);
}
}
Note: Make sure not to call destroy on the game object.
4. Test installs
4.1 Allowlist the test device
Allowlist the test device.
4.2 Simulate installs
Simulate organic and non-organic installs.
Simulate an organic install
Organic installs are unattributed installs; they are usually the result of installs made directly via app stores.
To simulate an organic install, see the relevant operating system instructions:
Simulate a non-organic install
Non-organic installs are attributed installs; they are usually the result of an ad engagement.
To simulate a non-organic install (using attribution links), see the relevant operating system instructions:
Note
When you're done testing and debugging the integration, disable the logs.
Recording in-app events and revenue measures the quality of your app users, while deep linking allows you to give app users a better user experience.
In this tab, app developers find relevant instructions. However, app owner/marketer input is essential. The app owner:
- Decides the in-app events required to record and measure user quality.
- Needs to access the AppsFlyer platform to set up OneLink for deep linking.
5. Record in-app events
Record in-app events to measure KPIs such as revenue, ROI, and LTV (Lifetime Value).
In-app events should be implemented to record user events. Events can be sent in several ways:
- [Best practice] Sending events via the app as described in this article.
- For additional methods see in-app events overview guide.
For apps that belong to a vertical, for example, travel, gaming, eCommerce, see the list of recommended in-app events per vertical.
5.1 In-app event names and parameters
To send events:
- Specify the event name and parameters.
- See related lists:
- List of recommended event names and structures
- List found in
AFInAppEvents
class.
[Best practice] Use event names and parameters for the following reasons:
- Standard naming: AppsFlyer can automatically map events to SRNs such as Facebook, Google, and Twitter.
- Backward compatibility: No issue arises if AppsFlyer changes an event name or parameter. The implementation is backward compatible.
5.2 Record revenue
Report revenue by adding the af_revenue
parameter to in-app events.
- Populate
af_revenue
with numeric values. Negative values are permitted. - The
af_revenue
parameter populates AppsFlyer revenue counters and raw data fields. Doing so enables marketers to view revenue in the dashboard. - Revenue can be sent using other parameters, but the AppsFlyer platform won't recognize it as revenue. Click here for more details.
- Revenue values must not contain comma separators, currency symbols, or text.
Example revenue event: 1234.56
Best practice: Learn about currency settings, display, and currency conversion.
Currency code requirements when sending revenue events
- Default currency: USD
- Use a 3-character ISO 4217 code (an example follows).
- Set the currency code by calling the API:
AppsFlyer.setCurrencyCode("ZZZ")
Example: In-app purchase event with revenue
This purchase event is for 200.12 Euros. For the revenue to reflect in the dashboard use the following.
System.Collections.Generic.Dictionary<string, string> purchaseEvent = new
System.Collections.Generic.Dictionary<string, string> ();
purchaseEvent.Add(AFInAppEvents.CURRENCY, "EUR");
purchaseEvent.Add(AFInAppEvents.REVENUE, "200.12");
purchaseEvent.Add(AFInAppEvents.QUANTITY, "1");
purchaseEvent.Add(AFInAppEvents.CONTENT_TYPE, "category_a",);
AppsFlyer.sendEvent ("af_purchase", purchaseEvent);
Record negative revenue
Record negative revenue using a minus sign.
- Revenue value is preceded by a minus sign.
- The event name has a unique value, "cancel_purchase". This lets you identify negative revenue events in raw data reports and in the Dashboard.
Example: App user receives a refund or cancels a subscription.
System.Collections.Generic.Dictionary<string, string> purchaseEvent = new
System.Collections.Generic.Dictionary<string, string> ();
purchaseEvent.Add(AFInAppEvents.CURRENCY, "USD");
purchaseEvent.Add(AFInAppEvents.REVENUE, "-200");
purchaseEvent.Add(AFInAppEvents.QUANTITY, "1");
purchaseEvent.Add(AFInAppEvents.CONTENT_TYPE, "category_a");
AppsFlyer.sendEvent ("cancel_purchase", purchaseEvent);
5.3 In-app purchase validation
The plugin provides server verification for in-app purchases.
To validate a purchase, operating system specific instructions:
#if UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.validateAndSendInAppPurchase(
"publicKey",
"signature",
"purchaseData",
"price",
"currency",
null,
this);
#endif
Ensure you test against the Apple sandbox server call:
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.validateAndSendInAppPurchase(
"productIdentifier",
"price",
"currency",
"tranactionId",
null,
this);
#endif
Method parameters
Parameter | Description |
---|---|
String publicKey | Public key from Google Developer Console |
String signature |
Transaction signature; returned by Google API when a purchase is completed |
String purchaseData |
Product purchased in JSON format; returned by Google API when a purchase is completed |
String revenue | In-app event revenue to be reported to AppsFlyer |
String currency | In-app event currency to be reported to AppsFlyer |
Dictionary<String, String> additionalParameters |
Additional in-app event parameters which appear in the event_value field in in-app event raw data |
Parameter | Description |
---|---|
String productIdentifier | Product identifier |
String price | In-app event revenue to be reported to AppsFlyer |
String currency | In-app event currency to be reported to AppsFlyer |
Dictionary<String, String> additionalParameters |
Additional in-app event parameters which appear in the event_value field in in-app event raw data |
Note
Call validateReceipt
to automatically generate an af_purchase in-app event.
Don't send a purchase event after validating the purchase. Doing so results in duplicate event reporting.
5.4 In-app event considerations
- Event name: maximum 45 characters
- Event value: must not exceed 1000 characters - if longer we can truncate it
- Supports non-English characters for in-app events (and other APIs)
- Pricing and revenue:
- Only use numbers and decimals such as 5 or 5.2
- Up to 5 numbers after the decimal are permitted. For example, 5.12345
5.5 Examples of recording in-app events
Record in-app events by calling sendEvent
and include the event name and value parameters.
See In-app events for more details.
Example: How to record an in-app purchase event
For a comprehensive list of ready-made code snippets per vertical, see our guide for rich in-app events per verticals.
System.Collections.Generic.Dictionary<string, string> purchaseEvent = new
System.Collections.Generic.Dictionary<string, string> ();
purchaseEvent.Add(AFInAppEvents.CURRENCY, "USD");
purchaseEvent.Add(AFInAppEvents.REVENUE, "200");
purchaseEvent.Add(AFInAppEvents.QUANTITY, "2");
purchaseEvent.Add(AFInAppEvents.CONTENT_TYPE, "category_a");
purchaseEvent.Add(AFInAppEvents.CONTENT_ID, "092");
AppsFlyer.sendEvent (AFInAppEvents.PURCHASE, purchaseEvent);
5.6 Record offline in-app events
Sometimes users generate in-app events, while they have no internet connection. AppsFlyer caches the event and reports when possible.
- The plugin sends events to AppsFlyer servers and waits for a response.
- If the plugin doesn’t get a 200 response, the event is stored in the cache.
- After receiving the next 200 response, the cached event is re-sent to the server.
- If the cache holds multiple events, they are sent to the server one after the other.
Note
The cache can store up to 40 events.
- Only the first 40 offline events are saved.
- All following offline events, up until the next 200 response, are discarded.
- In the raw data report,
- Event time = when an event was sent to AppsFlyer after the device is back online.
- It is not the time when the event took place.
6. Deep-link with OneLink
AppsFlyer OneLink is the solution for multi-platform attribution: redirection and deep linking.
6.1 Device detection and redirection
OneLink:
- Detects the device type (Android and iOS, desktop, etc.) when a user clicks, then
- Redirects the user to the correct destination: Google Play, iOS app store, out-of-store markets, or web pages.
To implement multi-platform attribution links and review the basics of deep linking, see the OneLink redirection guide.
6.2 Deep linking
Use deep linking to direct existing users to specific activities and customized content.
An app owner and a developer must work together to set up deep linking with OneLink:
- App owner must access the AppsFlyer dashboard
- Developer must access the app
6.3 Deferred deep linking
Deferred deep linking lets you deep link new users to direct them to specific activities and customized content with the first launch after an app install.
Standard deep linking also directs users to specific activities and customized content, but an app must already be installed on the user's device.
To set up deferred deep linking with OneLink:
- Developer needs access to the AppsFlyer platform.
- AppsFlyer platform setup for deferred and standard deep linking is the same.
- Must implement additional logic in the app to deep link users and provide them with customized content after they install and launch the app.
Check deferred deep linking for more information.
6.4 Get deep link data
The plugin provides conversion or engagement data after every install or deep-linking event. Use this data to customize content or the app's programmatic behavior.
To receive deep link data:
- Implement callback
onAppOpenAttribution
(found inIAppsFlyerConversionData
class); it is called by the AppsFlyer plugin. - Returned OneLink/attribution link parameters trigger an app to open.
- Parse the values and apply the logic to trigger the relevant app page.
public void onAppOpenAttribution(string attributionData)
{
AppsFlyer.AFLog("onAppOpenAttribution", attributionData);
Dictionary<string, object> attributionDataDictionary = AppsFlyer.CallbackStringToDictionary(attributionData);
// add direct deeplink logic here
}
Check deep linking data for more information.
7. Get conversion data
Access to real-time user attribution data is available for each install. Use this to enhances user engagement by providing:
- Personalized content
- Sending users to specific activities within an app. See deferred deep linking in this article.
To obtain AppsFlyer conversion data:
- Implement the
IAppsFlyerConversionDatabase
. - Call the
initSDK
method with this as the last parameter. - Use the
onConversionDataSuccess
method to redirect the user.
See API reference for onConversionDataSuccess.
using AppsFlyerSDK;
public class AppsFlyerObjectScript : MonoBehaviour , IAppsFlyerConversionData
{
void Start()
{
/* AppsFlyer.setDebugLog(true); */
AppsFlyer.initSDK("devkey", "appID", this);
AppsFlyer.startSDK();
}
public void onConversionDataSuccess(string conversionData)
{
AppsFlyer.AFLog("onConversionDataSuccess", conversionData);
Dictionary<string, object> conversionDataDictionary = AppsFlyer.CallbackStringToDictionary(conversionData);
// add deferred deeplink logic here
}
public void onConversionDataFail(string error)
{
AppsFlyer.AFLog("onConversionDataFail", error);
}
public void onAppOpenAttribution(string attributionData)
{
AppsFlyer.AFLog("onAppOpenAttribution", attributionData);
Dictionary<string, object> attributionDataDictionary = AppsFlyer.CallbackStringToDictionary(attributionData);
// add direct deeplink logic here
}
public void onAppOpenAttributionFailure(string error)
{
AppsFlyer.AFLog("onAppOpenAttributionFailure", error);
}
}
8. Attribution
Measure uninstalls
Measure the uninstall rate of users coming from different sources.
To set up uninstall measurement, see the relevant operating system instructions.
- Download the Unity Firebase SDK from https://firebase.google.com/docs/unity/setup.
- Import FirebaseMessaging.unitypackage into the project.
- Import google-services.json into the project (obtained from the Firebase console)
Note
Unity Firebase SDK automatically adds manifest receivers.
- Add this code to the Unity class handling the AppsFlyer code:
using Firebase.Messaging; using Firebase.Unity;
- Add to Start() method:
Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
- Add this method:
public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token)
{
#if UNITY_ANDROID
AppsFlyerAndroid.updateServerUninstallToken(token.Token);
#endif
}
Warning
Scenario: Implementing the Unity Firebase SDK.
Requirement: Do not add the following method call to enableUninstallTracking(“SenderID”) if you added the Firebase Unity SDK to your project.
Consequences if added:
- Firebase Unity SDK will get the sender ID from the google-services.json file (that was added earlier).
- As a result, this may cause a debug warning from Android.
Get your device token from UnityEngine.iOS.NotificationServices.deviceToken.
Call this method when you receive your device token (tab content issues):
AppsFlyer.registerUninstall("device_push_notification_token");
Example:
using AppsFlyerSDK;
public class AppsFlyerObjectScript : MonoBehaviour, IAppsFlyerConversionData
{
private bool tokenSent;
void Start()
{
AppsFlyer.initSDK("devKey", "appID", this);
AppsFlyer.startSDK();
#if UNITY_IOS
UnityEngine.iOS.NotificationServices.RegisterForNotifications(UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Sound);
#endif
}
void Update()
{
#if UNITY_IOS
if (!tokenSent)
{
byte[] token = UnityEngine.iOS.NotificationServices.deviceToken;
if (token != null)
{
AppsFlyeriOS.registerUninstall(token);
tokenSent = true;
}
}
#endif
}
}
For more details, see iOS Uninstall Guide
Set additional custom data
To integrate on the plugin level with several external partner platforms (including Segment, Adobe, and Urban Airship), it is necessary to use the setAdditionalData
API.
Only use this API if the partner integration article states explicitly the setAdditionalData
API is required.
Example: setAdditionalData
code
Dictionary<string, string> CustomDataMap = new Dictionary<string, string>();
CustomDataMap.Add("custom_param_1", "value_of_param_1");
AppsFlyer.setAdditionalData(CustomDataMap);
9. Sessions
Custom time between sessions
By default, at least 5 seconds must pass between two app launches for them to count as two separate sessions. To set the minimum time between sessions:
AppsFlyer.setMinTimeBetweenSessions(custom_time_ins_seconds);
Note! If you set a high value for the custom time between launches, this can negatively impact APIs that rely on session data (such as deep linking).
See more about counting app sessions.
Background sessions for utility apps
Not available in Unity.
10. Owned media
Resolve wrapped deep-link URLs
Some 3rd party services (such as email service providers):
- Wrap links in emails using their own click recording domains.
- Allow you to set your own click-recording domains.
If OneLink is wrapped in such domains, it may limit its functionality. To overcome this:
- Call the
setResolveDeepLinkURLs
API before SDK initialization. - The API gets the OneLink from click domains that launch the app.
Scenario: The click domains redirect to your OneLink at https://mysubdomain.onelink.me/abCD.
Solution:
- Use the
setResolveDeepLinkURLs
API to get the OneLink that is reached after click domains redirect an app user. - This API method receives a list of domains that are resolved by the plugin.
- The following code lets you use your click domain but, also, preserve OneLink functionality:
Example
AppsFlyer.setResolveDeepLinkURLs("example.com", "click.example.com");
Now, use the data from this OneLink to deep-link and customize user content.
Record push notifications
Record push notifications as part of retargeting campaigns.
To record push notifications:
- Call the
sendPushNotificationData
method. - This method is inside the
onCreate
method of every activity that is launched after clicking this notification:
#if UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.handlePushNotifications();
#endif
For more information, read about push notification measurement.
User invite attribution
If existing app users invite their friends and contacts to become new users, this can be a source of growth.
Attribute and record installs originating from user invites within the app. User invite attribution.
Cross-promotion attribution
Cross-promoting apps can cand drive additional app installs.
Attribute and record installs originating from a cross-promotion campaign: promote one of your apps from within another of your apps already launched by one of your users. Cross-promotion attribution.
11. User identifiers
Get AppsFlyer ID
An AppsFlyer ID is created for each new app install. Use the AppsFlyer ID to:
- Send server-to-server in-app events.
- Match it to user records in your back-end systems.
- Map entries when merging data from pull and push API.
To obtain the unique AppsFlyer ID:
string AppsFlyerUID = AppsFlyer.getAppsFlyerId();
Set customer user ID
Set your own unique customer user ID (CUID) and cross-reference it with the unique AppsFlyer ID.
Unique CUID:
- Appear in AppsFlyer raw data CSV reports.
- Can be used in postback APIs to cross-reference with internal IDs.
To set the CUID, use:
AppsFlyer.setCustomerUserId("someId");
Good practice! Set the CUID early in the app flow—it is only associated with events reported after its setup.
Call setCustomerUserId
before calling startSDK
- Recorded events will be associated with the CUID.
- Related data will appear in the raw data reports for installs and events.
AppsFlyer.setCustomerUserId("someId");
Get Customer User ID
Check CUID for more information.
Delay plugin init for customerUserID
Set the customer user ID (CUID) and only then initialize the plugin. This is useful if you want your install and event data to contain your CUID.
See the relevant operating system instructions:
Warning
Only delay setting the CUID if it suits your business logic. If you delay setting the CUID, this can increase the chance for discrepancies and may expose your app to fraud attempts.
Collect OAID
OAID is one of the unique device identifiers that enable attribution.
To collect OAID:
OAID is collected automatically by default. To opt-out, call AppsFlyerAndroid.setCollectOaid(false);
.
- Download the AAR provided by the MSA alliance.
- Add the downloaded aar to the Assets/Plugins/Android folder.
- For Huawei devices, add the
hms-ads-identifier
lib to the Assets/Plugins/Android folder. - Add appsflyer-oaid to your project. This can be done by adding the aar to the Assets/Plugins/Android folder or by adding the following to Assets/AppsFlyer/Editor/AppsFlyerDependencies.xml:
<androidPackage spec="com.appsflyer:oaid:5.2.0">
</androidPackage>
12. User privacy
Opt-out
Different scenarios, such as legal and privacy compliance issues, may lead to a decision to opt-out and stop all recording (tracking)
Best practice! Follow the exact instructions for the scenario relevant to your app.
To stop tracking:
- Call stopSDK and set to true.
AppsFlyer.stopSDK(true);
- Plugin stops functioning and no longer communicates with AppsFlyer servers.
To reactivate tracking: Call stopSDK and set to false.
Caution
Use the stopSDK API if you want to completely stop tracking a specific app user. Using the API severely impacts attribution, data collection, and the deep linking mechanism.
Anonymize user data
To anonymize an app user:
- Set the API during SDK initialization
- Call
anonymizeUser
and set to true.
AppsFlyer.anonymizeUser(true);
- App user installs, events, and sessions are anonymized.
To restart tracking: Call anonymizeUser
and set to false.
Warning
Anonymizing users severely impacts your attribution information. Only use this option for regions that legally prevent you from collecting user information.Exclude partners from getting data
In some cases, advertisers may want to stop sharing user-level data with ad networks/partners for specific users. Reasons for this include:
- Privacy policies such as CCPA or GDPR
- User opt-out mechanisms
- Competition with some partners (ad networks, 3rd parties)
AppsFlyer provides two API methods to stop sharing data with some or all partners:
- setSharingFilter: Used by advertisers to set some (one or more) networks/integrated partners to exclude from getting data.
- setSharingFilterForAllPartners: Used by advertisers to exclude all networks/integrated partners from getting data.
These filtering methods are supported as of SDK V5.4.1.
The filtering method must be called every time the SDK is initialized and affects the whole session. If it takes time to determine whether you must set the sharing filters, then delay the SDK initialization.
When the method is activated before the first startSDK call:
- Users from SRNs are attributed as Organic, and their data is not shared with integrated partners.
- Users from click ad networks (non-SRNs) are attributed correctly in AppsFlyer, but not shared with the ad networks via postbacks, APIs, raw data reports, or by any other method.
Currently, uninstall data can't be filtered using these methods. However, you can stop sending Uninstall events to partners using their setup pages in AppsFlyer.
Android and iOS APIs
initSDK
Description |
Initialize the plugin with the dev key and app ID. The dev key is required for all app. The app ID is required for iOS only. If your app is for Android only, pass null for the app ID. The game object contains the IAppsFlyerConversionData interface. |
Method signature |
|
Example |
|
startSDK
Description |
Once this API is invoked, the SDK will start, sessions will be immediately sent, and all background foreground transitions will record a session. |
Method signature |
|
Example |
|
sendEvent
Description |
Recording of in-app events is performed by calling sendEvent with the event name and value parameters. |
Method signature |
|
Example |
|
stopSDK
Description |
In some extreme cases, you might want to shut down all SDK functions for regulators and privacy compliance requirements. To do so use stopSDK API. Once invoked, the SDK no longer communicates with AppsFLyer servers and stops functioning. |
Method signature |
|
Example |
|
isSDKStopped
Description |
Was the stopSDK (boolean) API set to true. |
Method signature |
bool isSDKStopped() |
Example |
|
getSdkVersion
Description |
Get the AppsFlyer SDK version |
Method signature |
|
Example |
|
setIsDebug
Description |
Enables debug logs |
Method signature |
|
Example |
|
setCustomerUserID
Description |
Set the customer user ID (CUID). |
Method signature |
|
Example |
|
setAppInviteOneLink
Description |
Set the OneLink template ID used to create custom attribution links for user invites. |
Method signature |
|
Example |
|
setAdditionalData
Description |
Add additional data to send to external partner platforms. |
Method signature |
|
Example |
|
setResolveDeepLinkURLs
Description |
Resolve OneLink from click domains. Learn more about resolving wrapped deep link URLs. |
Method signature |
|
Example |
|
setOneLinkCustomDomain
Description |
Advertisers can use this method to set vanity OneLink domains. |
Method signature |
|
Example |
|
setcurrencyCode
Description |
Use for events with revenue. Accepts ISO currency codes. |
Method signature |
|
Example |
|
recordLocation
Description |
Manually record user location |
Method signature |
|
Example |
|
anonymizeUser
Description |
Use during initialization to explicitly anonymize the user install, events, and sessions. To stop anonymizing, call anonymizeUser again, set to false. |
Method signature |
|
Example |
|
getAppsFlyerId
Description |
To get the AppsFlyer Unique ID for a new install. |
Method signature |
|
Example |
|
setMinTimeBetweenSessions
Description |
By default, at least 5 seconds must elapse between 2 app launches to count as separate sessions. Set a custom value for the minimum required time between sessions. |
Method signature |
|
Example |
|
setUserEmails
Description |
Set user emails and encrypt them. |
Method signature |
|
Example |
|
setHost
Description |
Set a custom host |
Method signature |
|
Example |
|
getConversionData
Description |
Register a conversion data listener to allow access to user attribution data in real-time for every new install, directly from the SDK level. By doing so, serve users with personalized content or send them to specific activities within the app, which can significantly enhance their engagement with your app. |
Method signature |
|
Example |
|
attributeAndOpenStore
Description |
To attribute the click and launch the app store app page. |
Method signature |
|
Example |
|
recordCrossPromoteImpression
Description |
To attribute an impression, use the following API call. Make sure to use the promoted App ID as it appears within the AppsFlyer dashboard. |
Method signature |
|
Example |
|
generateUserInviteLink
Description |
The LinkGenerator class builds the invite URL according to various setter methods, which allow passing on additional information on the click. |
Method signature |
|
Example |
|
onAppOpenAttribution
Description |
Get deep-link data when an app opens via a deep link. |
Method signature |
|
Example |
|
onAppOpenAttributionFailure
Description |
Obtains errors while getting deep-link data. |
Method signature |
|
Example |
|
onConversionDataSuccess
Description |
Method used to get conversion data. Useful for deferred deep linking. Learn more.
|
Method signature |
|
Example |
|
onConversionDataFail
Description |
Handles errors when failing to get conversion data from installs. |
Method signature |
|
Example |
|
onInviteLinkGenerated
Description |
Success callback for generating OneLink URLs. |
Method signature |
|
Example |
|
onInviteLinkGeneratedFailure
Description |
Error callback for generating OneLink URLs. |
Method signature |
|
Example |
|
didFinishValidateReceipt
Description |
Success callback for validateAndSendInAppPurchase API. For Android: Callback returns "Validate success". |
Method signature |
|
Example |
|
didFinishValidateReceiptWithError
Description |
Error callback for validating receipts. |
Method signature |
|
Example |
|
setPhoneNumber
Description |
Used to set the user phone number. |
Method signature |
|
Example |
|
setSharingFilterForAllPartners
Description |
Used by advertisers to exclude all networks/integrated partners from getting data. Learn more |
Method signature |
|
Example |
|
setSharingFilter
Description |
Used by advertisers to set some (one or more) networks/integrated partners to exclude from getting data. Learn more |
Method signature |
|
Example |
|
Android APIs
updateServerUninstallToken
Description |
Manually pass the Firebase Device Token for uninstall measurement. |
Method signature |
|
Example |
|
setImeiData
Description |
To explicitly send the IMEI to AppsFlyer. |
Method signature |
|
Example |
|
setAndroidIdData
Description |
To explicitly send Android ID to AppsFlyer. |
Method signature |
|
Example |
|
waitForCustomerUserId
Description |
This feature makes sure that the SDK doesn't begin functioning until the customer user ID is provided. |
Method signature |
|
Example |
|
setCustomerIdAndStartSDK
Description |
To provide the SDK with the relevant customer user ID and trigger the SDK to begin its normal activity. |
Method signature |
|
Example |
|
getOutOfStore
Description |
Get the current AF_STORE value. |
Method signature |
|
Example |
|
setOutOfStore
Description |
Manually set the AF_STORE value. |
Method signature |
|
Example |
|
setCollectAndroidID
Description |
Opt-out of Android ID collection. 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 violates the Google Play policy. |
Method signature |
|
Example |
|
setCollectIMEI
Description |
Opt-out of IMEI collection. If the app does NOT contain Google Play Services, device IMEI is collected by the plugin. However, apps with Google play services should avoid IMEI collection as this violates the Google Play policy. |
Method signature |
|
Example |
|
setIsUpdate
Description |
Manually set that the application was updated. |
Method signature |
|
Example |
|
setPreinstallAttribution
Description |
Specify the manufacturer or media source name to which the pre-install is attributed. |
Method signature |
|
Example |
|
isPreInstalledApp
Description |
Boolean indicator for pre-install by the manufacturer. |
Method signature |
|
Example |
|
getAttributionId
Description |
Get the Facebook attribution ID, if one exists. |
Method signature |
|
Example |
|
handlePushNotifications
Description |
Get push notifications recorded. |
Method signature |
|
Example |
|
validateAndSendInAppPurchase
Description |
API for server verification of in-app purchases. An af_purchase event with the relevant values will be automatically sent if the validation is successful. |
Method signature |
|
Example |
|
iOS APIs
setShouldCollectDeviceName
Description |
Set this flag to true, to collect the current device name (for example, "My iPhone"). The default value is "false". |
Method signature |
|
Example |
|
setDisableCollectIAd
Description |
Opt-out for Apple Search Ads attributions. |
Method signature |
|
Example |
|
setUseReceiptValidationSandbox
Description |
In-app purchase receipt validation in Apple environment (production or sandbox). The default value is "false". |
Method signature |
|
Example |
|
setUseUninstallSandbox
Description |
Set this flag to test uninstall in Apple environment (production or sandbox). The default value is "false". |
Method signature |
|
Example |
|
validateAndSendInAppPurchase
Description |
To send and validate in-app purchases, call this method from the processPurchase method. |
Method signature |
|
Example |
|
registerUninstall
Description |
Register for remote notification and provide AppsFlyer the push device token. |
Method signature |
|
Example |
|
handleOpenUrl
Description |
Used to manually record deep linking. |
Method signature |
|
Example |
|
onOpenStoreLinkGenerated
Description |
Allows you to utilize the StoreKit component to open the App Store while remaining in the context of your app. Learn more. |
Method signature |
|
Example |
|
disableSKAdNetwork
Description |
Allows you to disable SKAdNetwork attribution. Set to "true" to disable. |
Method signature |
|
Example |
|
waitForATTUserAuthorizationWithTimeoutInterval
Description |
Used if you want to request user authorization via a popup before accessing app-related data for recording the user or the device (for example, IDFA). If the user opts-in, the IDFA will be passed to the SDK. The timeout interval gives the user a set amount of time to opt-in to IDFA collection. After the timer expires, the IDFA is not collected. |
Method signature |
|
Example |
|