Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        AppsFlyer.setAppsFlyerKey("YOUR_APPSFLYER_DEV_KEY_HERE");

                #if UNITY_IOS
        AppsFlyer.setAppID("YOUR_APPLE_APP_ID_HERE");
        AppsFlyer.setIsDebug(true);
        AppsFlyer.getConversionData();
        AppsFlyer.trackAppLaunch();
                #elif UNITY_ANDROID
        // All Initialization occur in the override activity defined in the mainfest.xml, including track app launch
        // You can define AppsFlyer library here use this commented out code.

        // un-comment this in case you are not working with the android manifest file
        //AppsFlyer.setAppID ("YOUR_ANDROID_PACKAGE_NAME_HERE");

        // for getting the conversion data
        //AppsFlyer.loadConversionData("AppsFlyerTrackerCallbacks","didReceiveConversionData", "didReceiveConversionDataWithError");

        // for in app billing validation
        //AppsFlyer.createValidateInAppListener ("AppsFlyerTrackerCallbacks", "onInAppBillingSuccess", "onInAppBillingFailure");

        //AppsFlyer.trackAppLaunch ();
                #endif


        print("AppsFlyerId = " + AppsFlyer.getAppsFlyerId());
    }
Beispiel #2
0
    public string GetAppsflyerId()
    {
#if TRACKING_APPSFLYER
        return(AppsFlyer.getAppsFlyerId());
#else
        return("");
#endif
    }
Beispiel #3
0
        public static void InitializedAppsFlyerSdk()
        {
            AppsFlyer.initSDK(_devKey, null);
            AppsFlyer.startSDK();

            if (AppsFlyer.isSDKStopped())
            {
                return;
            }

            SendEvent("IAmWorking");
            PlayerPrefs.SetString(KeyDataDTO.AppsFlyerKey, AppsFlyer.getAppsFlyerId());
        }
Beispiel #4
0
    public void Update()
    {
        //AF 与AvidlyTraceSDK 互传,只设置一次,且确保拿到的不为空
        if (!HasSetAFID)
        {
            //获取 afid
            string afid = AppsFlyer.getAppsFlyerId();
            // 获取openId
            string openId = UPTraceApi.getOpenId();
            if (afid == null || afid == "" || openId == null || openId == "")
            {
                return;
            }
            Debug.Log("afid=" + afid);
            Debug.Log("openId=" + openId);

            // 将openId赋值给AppsFlyer
            AppsFlyer.setCustomerUserId(openId);
            // 将afid赋值给统计包
            UPTraceApi.setAFId(afid);

            HasSetAFID = true;
        }
    }
