Class: Rack::Mixpanel
- Inherits:
-
Object
- Object
- Rack::Mixpanel
- Defined in:
- lib/rack/mixpanel.rb
Defined Under Namespace
Classes: Tracker
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, token = nil) ⇒ Mixpanel
constructor
A new instance of Mixpanel.
Constructor Details
#initialize(app, token = nil) ⇒ Mixpanel
Returns a new instance of Mixpanel.
9 10 11 12 |
# File 'lib/rack/mixpanel.rb', line 9 def initialize(app, token=nil) @app = app @token = token || ENV['MIXPANEL_API_TOKEN'] end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rack/mixpanel.rb', line 14 def call(env) request = Rack::Request.new(env) = request.["mp_#{@token}_mixpanel"] if mp_env = JSON.parse() distinct_id = mp_env['distinct_id'] env['mixpanel.distinct_id'] = distinct_id end env['mixpanel.tracker'] = Tracker.new(@token, request.ip, env['mixpanel.distinct_id']) @app.call(env) end |