using System.Collections.Generic;
using UnityEngine;
namespace AppsFlyerSDK
{
public class AppsFlyer : MonoBehaviour
{
public static readonly string kAppsFlyerPluginVersion = "5.4.2";
///
/// Initialize the AppsFlyer SDK with your devKey and appID.
/// The dev key is required on all platforms, and the appID is required for iOS.
/// If you app is for Android only pass null for the appID.
///
/// AppsFlyer's Dev-Key, which is accessible from your AppsFlyer account under 'App Settings' in the dashboard.
/// Your app's Apple ID.
///
///
/// AppsFlyer.initSDK("K2***********99", "41*****44"");
///
///
public static void initSDK(string devKey, string appID)
{
initSDK(devKey, appID, null);
}
///
/// Initialize the AppsFlyer SDK with your devKey and appID.
/// The dev key is required on all platforms, and the appID is required for iOS.
/// If you app is for Android only pass null for the appID.
///
/// AppsFlyer's Dev-Key, which is accessible from your AppsFlyer account under 'App Settings' in the dashboard.
/// Your app's Apple ID.
/// pass the script of the game object being used.
///
///
/// AppsFlyer.initSDK("K2***********99", 41*****44, this);
///
///
public static void initSDK(string devKey, string appID, MonoBehaviour gameObject)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setAppsFlyerDevKey(devKey);
AppsFlyeriOS.setAppleAppID(appID);
if(gameObject != null)
{
AppsFlyeriOS.getConversionData(gameObject.name);
}
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.initSDK(devKey, gameObject);
#else
#endif
}
///
/// Once this API is invoked, our SDK will start.
/// Once the API is called a sessions will be immediately sent, and all background forground transitions will send a session.
///
public static void startSDK()
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.startSDK();
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.startSDK();
#else
#endif
}
///
/// Send an In-App Event.
/// In-App Events provide insight on what is happening in your app.
///
/// Event Name as String.
/// Event Values as Dictionary.
public static void sendEvent(string eventName, Dictionary eventValues)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.sendEvent(eventName, eventValues);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.sendEvent(eventName, eventValues);
#else
#endif
}
///
/// Once this API is invoked, our SDK no longer communicates with our servers and stops functioning.
/// In some extreme cases you might want to shut down all SDK activity due to legal and privacy compliance.
/// This can be achieved with the stopSDK API.
///
/// should sdk be stopped.
public static void stopSDK(bool isSDKStopped)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.stopSDK(isSDKStopped);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.stopSDK(isSDKStopped);
#else
#endif
}
//
/// Was the stopSDK(boolean) API set to true.
///
/// boolean isSDKStopped.
public static bool isSDKStopped()
{
#if UNITY_IOS && !UNITY_EDITOR
return AppsFlyeriOS.isSDKStopped();
#elif UNITY_ANDROID && !UNITY_EDITOR
return AppsFlyerAndroid.isSDKStopped();
#else
return false;
#endif
}
///
/// Get the AppsFlyer SDK version used in app.
///
/// The current SDK version.
public static string getSdkVersion()
{
#if UNITY_IOS && !UNITY_EDITOR
return AppsFlyeriOS.getSDKVersion();
#elif UNITY_ANDROID && !UNITY_EDITOR
return AppsFlyerAndroid.getSdkVersion();
#else
return "";
#endif
}
///
/// Enables Debug logs for the AppsFlyer SDK.
/// Should only be set to true in development / debug.
///
/// shouldEnable boolean.
public static void setIsDebug(bool shouldEnable)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setIsDebug(shouldEnable);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setIsDebug(shouldEnable);
#else
#endif
}
///
/// Setting your own customer ID enables you to cross-reference your own unique ID with AppsFlyer’s unique ID and the other devices’ IDs.
/// This ID is available in AppsFlyer CSV reports along with Postback APIs for cross-referencing with your internal IDs.
///
/// Customer ID for client.
public static void setCustomerUserId(string id)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setCustomerUserID(id);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setCustomerUserId(id);
#else
#endif
}
///
/// Set the OneLink ID that should be used for User-Invite-API.
/// The link that is generated for the user invite will use this OneLink as the base link.
///
/// OneLink ID obtained from the AppsFlyer Dashboard.
public static void setAppInviteOneLinkID(string oneLinkId)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setAppInviteOneLinkID(oneLinkId);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setAppInviteOneLinkID(oneLinkId);
#else
#endif
}
///
/// Set additional data to be sent to AppsFlyer.
///
/// additional data Dictionary.
public static void setAdditionalData(Dictionary customData)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setAdditionalData(customData);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setAdditionalData(customData);
#else
#endif
}
///
/// Advertisers can wrap AppsFlyer OneLink within another Universal Link.
/// This Universal Link will invoke the app but any deep linking data will not propagate to AppsFlyer.
///
/// Array of urls.
public static void setResolveDeepLinkURLs(params string[] urls)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setResolveDeepLinkURLs(urls);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setResolveDeepLinkURLs(urls);
#else
#endif
}
///
/// Advertisers can use this method to set vanity onelink domains.
///
/// Array of domains.
public static void setOneLinkCustomDomain(params string[] domains)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setOneLinkCustomDomains(domains);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setOneLinkCustomDomain(domains);
#else
#endif
}
///
/// 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 the following method.
///
/// 3 character ISO 4217 code.
public static void setCurrencyCode(string currencyCode)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setCurrencyCode(currencyCode);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setCurrencyCode(currencyCode);
#else
#endif
}
///
/// Manually record the location of the user.
///
/// latitude as double.
/// longitude as double.
public static void recordLocation(double latitude, double longitude)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.recordLocation(latitude, longitude);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.recordLocation(latitude, longitude);
#else
#endif
}
///
/// Anonymize user Data.
/// Use this API during the SDK Initialization to explicitly anonymize a user's installs, events and sessions.
/// Default is false.
///
/// shouldAnonymizeUser boolean.
public static void anonymizeUser(bool shouldAnonymizeUser)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.anonymizeUser(shouldAnonymizeUser);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.anonymizeUser(shouldAnonymizeUser);
#else
#endif
}
///
/// Get AppsFlyer's unique device ID which is created for every new install of an app.
///
/// AppsFlyer's unique device ID.
public static string getAppsFlyerId()
{
#if UNITY_IOS && !UNITY_EDITOR
return AppsFlyeriOS.getAppsFlyerId();
#elif UNITY_ANDROID && !UNITY_EDITOR
return AppsFlyerAndroid.getAppsFlyerId();
#else
return "";
#endif
}
///
/// Set a custom value for the minimum required time between sessions.
/// By default, at least 5 seconds must lapse between 2 app launches to count as separate 2 sessions.
///
/// minimum time between 2 separate sessions in seconds.
public static void setMinTimeBetweenSessions(int seconds)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setMinTimeBetweenSessions(seconds);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setMinTimeBetweenSessions(seconds);
#else
#endif
}
///
/// Set a custom host.
///
/// Host prefix.
/// Host name.
public static void setHost(string hostPrefixName, string hostName)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setHost(hostName, hostPrefixName);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setHost(hostPrefixName, hostName);
#else
#endif
}
///
/// Set the user emails and encrypt them.
/// cryptMethod Encryption method:
/// EmailCryptType.EmailCryptTypeMD5
/// EmailCryptType.EmailCryptTypeSHA1
/// EmailCryptType.EmailCryptTypeSHA256
/// EmailCryptType.EmailCryptTypeNone
///
/// Encryption method.
/// User emails.
public static void setUserEmails(EmailCryptType cryptMethod, params string[] emails)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setUserEmails(cryptMethod, emails.Length, emails);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setUserEmails(cryptMethod, emails);
#else
#endif
}
///
/// Set the user phone number.
///
/// phoneNumber string
public static void setPhoneNumber(string phoneNumber)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setPhoneNumber(phoneNumber);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setPhoneNumber(phoneNumber);
#else
#endif
}
///
/// Used by advertisers to exclude all networks/integrated partners from getting data.
///
public static void setSharingFilterForAllPartners()
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setSharingFilterForAllPartners();
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setSharingFilterForAllPartners();
#else
#endif
}
///
/// Used by advertisers to set some (one or more) networks/integrated partners to exclude from getting data.
///
/// partners to exclude from getting data
public static void setSharingFilter(params string[] partners)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.setSharingFilter(partners);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.setSharingFilter(partners);
#else
#endif
}
///
/// Register a Conversion Data Listener.
/// Allows the developer to access the user attribution data in real-time for every new install, directly from the SDK level.
/// By doing this you can serve users with personalized content or send them to specific activities within the app,
/// which can greatly enhance their engagement with your app.
///
///
///
/// AppsFlyer.getConversionData(this.name);
///
///
public static void getConversionData(string objectName)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.getConversionData(objectName);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.getConversionData(objectName);
#else
#endif
}
///
/// Use the following API to attribute the click and launch the app store's app page.
///
/// promoted App ID
/// cross promotion campaign
/// additional user params
///
///
/// Dictionary parameters = new Dictionary();
/// parameters.Add("af_sub1", "val");
/// parameters.Add("custom_param", "val2");
/// AppsFlyer.attributeAndOpenStore("123456789", "test campaign", parameters, this);
///
///
public static void attributeAndOpenStore(string appID, string campaign, Dictionary userParams, MonoBehaviour gameObject)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.attributeAndOpenStore(appID, campaign, userParams, gameObject);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.attributeAndOpenStore(appID, campaign, userParams);
#else
#endif
}
///
/// To attribute an impression use the following API call.
/// Make sure to use the promoted App ID as it appears within the AppsFlyer dashboard.
///
/// promoted App ID.
/// cross promotion campaign.
/// parameters Dictionary.
public static void recordCrossPromoteImpression(string appID, string campaign, Dictionary parameters)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.recordCrossPromoteImpression(appID, campaign, parameters);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.recordCrossPromoteImpression(appID, campaign, parameters);
#else
#endif
}
///
/// The LinkGenerator class builds the invite URL according to various setter methods which allow passing on additional information on the click.
/// See - https://support.appsflyer.com/hc/en-us/articles/115004480866-User-invite-attribution-
///
/// parameters Dictionary.
public static void generateUserInviteLink(Dictionary parameters, MonoBehaviour gameObject)
{
#if UNITY_IOS && !UNITY_EDITOR
AppsFlyeriOS.generateUserInviteLink(parameters, gameObject);
#elif UNITY_ANDROID && !UNITY_EDITOR
AppsFlyerAndroid.generateUserInviteLink(parameters, gameObject);
#else
#endif
}
///
/// Helper method to convert json strings to dictionary.
///
/// json string
/// dictionary representing the input json string.
public static Dictionary CallbackStringToDictionary(string str)
{
return AFMiniJSON.Json.Deserialize(str) as Dictionary;
}
///
/// Helper method to log AppsFlyer events and callbacks.
///
/// method name
/// message to log
public static void AFLog(string methodName, string str)
{
Debug.Log(string.Format("AppsFlyer_Unity_v{0} {1} called with {2}", kAppsFlyerPluginVersion, methodName, str));
}
}
public enum EmailCryptType
{
// None
EmailCryptTypeNone = 0,
// SHA256
EmailCryptTypeSHA256 = 1,
}
}