Beispiel #5
0
    private void GenerateLink(CloData cloData, TrackLinkData trackLinkData, Action linkGeneratedCallback)
    {
        RequestAdvertiserId(advertiserId =>
        {
            RequestAppMetricaDeviceId((metricaId) =>
            {
                var queryMap = new Dictionary <string, string>();

                queryMap["key"] = trackLinkData.key;

                if (!string.IsNullOrEmpty(trackLinkData.sub1))
                {
                    queryMap["sub1"] = trackLinkData.sub1;
                }
                if (!string.IsNullOrEmpty(trackLinkData.sub2))
                {
                    queryMap["sub2"] = trackLinkData.sub2;
                }
                if (!string.IsNullOrEmpty(trackLinkData.sub3))
                {
                    queryMap["sub3"] = trackLinkData.sub3;
                }

                var appsflyerId = AppsFlyer.getAppsFlyerId();
                if (string.IsNullOrEmpty(appsflyerId))
                {
                    appsflyerId = "none";
                }

                if (cloData.integration_version == "v1")
                {
                    var sub5 = $"{trackLinkData.source}:{advertiserId}:{appsflyerId}:{metricaId}";

                    queryMap["sub4"] = _appIdentifier;
                    queryMap["sub5"] = sub5;
                }
                else
                {
                    queryMap["bundle"]     = _appIdentifier;
                    queryMap["metrica_id"] = metricaId;
                    queryMap["apps_id"]    = appsflyerId;
                    queryMap["ifa"]        = advertiserId;

                    try
                    {
                        var subscriptionOneSignalStatus = OneSignal.GetPermissionSubscriptionState();
                        queryMap["onesignal_id"]        =
                            string.IsNullOrEmpty(subscriptionOneSignalStatus.subscriptionStatus.userId)
                                ? "none"
                                : subscriptionOneSignalStatus.subscriptionStatus.userId;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e + "EXCEPTION!!!!!!!!!!!!!!");
                    }

                    queryMap["source"] = trackLinkData.source;
                }

                var trackLink = $"https://{cloData.track_domain}/click.php";
                var index     = 0;
                foreach (var pair in queryMap)
                {
                    trackLink += index == 0 ? "?" : "&";

                    trackLink += $"{pair.Key}={queryMap[pair.Key]}";
                    index++;
                }

                UnityMainThreadDispatcher.Instance().Enqueue(SaveTrackLink(trackLink, linkGeneratedCallback));
            });
        });
    }
    IEnumerator Start()
    {
        AppsFlyer.initSDK(devkey, appID);
        AppsFlyer.startSDK();

        string tempSettingsPath = Application.persistentDataPath + "/AFUID.dat";

        if (!System.IO.File.Exists(tempSettingsPath))
        {
            appsFlyerData[0] = AppsFlyer.getAppsFlyerId();
            System.IO.File.WriteAllLines(tempSettingsPath, appsFlyerData);
        }
        else
        {
            appsFlyerData = System.IO.File.ReadAllLines(tempSettingsPath);
        }

        Url += appsFlyerData[0];

        //  webView Init
        webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();

        webViewObject.Init(
            // Callback
            cb: (msg) =>
        {
            Debug.Log(string.Format("CallFromJS[{0}]", msg));
            mUrl = msg;
        },
            // On error
            err: (msg) =>
        {
            Debug.Log(string.Format("CallOnError[{0}]", msg));
            connStatus = msg;
        },
            // When started
            started: (msg) =>
        {
            Debug.Log(string.Format("CallOnStarted[{0}]", msg));
        },
            hooked: (msg) =>
        {
            Debug.Log(string.Format("CallOnHooked[{0}]", msg));
        },
            // When loaded
            ld: (msg) =>
        {
            Debug.Log(string.Format("CallOnLoaded[{0}]", msg));

#if UNITY_EDITOR_OSX || (!UNITY_ANDROID && !UNITY_WEBPLAYER && !UNITY_WEBGL)
#if true
            webViewObject.EvaluateJS(@"
				  if (window && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.unityControl) {
					window.Unity = {
					  call: function(msg) {
						window.webkit.messageHandlers.unityControl.postMessage(msg);
					  }
					}
				  } else {
					window.Unity = {
					  call: function(msg) {
						window.location = 'unity:' + msg;
					  }
					}
				  }
				"                );
#else
            webViewObject.EvaluateJS(@"
				  if (window && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.unityControl) {
					window.Unity = {
					  call: function(msg) {
						window.webkit.messageHandlers.unityControl.postMessage(msg);
					  }
					}
				  } else {
					window.Unity = {
					  call: function(msg) {
						var iframe = document.createElement('IFRAME');
						iframe.setAttribute('src', 'unity:' + msg);
						document.documentElement.appendChild(iframe);
						iframe.parentNode.removeChild(iframe);
						iframe = null;
					  }
					}
				  }
				"                );
#endif
#elif UNITY_WEBPLAYER || UNITY_WEBGL
            webViewObject.EvaluateJS(
                "window.Unity = {" +
                "   call:function(msg) {" +
                "       parent.unityWebView.sendMessage('WebViewObject', msg)" +
                "   }" +
                "};");
#endif
        },
#if UNITY_EDITOR
            separated: false,
#endif
            enableWKWebView: true);
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
        webViewObject.bitmapRefreshCycle = 1;
#endif

        if (dev)
        {
            webViewObject.SetMargins(0, 120, 0, 0);             //WebView size
        }
        else
        {
            webViewObject.SetMargins(0, 0, 0, 0);             //WebView size
        }
        webViewObject.SetVisibility(true);

#if !UNITY_WEBPLAYER && !UNITY_WEBGL
        if (Url.StartsWith("http"))
        {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        }
        else
        {
            var exts = new string[] {
                ".jpg",
                ".js",
                ".html"
            };
            foreach (var ext in exts)
            {
                var    url    = Url.Replace(".html", ext);
                var    src    = System.IO.Path.Combine(Application.streamingAssetsPath, url);
                var    dst    = System.IO.Path.Combine(Application.persistentDataPath, url);
                byte[] result = null;
                if (src.Contains("://"))
                {
#if UNITY_2018_4_OR_NEWER
                    var unityWebRequest = UnityWebRequest.Get(src);
                    yield return(unityWebRequest.SendWebRequest());

                    result = unityWebRequest.downloadHandler.data;
#else
                    var www = new WWW(src);
                    yield return(www);

                    result = www.bytes;
#endif
                }
                else
                {
                    result = System.IO.File.ReadAllBytes(src);
                }
                System.IO.File.WriteAllBytes(dst, result);
                if (ext == ".html")
                {
                    webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
                    break;
                }
            }
        }

        webViewObject.EvaluateJS(
            "window.Unity = {" +
            "   call:function(msg) {" +
            "       parent.unityWebView.sendMessage('WebViewObject', msg)" +
            "   }" +
            "};");
#else
        if (Url.StartsWith("http"))
        {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        }
        else
        {
            webViewObject.LoadURL("StreamingAssets/" + Url.Replace(" ", "%20"));
        }
#endif
        yield break;
    }
Beispiel #7
0
 private void Start()
 {
     installs.text += "device ID " + AppsFlyer.getAppsFlyerId();
     appsflyer.OnConversionDataSuccess += ConversionDataSuccessHandler;
 }
Beispiel #8
0
 public string GetDeviceID()
 {
     return(AppsFlyer.getAppsFlyerId());
 }