コード例 #1
0
ファイル: Controller.cs プロジェクト: nonumpa/mixpanel-unity
        internal static void DoTrack(string eventName, Value properties)
        {
            if (!MixpanelStorage.IsTracking)
            {
                return;
            }
            if (properties == null)
            {
                properties = Mixpanel.ObjectPool.Get();
            }
            properties.Merge(GetEventsDefaultProperties());
            // These auto properties can change in runtime so we don't bake them into AutoProperties
            properties["$screen_width"]  = Screen.width;
            properties["$screen_height"] = Screen.height;
            properties.Merge(MixpanelStorage.OnceProperties);
            MixpanelStorage.ResetOnceProperties();
            properties.Merge(MixpanelStorage.SuperProperties);
            Value startTime;

            if (MixpanelStorage.TimedEvents.TryGetValue(eventName, out startTime))
            {
                properties["$duration"] = Util.CurrentTime() - (double)startTime;
                MixpanelStorage.TimedEvents.Remove(eventName);
            }
            properties["token"]       = MixpanelSettings.Instance.Token;
            properties["distinct_id"] = MixpanelStorage.DistinctId;
            properties["time"]        = Util.CurrentTime();
            Value data = Mixpanel.ObjectPool.Get();

            data["event"]        = eventName;
            data["properties"]   = properties;
            data["$mp_metadata"] = Metadata.GetEventMetadata();

            Worker.EnqueueEventOp(data);
        }
コード例 #2
0
 /// <summary>
 /// Clears all current event timers.
 /// </summary>
 public static void ClearTimedEvents()
 {
     if (!IsInitialized())
     {
         return;
     }
     MixpanelStorage.ResetTimedEvents();
 }
コード例 #3
0
ファイル: Controller.cs プロジェクト: mixpanel/mixpanel-unity
        internal static void DoEngage(Value properties)
        {
            if (!MixpanelStorage.IsTracking)
            {
                return;
            }
            properties["$token"]       = MixpanelSettings.Instance.Token;
            properties["$distinct_id"] = MixpanelStorage.DistinctId;
            properties["$time"]        = Util.CurrentTime();
            properties["$mp_metadata"] = Metadata.GetPeopleMetadata();

            MixpanelStorage.EnqueueTrackingData(properties, MixpanelStorage.FlushType.PEOPLE);
            if (Debug.isDebugBuild)
            {
                MixpanelStorage.HasUsedPeople = true;
            }
        }
コード例 #4
0
ファイル: Controller.cs プロジェクト: mixpanel/mixpanel-unity
        private IEnumerator SendData(MixpanelStorage.FlushType flushType)
        {
            if (_retryTime > DateTime.Now && _retryCount > 0)
            {
                yield break;
            }

            string url   = (flushType == MixpanelStorage.FlushType.EVENTS) ? Config.TrackUrl : Config.EngageUrl;
            Value  batch = MixpanelStorage.DequeueBatchTrackingData(flushType, Config.BatchSize);

            while (batch.Count > 0)
            {
                WWWForm form    = new WWWForm();
                String  payload = batch.ToString();
                form.AddField("data", payload);
                Mixpanel.Log("Sending batch of data: " + payload);
                using (UnityWebRequest request = UnityWebRequest.Post(url, form))
                {
                    yield return(request.SendWebRequest());

                    #if UNITY_2020_1_OR_NEWER
                    if (request.result != UnityWebRequest.Result.Success)
                    #else
                    if (request.isHttpError || request.isNetworkError)
                    #endif
                    {
                        Mixpanel.Log("API request to " + url + "has failed with reason " + request.error);
                        _retryCount += 1;
                        double retryIn = Math.Pow(2, _retryCount - 1) * 60;
                        retryIn    = Math.Min(retryIn, 10 * 60); // limit 10 min
                        _retryTime = DateTime.Now;
                        _retryTime = _retryTime.AddSeconds(retryIn);
                        Mixpanel.Log("Retrying request in " + retryIn + " seconds (retryCount=" + _retryCount + ")");
                        yield break;
                    }
                    else
                    {
                        _retryCount = 0;
                        MixpanelStorage.DeleteBatchTrackingData(batch);
                        batch = MixpanelStorage.DequeueBatchTrackingData(flushType, Config.BatchSize);
                        Mixpanel.Log("Successfully posted to " + url);
                    }
                }
            }
        }
コード例 #5
0
ファイル: Controller.cs プロジェクト: mixpanel/mixpanel-unity
        internal static void DoTrack(string eventName, Value properties)
        {
            if (!MixpanelStorage.IsTracking)
            {
                return;
            }
            if (properties == null)
            {
                properties = new Value();
            }
            properties.Merge(GetEventsDefaultProperties());
            // These auto properties can change in runtime so we don't bake them into AutoProperties
            properties["$screen_width"]  = Screen.width;
            properties["$screen_height"] = Screen.height;
            properties.Merge(MixpanelStorage.OnceProperties);
            MixpanelStorage.ResetOnceProperties();
            properties.Merge(MixpanelStorage.SuperProperties);
            Value startTime;

            if (MixpanelStorage.TimedEvents.TryGetValue(eventName, out startTime))
            {
                properties["$duration"] = Util.CurrentTime() - (double)startTime;
                MixpanelStorage.TimedEvents.Remove(eventName);
            }
            properties["token"]       = MixpanelSettings.Instance.Token;
            properties["distinct_id"] = MixpanelStorage.DistinctId;
            properties["time"]        = Util.CurrentTime();

            Value data = new Value();

            data["event"]        = eventName;
            data["properties"]   = properties;
            data["$mp_metadata"] = Metadata.GetEventMetadata();

            if (Debug.isDebugBuild && !eventName.StartsWith("$"))
            {
                MixpanelStorage.HasTracked = true;
            }

            MixpanelStorage.EnqueueTrackingData(data, MixpanelStorage.FlushType.EVENTS);
        }
コード例 #6
0
ファイル: Controller.cs プロジェクト: mixpanel/mixpanel-unity
 internal static void DoClear()
 {
     MixpanelStorage.DeleteAllTrackingData(MixpanelStorage.FlushType.EVENTS);
     MixpanelStorage.DeleteAllTrackingData(MixpanelStorage.FlushType.PEOPLE);
 }
コード例 #7
0
ファイル: MixpanelAPI.cs プロジェクト: nonumpa/mixpanel-unity
 /// <summary>
 /// Clears all current event timers.
 /// </summary>
 public static void ClearTimedEvents()
 {
     MixpanelStorage.ResetTimedEvents();
 }
コード例 #8
0
 /// <summary>
 /// By default, Mixpanel uses PlayerPreferences for data persistence. However you can call this method to
 /// set the data persistence of your choice as long as it follows IPeferences
 /// </summary>
 /// <param name="preferences">the new distinct_id that should represent original</param>
 public static void SetPreferencesSource(IPreferences preferences)
 {
     MixpanelStorage.SetPreferencesSource(preferences);
 }