Skip to content

Commit

Permalink
dont use milliseconds for $duration of timed events (#150)
Browse files Browse the repository at this point in the history
* dont use milliseconds for $duration of timed events

* update changelog

* fix StartTimedEventOnce

* update changelog again
  • Loading branch information
jaredmixpanel committed Sep 21, 2022
1 parent 6c4b020 commit a11ffd9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [v3.3.1](https://github.com/mixpanel/mixpanel-unity/tree/v3.3.1) (2022-08-18)

### Fixes

- LICENSE has no meta file [\#147](https://github.com/mixpanel/mixpanel-unity/issues/147)

#

## [v3.3.0](https://github.com/mixpanel/mixpanel-unity/tree/v3.3.0) (2022-08-04)
Expand Down
6 changes: 3 additions & 3 deletions Mixpanel/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,12 @@ internal static void DoTrack(string eventName, Value properties)
Value startTime;
if (MixpanelStorage.TimedEvents.TryGetValue(eventName, out startTime))
{
properties["$duration"] = Util.CurrentTime() - (double)startTime;
properties["$duration"] = Util.CurrentTimeInSeconds() - (double)startTime;
MixpanelStorage.TimedEvents.Remove(eventName);
}
properties["token"] = MixpanelSettings.Instance.Token;
properties["distinct_id"] = MixpanelStorage.DistinctId;
properties["time"] = Util.CurrentTime();
properties["time"] = Util.CurrentTimeInMilliseconds();

Value data = new Value();

Expand All @@ -376,7 +376,7 @@ 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["$time"] = Util.CurrentTimeInMilliseconds();
properties["$mp_metadata"] = Metadata.GetPeopleMetadata();

MixpanelStorage.EnqueueTrackingData(properties, MixpanelStorage.FlushType.PEOPLE);
Expand Down
6 changes: 3 additions & 3 deletions Mixpanel/MixpanelAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace mixpanel
/// </code>
public static partial class Mixpanel
{
internal const string MixpanelUnityVersion = "3.3.1";
internal const string MixpanelUnityVersion = "3.3.2";

/// <summary>
/// Creates an Mixpanel instance. Use only if you have enabled "Manual Initialization" from your Project Settings.
Expand Down Expand Up @@ -217,7 +217,7 @@ public static void StartTimedEvent(string eventName)
{
if (!IsInitialized()) return;
Value properties = MixpanelStorage.TimedEvents;
properties[eventName] = Util.CurrentTime();
properties[eventName] = Util.CurrentTimeInSeconds();
MixpanelStorage.TimedEvents = properties;
}

Expand All @@ -232,7 +232,7 @@ public static void StartTimedEventOnce(string eventName)
if (!MixpanelStorage.TimedEvents.ContainsKey(eventName))
{
Value properties = MixpanelStorage.TimedEvents;
properties[eventName] = Util.CurrentTime();
properties[eventName] = Util.CurrentTimeInSeconds();
MixpanelStorage.TimedEvents = properties;
}
}
Expand Down
9 changes: 8 additions & 1 deletion Mixpanel/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ namespace mixpanel

internal static class Util
{
internal static double CurrentTime()
internal static double CurrentTimeInSeconds()
{
DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
double currentEpochTime = (DateTime.UtcNow - epochStart).TotalSeconds;
return currentEpochTime;
}

internal static double CurrentTimeInMilliseconds()
{
DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
long currentEpochTime = (long)(DateTime.UtcNow - epochStart).TotalMilliseconds;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.mixpanel.unity",
"displayName": "Mixpanel",
"version": "3.3.1",
"version": "3.3.2",
"description": "Official Mixpanel library for Unity.",
"repository": {
"type": "git",
Expand Down

0 comments on commit a11ffd9

Please sign in to comment.