At a glance: Additional SDK functionalities that are available to implement APIs such as uninstall measurement, user invite attribution, push notifications, and privacy settings.
Related reading
For a complete picture of integrating the Unity plugin with your apps, be sure to read these articles:
- Unity plugin V6 integration guide—Overview
- Unity plugin V6 integration guide—Basic SDK integration
- Unity plugin V6 integration guide—Additional SDK integration (this article)
- Unity plugin V6 integration guide—API reference
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
AppsFlyer.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)
{
AppsFlyer.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);
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.
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.
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>
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.