Mixpanel for Windows Phone 8

A few weeks back I released a Windows Phone 8 version of Mixpanel’s API so WP8 developers could easily add analytics to their apps. The library is available as a NuGet package and can be found here: https://www.nuget.org/packages/Mixpanel/

The API relies on Mixpanel’s HTTP API which is documented here: https://mixpanel.com/help/reference/http

Here’s a set of examples illustrating how to use the library from a Windows Phone 8 app.

MixpanelClient

The main class is MixpanelClient, it’s that little fellow that allows you to track events and profile updates. Furthermore, if ever sending an element failed, the client will automatically save it locally to automatically send them as a batch later on.

Here’s how to retrieve an instance of it:

_client = await MixpanelClient.GetCurrentClient();

This method is awaitable as on the first call, the client checks if there’s any unsent element and sends them if so.

Tracking events

Once you have an instance of MixpanelClient, here’s how to track events:

Example 1

TrackingEvent evt = new TrackingEvent("Signed Up");
evt.Properties = new TrackingEventProperties(Token);
evt.Properties.DistinctId = "13793";
evt.Properties.All["Referred by"] = "Friend";
await _client.Track(evt);

Example 2

TrackingEvent levelComplete = new TrackingEvent("Level Complete");
levelComplete.Properties = new TrackingEventProperties(Token);
levelComplete.Properties.DistinctId = "13793";
levelComplete.Properties.Time = MixpanelClient.ToEpochTime(DateTime.Now);
levelComplete.Properties.IP = "203.0.113.9";
levelComplete.Properties.Tag = "Tim Trefren";
levelComplete.Properties.All["Level Number"] = 9;
await _client.Track(levelComplete);

Profile updates

ProfileUpdate pu = new ProfileUpdate(Token, "13793", ProfileUpdateOperation.Set);
pu.IP = "123.123.123.123";
pu.OperationValues["Address"] = "1313 Mockingbird Lane";
pu.OperationValues["Birthday"] = "1948-01-01";
await _client.Track(pu);

Set

ProfileUpdate pu = new ProfileUpdate(Token, "13793", ProfileUpdateOperation.Set);
pu.IP = "123.123.123.123";
pu.OperationValues["Address"] = "1313 Mockingbird Lane";
pu.OperationValues["Birthday"] = "1948-01-01";
await _client.Track(pu);

Set Once

ProfileUpdate pu = new ProfileUpdate(Token, "13793", ProfileUpdateOperation.SetOnce);
pu.OperationValues["First login date"] = MixpanelClient.ConvertToMixpanelDate(DateTime.Now);
await _client.Track(pu);

Add

ProfileUpdate pu = new ProfileUpdate(Token, "13793", ProfileUpdateOperation.Add);
pu.OperationValues["Coins gathered"] = 12;
await _client.Track(pu);

Append

ProfileUpdate pu = new ProfileUpdate(Token, "13793", ProfileUpdateOperation.Append);
pu.OperationValues["Power Ups"] = "Bubble Lead";
await _client.Track(pu);

Union

ProfileUpdate pu = new ProfileUpdate(Token, "13793", ProfileUpdateOperation.Union);
pu.OperationValues["Items purchased"] = new List() { "socks", "shirts" };
await _client.Track(pu);

Unset

ProfileUpdate pu = new ProfileUpdate(Token, "13793", ProfileUpdateOperation.Unset);
pu.UnsetValueList = new List() { "Days overdue" };
await _client.Track(pu);

Delete

ProfileUpdate pu = new ProfileUpdate(Token, "13793", ProfileUpdateOperation.Delete);
await _client.Track(pu);

 

Hope this helps,

Carl

Advertisements

Published by

canderso

Head of Engineering - Core Apps @ Deezer

3 thoughts on “Mixpanel for Windows Phone 8”

  1. Hi Carl,

    When I’m trying to use this library (latest package version as for today is 1.2.6) for Windows 10 universal app I’m getting the following run-time error:

    Could not load file or assembly ‘System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes’ or one of its dependencies. The system cannot find the file specified.

    That is after I’ve added additional Json.NET 7.0.1 package (latest as for today) which was not specified as dependency for Mixpanel package so it was not automatically resolved (only mentioned in release notes).

    I understand that as of now the Windows 10 is not officially supported by Mixpanel library, but it looks more like assembly reference/nuget package composition-related issue, not like it is totally un-doable. Could you please check it out when you have time?

    BTW, the lib looks awesome and you did a very great job and I would be really happy to give it a try.

    Hopefully Windows 10 support is just a matter of time 🙂

    Like

  2. As it’s turned out the problem was specifically with Json.NET 7.0.1. The temporary workaround is to use Json.NET 6.0.8 instead and Mixpanel 1.2.6 then working just fine. The only thing that I have to change still was reference Mixpanel.dll from “wpa” subfolder rather then from “windows8” as it was by default after nuget package installation.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s