98 lines
3.3 KiB
C#
98 lines
3.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using AppsFlyerSDK;
|
|
|
|
// This class is intended to be used the the AppsFlyerObject.prefab
|
|
|
|
public class AppsFlyerObjectScript : MonoBehaviour , IAppsFlyerConversionData
|
|
{
|
|
|
|
// These fields are set from the editor so do not modify!
|
|
//******************************//
|
|
public string devKey;
|
|
public string iosDevKey;
|
|
public string appID;
|
|
public string UWPAppID;
|
|
public string macOSAppID;
|
|
public bool isDebug;
|
|
public bool getConversionData;
|
|
//******************************//
|
|
public static string AFConversionData = "";
|
|
public static bool IsGetConversionDataOver = false;
|
|
public static string AFAttributionData = "";
|
|
public static bool IsGetAppOpenAttributionOver = false;
|
|
public static bool IsGetAFOnRequestResponse = false;
|
|
public static int AFOnRequestResponseStatusCode = 0;
|
|
public static string AFOnRequestResponseErrorDescription = string.Empty;
|
|
|
|
|
|
void Start()
|
|
{
|
|
// These fields are set from the editor so do not modify!
|
|
//******************************//
|
|
AppsFlyer.setIsDebug(isDebug);
|
|
AppsFlyer.OnRequestResponse += AppsFlyerOnRequestResponse;
|
|
#if UNITY_WSA_10_0 && !UNITY_EDITOR
|
|
AppsFlyer.initSDK(devKey, UWPAppID, getConversionData ? this : null);
|
|
#elif UNITY_STANDALONE_OSX && !UNITY_EDITOR
|
|
AppsFlyer.initSDK(devKey, macOSAppID, getConversionData ? this : null);
|
|
#elif UNITY_IOS && !UNITY_EDITOR
|
|
AppsFlyer.waitForATTUserAuthorizationWithTimeoutInterval(60);
|
|
AppsFlyer.initSDK(iosDevKey, appID, getConversionData ? this : null);
|
|
#else
|
|
AppsFlyer.initSDK(devKey, appID, getConversionData ? this : null);
|
|
#endif
|
|
//******************************/
|
|
|
|
AppsFlyer.startSDK();
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
// Mark AppsFlyer CallBacks
|
|
public void onConversionDataSuccess(string conversionData)
|
|
{
|
|
AppsFlyer.AFLog("didReceiveConversionData", conversionData);
|
|
// Dictionary<string, object> conversionDataDictionary = AppsFlyer.CallbackStringToDictionary(conversionData);
|
|
// add deferred deeplink logic here
|
|
AFConversionData = conversionData;
|
|
IsGetConversionDataOver = true;
|
|
}
|
|
|
|
public void onConversionDataFail(string error)
|
|
{
|
|
AppsFlyer.AFLog("didReceiveConversionDataWithError", error);
|
|
IsGetConversionDataOver = true;
|
|
}
|
|
|
|
public void onAppOpenAttribution(string attributionData)
|
|
{
|
|
AppsFlyer.AFLog("onAppOpenAttribution", attributionData);
|
|
// Dictionary<string, object> attributionDataDictionary = AppsFlyer.CallbackStringToDictionary(attributionData);
|
|
// add direct deeplink logic here
|
|
AFAttributionData = attributionData;
|
|
IsGetAppOpenAttributionOver = true;
|
|
}
|
|
|
|
public void onAppOpenAttributionFailure(string error)
|
|
{
|
|
AppsFlyer.AFLog("onAppOpenAttributionFailure", error);
|
|
IsGetAppOpenAttributionOver = true;
|
|
}
|
|
|
|
void AppsFlyerOnRequestResponse(object sender, EventArgs e)
|
|
{
|
|
var args = e as AppsFlyerRequestEventArgs;
|
|
AFOnRequestResponseStatusCode = args.statusCode;
|
|
AFOnRequestResponseErrorDescription = args.errorDescription;
|
|
IsGetAFOnRequestResponse = true;
|
|
}
|
|
|
|
}
|