Skip to content

Instantly share code, notes, and snippets.

View ttrefren's full-sized avatar

Tim Trefren ttrefren

View GitHub Profile
mpmetrics.register({"account type": "pro", "ad" : "pepsi"}, "events");
mpmetrics.register(properties, type, days);
Required:
@properties: A dictionary of properties in the usual format. {"key" : "value", "key2", "value2"}
Optional:
@type: The type of event to register these properties for
"all": All data (DEFAULT)
"events": Only events
"funnels": Only funnels
mpmetrics.track('button click', {"user type": "noob", "gender": "male", "account type": "premium"});
mpmetrics.track('button click');
<script type="text/javascript">
function create_account() {
...
mpmetrics.register({"account type": "premium"});
}
</script>
<script type="text/javascript" src="http://mixpanel.com/site_media/js/api/mpmetrics.js"></script>
<script type="text/javascript">
try {
mpmetrics.init("YOUR_TOKEN");
mpmetrics.register({"user type": "noob", "gender": "male"});
} catch(err) {}
</script>
require 'rubygems'
require 'base64'
require 'json'
require 'active_support'
# Adapted from the Python code here: http://mixpanel.com/api/docs/code/
class MixPanel
# A simple function for asynchronously logging to the mixpanel.com API.
# This function requires `curl`.
# This isn't perfect for high traffic sites, if you need something more production ready
# please tell us or stay tuned as we will open it up shortly.
import subprocess
import base64
import simplejson
def track(event, properties=None):
"""
A simple function for asynchronously logging to the mixpanel.com API.
<?php
/*
If you wish to do metric logging from your backend, the best method of doing this is to do it in
a non-blocking way. This will let your pages continue to execute at about the same speed while
logging metric data in the background. Please note: If you're on a shared host, you may be limited
in logging metric data with a background process.
Feel free to modify this code to your own environments liking
*/
class MetricsTracker {
public $token;
<!-- First include the script: -->
<script type="text/javascript">
var mp_protocol = (("https:" == document.location.protocol) ? "https://" : "http://");
document.write(unescape("%3Cscript src='" + mp_protocol + "api.mixpanel.com/site_media/js/api/mpmetrics.js'
type='text/javascript'%3E%3C/script%3E"));
</script>
<!-- Initialize it with your project token -->
<script type="text/javascript">
try { mpmetrics.init("YOUR_TOKEN");} catch(err) {}