using AppsFlyerSDK;
public class AppsFlyerObjectScript : MonoBehaviour
{
void Start()
{
/* AppsFlyer.setDebugLog(true); */
AppsFlyer.initSDK("devkey", "appID");
AppsFlyer.startSDK();
}
}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);
}
}Since users may or may not have the mobile app installed, there are 2 types of deep linking:
- Deferred Deep Linking - Serving personalized content to new or former users, directly after the installation.
- Direct Deep Linking - Directly serving personalized content to existing users, which already have the mobile app installed.
For more info please check out the OneLink™ Deep Linking Guide.
Check out the deferred deeplinkg guide from the AppFlyer knowledge base here.
Code Sample to handle the conversion data:
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);
}When a deeplink is clicked on the device the AppsFlyer SDK will return the resolved link in the onAppOpenAttribution method.
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);
}In your app’s manifest add the following intent-filter to your relevant activity:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="your unique scheme" />
</intent-filter>For more on App Links check out the guide here.
For more on Universal Links check out the guide here.
Essentially, the Universal Links method links between an iOS mobile app and an associate website/domain, such as AppsFlyer’s OneLink domain (xxx.onelink.me). To do so, it is required to:
- Configure OneLink sub-domain and link to mobile app (by hosting the ‘apple-app-site-association’ file - AppsFlyer takes care of this part in the onelink setup on your dashboard)
- Configure the mobile app to register approved domains:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:test.onelink.me</string>
</array>
</dict>
</plist>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:
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);
Screen.orientation = ScreenOrientation.Portrait;
#endif
}
void Update()
{
#if UNITY_IOS
if (!tokenSent)
{
byte[] token = UnityEngine.iOS.NotificationServices.deviceToken;
if (token != null)
{
AppsFlyeriOS.registerUninstall(token);
tokenSent = true;
}
}
#endif
}
}Read more about Uninstall register: Appsflyer SDK support site
- 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 in the Firebase console) Note Manifest receivers should be automatically added by the Unity Firebase SDK.
- In the Unity class handling the AppsFlyer code, add the following:
using Firebase.Messaging;
using Firebase.Unity;- Add to the
Start()method:
Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;- Add the following method:
public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token)
{
#if UNITY_ANDROID
AppsFlyerAndroid.updateServerUninstallToken(token.Token);
#endif
}Read more about Android Uninstall Tracking: Appsflyer SDK support site
AppsFlyer allows you to attribute and record installs originating from user invites within your app. 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.
Example:
public class AppsFlyerObjectScript : MonoBehaviour , IAppsFlyerConversionData, IAppsFlyerUserInvite {
...
public void generateAppsFlyerLink()
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("channel", "some_channel");
parameters.Add("campaign", "some_campaign");
parameters.Add("additional_param1", "some_param1");
parameters.Add("additional_param2", "some_param2");
// other params
//parameters.Add("referrerName", "some_referrerName");
//parameters.Add("referrerImageUrl", "some_referrerImageUrl");
//parameters.Add("customerID", "some_customerID");
//parameters.Add("baseDeepLink", "some_baseDeepLink");
//parameters.Add("brandDomain", "some_brandDomain");
AppsFlyer.generateUserInviteLink(parameters, this);
}
...
public void onInviteLinkGenerated(string link)
{
AppsFlyer.AFLog("onInviteLinkGenerated", link);
}
public void onInviteLinkGeneratedFailure(string error)
{
AppsFlyer.AFLog("onInviteLinkGeneratedFailure", error);
}
public void onOpenStoreLinkGenerated(string link)
{
AppsFlyer.AFLog("onOpenStoreLinkGenerated", link);
}
}For In-App Purchase Receipt Validation, follow the instructions according to your operating system.
Notes Calling validateReceipt automatically generates an af_purchase in-app event, so you don't need to send this event yourself. The validate purchase response is triggered in the AppsFlyerTrackerCallbacks.cs class.
//To get the callbacks
//AppsFlyer.createValidateInAppListener ("AppsFlyerTrackerCallbacks", "onInAppBillingSuccess", "onInAppBillingFailure");
AppsFlyer.validateReceipt(string publicKey, string purchaseData, string signature, string price, string currency, Dictionary additionalParametes);using UnityEngine.Purchasing;
using AppsFlyerSDK;
public class AppsFlyerObject : MonoBehaviour, IStoreListener, IAppsFlyerValidateReceipt
{
public static string kProductIDConsumable = "com.test.cons";
void Start()
{
AppsFlyer.initSDK("devKey", "devKey");
AppsFlyer.startSDK();
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
string prodID = args.purchasedProduct.definition.id;
string price = args.purchasedProduct.metadata.localizedPrice.ToString();
string currency = args.purchasedProduct.metadata.isoCurrencyCode;
string receipt = args.purchasedProduct.receipt;
var recptToJSON = (Dictionary<string, object>)AFMiniJSON.Json.Deserialize(args.purchasedProduct.receipt);
var transactionID = (string)recptToJSON["TransactionID"];
if (String.Equals(args.purchasedProduct.definition.id, kProductIDConsumable, StringComparison.Ordinal))
{
#if UNITY_IOS
if(isSandbox)
{
AppsFlyeriOS.setUseReceiptValidationSandbox(true);
}
AppsFlyeriOS.validateAndSendInAppPurchase(prodID, price, currency, transactionID, null, this);
#endif
}
return PurchaseProcessingResult.Complete;
}
public void didFinishValidateReceipt(string result)
{
AppsFlyer.AFLog("didFinishValidateReceipt", result);
}
public void didFinishValidateReceiptWithError(string error)
{
AppsFlyer.AFLog("didFinishValidateReceiptWithError", error);
}
}
