diff --git a/Mixpanel/Controller.cs b/Mixpanel/Controller.cs index 65c3630..c3294bc 100644 --- a/Mixpanel/Controller.cs +++ b/Mixpanel/Controller.cs @@ -90,47 +90,10 @@ void OnApplicationPause(bool pauseStatus) private void Start() { MigrateFrom1To2(); - MixpanelTracking(); - CheckForMixpanelImplemented(); Mixpanel.Log($"Mixpanel Component Started"); StartCoroutine(WaitAndFlush()); } - private void MixpanelTracking() - { - if (!MixpanelStorage.HasIntegratedLibrary) { - StartCoroutine(SendHttpEvent("Integration", "85053bf24bba75239b16a601d9387e17", MixpanelSettings.Instance.Token, "", false)); - MixpanelStorage.HasIntegratedLibrary = true; - } - #if DEVELOPMENT_BUILD - StartCoroutine(SendHttpEvent("SDK Debug Launch", "metrics-1", MixpanelSettings.Instance.Token, $",\"Debug Launch Count\":{MixpanelStorage.MPDebugInitCount}", true)); - #endif - } - - private void CheckForMixpanelImplemented() - { - if (MixpanelStorage.HasImplemented) { - return; - } - - int implementedScore = 0; - implementedScore += MixpanelStorage.HasTracked ? 1 : 0; - implementedScore += MixpanelStorage.HasIdendified ? 1 : 0; - implementedScore += MixpanelStorage.HasAliased ? 1 : 0; - implementedScore += MixpanelStorage.HasUsedPeople ? 1 : 0; - - if (implementedScore >= 3) { - MixpanelStorage.HasImplemented = true; - - StartCoroutine(SendHttpEvent("SDK Implemented", "metrics-1", MixpanelSettings.Instance.Token, - $",\"Tracked\":{MixpanelStorage.HasTracked.ToString().ToLower()}" + - $",\"Identified\":{MixpanelStorage.HasIdendified.ToString().ToLower()}" + - $",\"Aliased\":{MixpanelStorage.HasAliased.ToString().ToLower()}" + - $",\"Used People\":{MixpanelStorage.HasUsedPeople.ToString().ToLower()}", - true - )); - } - } private IEnumerator WaitAndFlush() { @@ -268,12 +231,6 @@ private void MigrateFrom1To2() { bool optedOut = stateValue[optedOutKey]; MixpanelStorage.IsTracking = !optedOut; } - string trackedIntegrationKey = "tracked_integration"; - if (stateValue.ContainsKey(trackedIntegrationKey) && !stateValue[trackedIntegrationKey].IsNull) - { - bool trackedIntegration = stateValue[trackedIntegrationKey]; - MixpanelStorage.HasIntegratedLibrary = trackedIntegration; - } } } catch (Exception) diff --git a/Mixpanel/MixpanelAPI.cs b/Mixpanel/MixpanelAPI.cs index dfebf8c..79a373e 100644 --- a/Mixpanel/MixpanelAPI.cs +++ b/Mixpanel/MixpanelAPI.cs @@ -62,7 +62,6 @@ public static void Alias(string alias) Value properties = new Value(); properties["alias"] = alias; Track("$create_alias", properties); - MixpanelStorage.HasAliased = true; Flush(); } @@ -102,7 +101,6 @@ public static void Identify(string uniqueId) string oldDistinctId = MixpanelStorage.DistinctId; MixpanelStorage.DistinctId = uniqueId; Track("$identify", "$anon_distinct_id", oldDistinctId); - MixpanelStorage.HasIdendified = true; } [Obsolete("Please use 'DistinctId' instead!")] @@ -200,7 +198,7 @@ public static void Clear() if (!IsInitialized()) return; Controller.DoClear(); } - + /// /// Clears all super properties /// diff --git a/Mixpanel/Storage.cs b/Mixpanel/Storage.cs index 0796e35..2b99d65 100644 --- a/Mixpanel/Storage.cs +++ b/Mixpanel/Storage.cs @@ -38,108 +38,12 @@ internal static bool HasMigratedFrom1To2 #endregion - #region HasIntegratedLibrary - - private const string HasIntegratedLibraryName = "Mixpanel.HasIntegratedLibrary"; - - internal static bool HasIntegratedLibrary - { - get => Convert.ToBoolean(PreferencesSource.GetInt(HasIntegratedLibraryName, 0)); - set => PreferencesSource.SetInt(HasIntegratedLibraryName, Convert.ToInt32(value)); - } - - #endregion - - #region MPDebugInitCount - - private const string MPDebugInitCountName = "Mixpanel.MPDebugInitCount"; - - internal static int MPDebugInitCount - { - get => PreferencesSource.GetInt(MPDebugInitCountName, 0); - set => PreferencesSource.SetInt(MPDebugInitCountName, value); - } - - #endregion - - #region HasImplemented - - private const string HasImplementedName = "Mixpanel.HasImplemented"; - - internal static bool HasImplemented - { - get => Convert.ToBoolean(PreferencesSource.GetInt(HasImplementedName, 0)); - set => PreferencesSource.SetInt(HasImplementedName, Convert.ToInt32(value)); - } - - #endregion - - #region HasTracked - - private const string HasTrackedName = "Mixpanel.HasTracked"; - - internal static bool HasTracked - { - get => Convert.ToBoolean(PreferencesSource.GetInt(HasTrackedName, 0)); - set => PreferencesSource.SetInt(HasTrackedName, Convert.ToInt32(value)); - } - - #endregion - - #region HasIdentified - - private const string HasIdentifiedName = "Mixpanel.HasIdentified"; - - internal static bool HasIdendified - { - get => Convert.ToBoolean(PreferencesSource.GetInt(HasIdentifiedName, 0)); - set => PreferencesSource.SetInt(HasIdentifiedName, Convert.ToInt32(value)); - } - - #endregion - - #region HasAliased - - private const string HasAliasedName = "Mixpanel.HasAliased"; - - internal static bool HasAliased - { - get => Convert.ToBoolean(PreferencesSource.GetInt(HasAliasedName, 0)); - set => PreferencesSource.SetInt(HasAliasedName, Convert.ToInt32(value)); - } - - #endregion - - #region HasUsedPeople - - private const string HasUsedPeopleName = "Mixpanel.HasUsedPeople"; - - internal static bool HasUsedPeople - { - get => Convert.ToBoolean(PreferencesSource.GetInt(HasUsedPeopleName, 0)); - set => PreferencesSource.SetInt(HasUsedPeopleName, Convert.ToInt32(value)); - } - - #endregion - - #region HasTrackedFirstSDKDebugLaunch - - private const string HasTrackedFirstSDKDebugLaunchName = "Mixpanel.HasTrackedFirstSDKDebugLaunch"; - - internal static bool HasTrackedFirstSDKDebugLaunch - { - get => Convert.ToBoolean(PreferencesSource.GetInt(HasTrackedFirstSDKDebugLaunchName, 0)); - set => PreferencesSource.SetInt(HasTrackedFirstSDKDebugLaunchName, Convert.ToInt32(value)); - } - - #endregion - #region DistinctId - + private const string DistinctIdName = "Mixpanel.DistinctId"; - + private static string _distinctId; - + public static string DistinctId { get @@ -160,7 +64,7 @@ public static string DistinctId PreferencesSource.SetString(DistinctIdName, _distinctId); } } - + #endregion #region Track @@ -251,7 +155,7 @@ internal static Value DequeueBatchTrackingData(FlushType flushType, int batchSiz if (newStartIndex != oldStartIndex) { PreferencesSource.SetInt(startIndexKey, newStartIndex); } - + return batch; } @@ -264,7 +168,7 @@ internal static void DeleteBatchTrackingData(FlushType flushType, int batchSize) int dataIndex = oldStartIndex; int maxIndex = (flushType == FlushType.EVENTS) ? EventAutoIncrementingID() - 1 : PeopleAutoIncrementingID() - 1; while (deletedCount < batchSize && dataIndex <= maxIndex) { - String trackingKey = (flushType == FlushType.EVENTS) ? "Event" + dataIndex.ToString() : "People" + dataIndex.ToString(); + String trackingKey = (flushType == FlushType.EVENTS) ? "Event" + dataIndex.ToString() : "People" + dataIndex.ToString(); if (PreferencesSource.HasKey(trackingKey)) { PreferencesSource.DeleteKey(trackingKey); deletedCount++; @@ -307,7 +211,7 @@ internal static void DeleteAllTrackingData(FlushType flushType) #region IsTracking private const string IsTrackingName = "Mixpanel.IsTracking"; - + private static bool _isTracking; public static bool IsTracking @@ -326,9 +230,9 @@ public static bool IsTracking } #endregion - + #region OnceProperties - + private const string OncePropertiesName = "Mixpanel.OnceProperties"; private static Value _onceProperties; @@ -359,11 +263,11 @@ internal static void ResetOnceProperties() properties.OnRecycle(); OnceProperties = properties; } - + #endregion - + #region SuperProperties - + private const string SuperPropertiesName = "Mixpanel.SuperProperties"; private static Value _superProperties; @@ -387,18 +291,18 @@ internal static Value SuperProperties PreferencesSource.SetString(SuperPropertiesName, JsonUtility.ToJson(_superProperties)); } } - + internal static void ResetSuperProperties() { Value properties = SuperProperties; properties.OnRecycle(); SuperProperties = properties; } - + #endregion - + #region TimedEvents - + private const string TimedEventsName = "Mixpanel.TimedEvents"; private static Value _timedEvents; @@ -409,7 +313,7 @@ internal static Value TimedEvents { if (_timedEvents != null) return _timedEvents; if (!PreferencesSource.HasKey(TimedEventsName)) TimedEvents = new Value(); - else + else { _timedEvents = new Value(); JsonUtility.FromJsonOverwrite(PreferencesSource.GetString(TimedEventsName), _timedEvents); @@ -422,14 +326,14 @@ internal static Value TimedEvents PreferencesSource.SetString(TimedEventsName, JsonUtility.ToJson(_timedEvents)); } } - + internal static void ResetTimedEvents() { Value properties = TimedEvents; properties.OnRecycle(); TimedEvents = properties; } - + #endregion } } diff --git a/README.md b/README.md index dded831..e248d02 100644 --- a/README.md +++ b/README.md @@ -5,65 +5,74 @@ # Table of Contents + - [Introduction](#introduction) - [Quick Start Guide](#quick-start-guide) - - [Install Mixpanel](#1-install-mixpanel) - - [Initialize Mixpanel](#2-initialize-mixpanel) - - [Send Data](#3-send-data) - - [Check for Success](#4-check-for-success) + - [Install Mixpanel](#1-install-mixpanel) + - [Initialize Mixpanel](#2-initialize-mixpanel) + - [Send Data](#3-send-data) + - [Check for Success](#4-check-for-success) - [FAQ](#faq) - [I want to know more!](#i-want-to-know-more) # Overview + Welcome to the official Mixpanel Unity SDK. The Mixpanel Unity SDK is an open-source project, and we'd love to see your contributions! Check out our [official documentation](https://mixpanel.com/help/reference/unity) to learn how to make use of all the features we currently support! # Quick Start Guide + Supported Unity Version >= 2018.3. For older versions, you need to have `.NET 4.x Equivalent` selected as the scripting runtime version in your editor settings. + ## 1. Install Mixpanel + This library can be installed using the unity package manager system with git. We support Unity 2018.3 and above. For older versions of Unity, you need to have .NET 4.x Equivalent selected as the scripting runtime version in your editor settings. -* In your unity project root open ./Packages/manifest.json -* Add the following line to the dependencies section "com.mixpanel.unity": "https://github.com/mixpanel/mixpanel-unity.git#master", -* Open Unity and the package should download automatically -Alternatively you can go to the [releases page](https://github.com/mixpanel/mixpanel-unity/releases) and download the .unitypackage file and have unity install that. +- In your unity project root open ./Packages/manifest.json +- Add the following line to the dependencies section "com.mixpanel.unity": "https://github.com/mixpanel/mixpanel-unity.git#master", or point to a specific version. Example: ("com.mixpanel.unity": "https://github.com/mixpanel/mixpanel-unity.git#v3.5.1") +- Open Unity and the package should download automatically + Alternatively you can go to the [releases page](https://github.com/mixpanel/mixpanel-unity/releases) and download the .unitypackage file and have unity install that. + ## 2. Initialize Mixpanel + You will need your project token for initializing your library. You can get your project token from [project settings](https://mixpanel.com/settings/project). To initialize the library, first open the unity project settings menu for Mixpanel. (Edit -> Project Settings -> Mixpanel) Then, enter your project token into the Token and Debug Token input fields within the inspector. Please note if you prefer to initialize Mixpanel manually, you can select the `Manual Initialization` in the settings and call `Mixpanel.Init()` to initialize. ![unity_screenshots](https://user-images.githubusercontent.com/36679208/152408022-62440f50-04c7-4ff3-b331-02d3d3122c9e.jpg) ## 3. Send Data -Let's get started by sending event data. You can send an event from anywhere in your application. Better understand user behavior by storing details that are specific to the event (properties). + +Let's get started by sending event data. You can send an event from anywhere in your application. Better understand user behavior by storing details that are specific to the event (properties). + ```csharp using mixpanel; // Track with event-name Mixpanel.Track("Sent Message"); // Track with event-name and property -var props = new Value(); +var props = new Value(); props["Plan"] = "Premium"; Mixpanel.Track("Plan Selected", props); ``` ## 4. Check for Success -[Open up Events in Mixpanel](http://mixpanel.com/report/events) to view incoming events. -Once data hits our API, it generally takes ~60 seconds for it to be processed, stored, and queryable in your project. -👋 👋 Tell us about the Mixpanel developer experience! [https://www.mixpanel.com/devnps](https://www.mixpanel.com/devnps) 👍 👎 +[Open up Events in Mixpanel](http://mixpanel.com/report/events) to view incoming events. +Once data hits our API, it generally takes ~60 seconds for it to be processed, stored, and queryable in your project. +👋 👋 Tell us about the Mixpanel developer experience! [https://www.mixpanel.com/devnps](https://www.mixpanel.com/devnps) 👍 👎 # FAQ + **I want to stop tracking an event/event property in Mixpanel. Is that possible?** -Yes, in Lexicon, you can intercept and drop incoming events or properties. Mixpanel won’t store any new data for the event or property you select to drop. [See this article for more information](https://help.mixpanel.com/hc/en-us/articles/360001307806#dropping-events-and-properties). +Yes, in Lexicon, you can intercept and drop incoming events or properties. Mixpanel won’t store any new data for the event or property you select to drop. [See this article for more information](https://help.mixpanel.com/hc/en-us/articles/360001307806#dropping-events-and-properties). **I have a test user I would like to opt out of tracking. How do I do that?** -Mixpanel’s client-side tracking library contains the OptOutTracking() method, which will set the user’s local opt-out state to “true” and will prevent data from being sent from a user’s device. More detailed instructions can be found in the section. - +Mixpanel’s client-side tracking library contains the OptOutTracking() method, which will set the user’s local opt-out state to “true” and will prevent data from being sent from a user’s device. More detailed instructions can be found in the section. **Starting with iOS 14.5, do I need to request the user’s permission through the AppTrackingTransparency framework to use Mixpanel?** @@ -71,17 +80,19 @@ No, Mixpanel does not use IDFA so it does not require user permission through th **If I use Mixpanel, how do I answer app privacy questions for the App Store?** -Please refer to our [Apple App Developer Privacy Guidance](https://mixpanel.com/legal/app-store-privacy-details/) - +Please refer to our [Apple App Developer Privacy Guidance](https://mixpanel.com/legal/app-store-privacy-details/) # I want to know more! + No worries, here are some links that you will find useful: -* **[Full Documentation](https://developer.mixpanel.com/docs/unity)** -* **[Full API Reference](http://mixpanel.github.io/mixpanel-unity/api-reference/annotated.html)** + +- **[Full Documentation](https://developer.mixpanel.com/docs/unity)** +- **[Full API Reference](http://mixpanel.github.io/mixpanel-unity/api-reference/annotated.html)** Have any questions? Reach out to Mixpanel [Support](https://help.mixpanel.com/hc/en-us/requests/new) to speak to someone smart, quickly. ## Examples + Checkout our Examples by importing the `Examples.unitypackage` file located inside the `Mixpanel` folder after you follow the installation instructions above ## Changelog