lib/mixpanel/tracker.rb in mixpanel-2.0.2 vs lib/mixpanel/tracker.rb in mixpanel-2.1.0
- old
+ new
@@ -6,13 +6,15 @@
module Mixpanel
class Tracker
def initialize(token, env, options={})
@token = token
+ @api_key = options.fetch(:api_key, "")
@env = env
@async = options.fetch(:async, false)
- @url = options.fetch(:url, 'http://api.mixpanel.com/track/?data=')
+ @import = options.fetch(:import, false)
+ @url = @import ? 'http://api.mixpanel.com/import/?data' : options.fetch(:url, 'http://api.mixpanel.com/track/?data=')
@persist = options.fetch(:persist, false)
if @persist
@env["rack.session"]["mixpanel_events"] ||= []
else
@@ -114,10 +116,10 @@
response == "1" ? true : false
end
def request(params)
data = Base64.encode64(JSON.generate(params)).gsub(/\n/,'')
- url = @url + data
+ url = @import ? @url + "=" + data + '&api_key=' + @api_key : @url + data
if(@async)
w = Tracker.worker
begin
url << "\n"