eealeivan / mixpanel-csharp

Mixpanel C# integration library
MIT License
63 stars 14 forks source link

Overriding MixPanel's time stamp on a tracked event fails. #16

Closed DanielCaspers closed 5 years ago

DanielCaspers commented 5 years ago

Problem I have performed tests locally that have led me to believe one of two things is happening.

1) When using [MixpanelName(MixpanelProperty.Time)] on some member of an event being tracked using the /track endpoint, MixPanel C# is not appropriately setting the metadata to tell Mixpanel that this member corresponds to the time property as described by MixPanel's list of reserved or special properties

or

2) The documentation should be improved to better explain how the [MixpanelName(MixpanelProperty.Time)] attribute works.

Background I have a base class which all events sent to Mixpanel inherit from called BaseMixpanelEvent. I've omitted other properties for brevity.

public abstract class BaseMixpanelEvent
{
    /// <summary>
    /// Mixpanel specific event tracking type
    /// </summary>
    [IgnoreDataMember]
    public string Type { get; set; }

    /// <summary>
    /// Time when the event was originally generated
    /// </summary>
    [MixpanelName(MixpanelProperty.Time)]
    public UtcDateTime TimeStamp { get; set; }

    protected BaseMixpanelEvent(string type)
    {
        Type = type;
    } 
}

For the test, I have a timestamp I've edited to be in the past by appx. 5 hours. The screenshot below shows TimeStamp set to 3/25/2019 10:30:00 UTC as represented by UtcDateTime class during the MixpanelClient.TrackAsync() call image

In MixPanel, the timestamp for the same event is assigned on the server, hence it says it happened only seconds ago. It's making the event instead tagged as something close to 3/25/2019 15:34:00 UTC image

DanielCaspers commented 5 years ago

I have confirmed this is not an issue with Mixpanel-C#. I was in fact sending a UtcDateTime as shown in my screenshot above, which I assume at some layer was cast to string when it became JSON.

I am only left to assume that when Mixpanel sees it, it rejects it because of the incompatible data type since they expect ms from epoch.

https://developer.mixpanel.com/docs/http#section-special-properties-in-events