Class: Rack::Mixpanel::Tracker
- Inherits:
-
Object
- Object
- Rack::Mixpanel::Tracker
- Defined in:
- lib/rack/mixpanel.rb
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#initialize(token, ip, distinct_id) ⇒ Tracker
constructor
A new instance of Tracker.
- #track(event, properties) ⇒ Object
Constructor Details
#initialize(token, ip, distinct_id) ⇒ Tracker
Returns a new instance of Tracker.
28 29 30 31 32 |
# File 'lib/rack/mixpanel.rb', line 28 def initialize(token, ip, distinct_id) @token = token @ip = ip @distinct_id = distinct_id end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
27 28 29 |
# File 'lib/rack/mixpanel.rb', line 27 def thread @thread end |
Instance Method Details
#track(event, properties) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rack/mixpanel.rb', line 34 def track(event, properties) base_props = { 'token' => @token, 'ip' => @ip, 'distinct_id' => @distinct_id } enc_props = Base64.encode64 JSON.generate({'event' => event, 'properties' => base_props.merge(properties)}) uri = URI('https://api.mixpanel.com/track') uri.query = URI.encode_www_form(:data => enc_props) @thread = Thread.new { uri.read } nil end |