Skip to content

Instantly share code, notes, and snippets.

@bradjasper
Created February 23, 2010 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradjasper/311776 to your computer and use it in GitHub Desktop.
Save bradjasper/311776 to your computer and use it in GitHub Desktop.
# Example of adapting Mixpanel task to work with Celery
import base64
import simplejson
import urllib2
def track(event, properties=None):
"""
A simple function for asynchronously logging to the mixpanel.com API.
@param event: The overall event/category you would like to log this data under
@param properties: A dictionary of key-value pairs that describe the event
See http://mixpanel.com/api/ for further detail.
@return True on success
"""
if properties == None:
properties = {}
token = "YOUR_TOKEN_HERE"
if "token" not in properties:
properties["token"] = token
params = {"event": event, "properties": properties}
data = base64.b64encode(simplejson.dumps(params))
request = "http://api.mixpanel.com/track/?data=" + data
url = urllib2.urlopen(request)
return url.read() == "1"
def track_funnel(funnel, step, goal, properties=None):
if properties == None:
properties = {}
properties["funnel"] = funnel
properties["step"] = step
properties["goal"] = goal
track("mp_funnel", properties)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment