Skip to content

Commit

Permalink
Remove internal tracking (#175)
Browse files Browse the repository at this point in the history
* remove all internal tracking

* remove logs

* remove logs

* update README
  • Loading branch information
zihejia authored May 2, 2024
1 parent d84fbf4 commit 6fec75b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 181 deletions.
43 changes: 0 additions & 43 deletions Mixpanel/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions Mixpanel/MixpanelAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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!")]
Expand Down Expand Up @@ -200,7 +198,7 @@ public static void Clear()
if (!IsInitialized()) return;
Controller.DoClear();
}

/// <summary>
/// Clears all super properties
/// </summary>
Expand Down
134 changes: 19 additions & 115 deletions Mixpanel/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -160,7 +64,7 @@ public static string DistinctId
PreferencesSource.SetString(DistinctIdName, _distinctId);
}
}

#endregion

#region Track
Expand Down Expand Up @@ -251,7 +155,7 @@ internal static Value DequeueBatchTrackingData(FlushType flushType, int batchSiz
if (newStartIndex != oldStartIndex) {
PreferencesSource.SetInt(startIndexKey, newStartIndex);
}

return batch;
}

Expand All @@ -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++;
Expand Down Expand Up @@ -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
Expand All @@ -326,9 +230,9 @@ public static bool IsTracking
}

#endregion

#region OnceProperties

private const string OncePropertiesName = "Mixpanel.OnceProperties";

private static Value _onceProperties;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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
}
}
Loading

0 comments on commit 6fec75b

Please sign in to comment.