Created
February 23, 2010 02:24
-
-
Save bradjasper/311776 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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