Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dont use milliseconds for $duration of timed events #150

Merged
merged 4 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#

## [v3.3.2](https://github.com/mixpanel/mixpanel-unity/tree/v3.3.2) (2022-09-20)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to manually update the file as long as you tag the PR.


### Fixes

- dont use milliseconds for $duration of timed events [\#150](https://github.com/mixpanel/mixpanel-unity/pull/150)

#

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will need to manually put the change log for 3.3.1


#
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