For more details on the mixpanel API see the mixpanel docs
The primary function is emix:track/2. This takes an event name and property list and returns true if mixpanel recorded the event, and false if it didnt.
This library requires mochiweb.
You will want to send "distinct_id", "token", and "time" properties at a minimum. Something like:
Logged = emix:track("game_completed", [
{"distinct_id", UID},
{"token", ?TOKEN},
{"time", emix:unixtime() }
]),
If you do not care whether the event is recorded or not you can use emix:track_asynch/2.
Alternatively you can spawn a process that calls emix:track/2. In this way you can record stats on successful and unsuccessful events. For example I use something like the following:
record_event(UID, EventName, Properties) ->
spawn( fun() ->
CommonProperties = [
{"distinct_id", UID},
{"token", ?TOKEN},
{"time", emix:unixtime() }
],
AllProperties = merge_properties(CommonProperties, Properties),
Logged = emix:track(EventName, AllProperties),
case Logged of
false -> estat:update(mixpanel_failed_events);
true -> estat:update(mixpanel_events)
end
end),
ok.