Skip to content

Instantly share code, notes, and snippets.

@foca
Created July 17, 2010 08:24
Show Gist options
  • Save foca/479356 to your computer and use it in GitHub Desktop.
Save foca/479356 to your computer and use it in GitHub Desktop.
require "open-uri"
require "active_support/base64"
class Mixpanel
def initialize(token, clock=Time.now)
@auth_token = token
@clock = clock
end
def event(name, properties={})
properties = { :token => @auth_token, :time => @clock.utc.to_i }.merge(properties)
request(:event => name, :properties => properties)
end
def funnel(name, step, goal, data={})
data = { :funnel => name, :step => step, :goal => goal }.merge(data)
event("mp_funnel", data)
end
private
def request(data={})
encoded = ActiveSupport::Base64.encode64s(data.to_json)
url = "http://api.mixpanel.com/track/?data=#{encoded}"
open(url).read == "1"
end
end
@sr
Copy link

sr commented Jul 17, 2010

reverse_merge omglolwtf

@foca
Copy link
Author

foca commented Jul 17, 2010

Bah, extracted from a rails app :) There, I fixed it, now shut up :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment