Created
July 17, 2010 08:24
-
-
Save foca/479356 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "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 |
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
reverse_merge omglolwtf