Skip to content

Instantly share code, notes, and snippets.

@interhive
Created February 8, 2013 23:59
Show Gist options
  • Save interhive/4742996 to your computer and use it in GitHub Desktop.
Save interhive/4742996 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'base64'
require 'json'
require 'httparty'
# based on https://mixpanel.com/docs/integration-libraries/ruby. Changed to use httpparty, rather than fork a process
module MixPanel
include HTTParty
TOKEN = "PUT YOUR TOKEN HERE"
base_uri "https://api.mixpanel.com/"
def self.track(event, properties={})
properties[:token] = TOKEN
params = {event: event, properties: properties}
data = Base64.strict_encode64(JSON.generate(params))
post URI.encode "/track?data=#{data}"
end
end
data = {
key: "value",
user_agent: "chrome",
content_type: "json"
}
MixPanel.track("now on the body", data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment