-
Notifications
You must be signed in to change notification settings - Fork 0
/
mixpanel.cs
30 lines (24 loc) · 1.08 KB
/
mixpanel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class Mixpanel
{
private const string Host = "http://api.mixpanel.com/";
private string _token;
private string _mpEvent;
private Dictionary<string, string> _eventParams;
// This method that will be called when the thread is started
public Mixpanel(string token, string mpEvent, Dictionary<string, string> eventParams)
{
this._token = token;
this._mpEvent = mpEvent;
this._eventParams = eventParams;
}
public void Track()
{
this._eventParams.Add("token", this._token);
var mpString = new {@event = this._mpEvent, properties = this._eventParams};
var mpJSON = new JavaScriptSerializer().Serialize(mpString);
var encbuff = System.Text.Encoding.UTF8.GetBytes(mpJSON);
var encString = Convert.ToBase64String(encbuff);
var myReq = (HttpWebRequest)WebRequest.Create(Host + "track/?data=" + encString);
var myRes = myReq.GetResponse();
}
}