Skip to content

Commit a11ffd9

Browse files
dont use milliseconds for $duration of timed events (#150)
* dont use milliseconds for $duration of timed events * update changelog * fix StartTimedEventOnce * update changelog again
1 parent 6c4b020 commit a11ffd9

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
### Fixes
6+
7+
- LICENSE has no meta file [\#147](https://github.com/mixpanel/mixpanel-unity/issues/147)
8+
59
#
610

711
## [v3.3.0](https://github.com/mixpanel/mixpanel-unity/tree/v3.3.0) (2022-08-04)

Mixpanel/Controller.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,12 @@ internal static void DoTrack(string eventName, Value properties)
351351
Value startTime;
352352
if (MixpanelStorage.TimedEvents.TryGetValue(eventName, out startTime))
353353
{
354-
properties["$duration"] = Util.CurrentTime() - (double)startTime;
354+
properties["$duration"] = Util.CurrentTimeInSeconds() - (double)startTime;
355355
MixpanelStorage.TimedEvents.Remove(eventName);
356356
}
357357
properties["token"] = MixpanelSettings.Instance.Token;
358358
properties["distinct_id"] = MixpanelStorage.DistinctId;
359-
properties["time"] = Util.CurrentTime();
359+
properties["time"] = Util.CurrentTimeInMilliseconds();
360360

361361
Value data = new Value();
362362

@@ -376,7 +376,7 @@ internal static void DoEngage(Value properties)
376376
if (!MixpanelStorage.IsTracking) return;
377377
properties["$token"] = MixpanelSettings.Instance.Token;
378378
properties["$distinct_id"] = MixpanelStorage.DistinctId;
379-
properties["$time"] = Util.CurrentTime();
379+
properties["$time"] = Util.CurrentTimeInMilliseconds();
380380
properties["$mp_metadata"] = Metadata.GetPeopleMetadata();
381381

382382
MixpanelStorage.EnqueueTrackingData(properties, MixpanelStorage.FlushType.PEOPLE);

Mixpanel/MixpanelAPI.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace mixpanel
1818
/// </code>
1919
public static partial class Mixpanel
2020
{
21-
internal const string MixpanelUnityVersion = "3.3.1";
21+
internal const string MixpanelUnityVersion = "3.3.2";
2222

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

@@ -232,7 +232,7 @@ public static void StartTimedEventOnce(string eventName)
232232
if (!MixpanelStorage.TimedEvents.ContainsKey(eventName))
233233
{
234234
Value properties = MixpanelStorage.TimedEvents;
235-
properties[eventName] = Util.CurrentTime();
235+
properties[eventName] = Util.CurrentTimeInSeconds();
236236
MixpanelStorage.TimedEvents = properties;
237237
}
238238
}

Mixpanel/Worker.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ namespace mixpanel
1414

1515
internal static class Util
1616
{
17-
internal static double CurrentTime()
17+
internal static double CurrentTimeInSeconds()
18+
{
19+
DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
20+
double currentEpochTime = (DateTime.UtcNow - epochStart).TotalSeconds;
21+
return currentEpochTime;
22+
}
23+
24+
internal static double CurrentTimeInMilliseconds()
1825
{
1926
DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
2027
long currentEpochTime = (long)(DateTime.UtcNow - epochStart).TotalMilliseconds;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.mixpanel.unity",
33
"displayName": "Mixpanel",
4-
"version": "3.3.1",
4+
"version": "3.3.2",
55
"description": "Official Mixpanel library for Unity.",
66
"repository": {
77
"type": "git",

0 commit comments

Comments
 (0)