lib/mixpanel/tracker.rb in mixpanel-1.1.2 vs lib/mixpanel/tracker.rb in mixpanel-1.1.3
- old
+ new
@@ -4,14 +4,15 @@
require 'thread'
require 'mixpanel/tracker/middleware'
module Mixpanel
class Tracker
- def initialize(token, env, async = false)
+ def initialize(token, env, async = false, url = 'http://api.mixpanel.com/track/?data=')
@token = token
@env = env
@async = async
+ @url = url
clear_queue
end
def append_event(event, properties = {})
append_api('track', event, properties)
@@ -20,11 +21,12 @@
def append_api(type, *args)
queue << [type, args.map {|arg| arg.to_json}]
end
def track_event(event, properties = {})
- options = { :token => @token, :time => Time.now.utc.to_i, :ip => ip }
+ options = { :time => Time.now.utc.to_i, :ip => ip }
+ options.merge!( :token => @token ) if @token
options.merge!(properties)
params = build_event(event, options)
parse_response request(params)
end
@@ -81,10 +83,10 @@
response == "1" ? true : false
end
def request(params)
data = Base64.encode64(JSON.generate(params)).gsub(/\n/,'')
- url = "http://api.mixpanel.com/track/?data=#{data}"
+ url = @url + data
if(@async)
w = Tracker.worker
begin
url << "\n"