Created
October 7, 2009 09:39
-
-
Save ttrefren/203917 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
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`. | |
# | |
# event: The overall event/category you would like to log this data under | |
# properties: A hash of key-value pairs that describe the event. Must include | |
# the Mixpanel API token as 'token' | |
# | |
# See http://mixpanel.com/api/ for further detail. | |
def self.track(event, properties={}) | |
if !properties.has_key?("token") | |
raise "Token is required" | |
end | |
params = {"event" => event, "properties" => properties} | |
data = ActiveSupport::Base64.encode64s(JSON.generate(params)) | |
request = "http://api.mixpanel.com/track/?data=#{data}" | |
`curl -s '#{request}' &` | |
end | |
def self.track_funnel(funnel, step, goal, properties={}) | |
properties["funnel"] = funnel | |
properties["step"] = step | |
properties["goal"] = goal | |
track("mp_funnel", properties) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment