Class: Mixpanel::Tracker
- Inherits:
-
Object
- Object
- Mixpanel::Tracker
- Extended by:
- Async
- Defined in:
- lib/mixpanel/tracker.rb
Constant Summary
Constants included from Async
Constants included from Person
Person::PERSON_PROPERTIES, Person::PERSON_REQUEST_PROPERTIES, Person::PERSON_URL
Constants included from Event
Event::EVENT_PROPERTIES, Event::IMPORT_URL, Event::TRACK_URL
Instance Method Summary collapse
- #append(type, *args) ⇒ Object
-
#initialize(token, options = {}) ⇒ Tracker
constructor
A new instance of Tracker.
- #queue ⇒ Object
Methods included from Async
Methods included from Person
#append_identify, #append_increment, #append_register, #append_register_once, #append_set, #append_set_once, #append_track_charge, #delete, #increment, #reset_charges, #set, #set_once, #track_charge, #unset
Methods included from Event
#alias, #append_alias, #append_track, #import, #redirect_url, #track, #tracking_pixel
Constructor Details
#initialize(token, options = {}) ⇒ Tracker
Returns a new instance of Tracker.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mixpanel/tracker.rb', line 17 def initialize(token, ={}) @token = token @async = !!.fetch(:async, false) @persist = !!.fetch(:persist, false) @env = .fetch :env, {} @api_key = .fetch :api_key, nil # Make sure queue object is instantiated to an array. If not persisted, set queue object to empty array. if @persist @env['rack.session'] ||= {} @env['rack.session']['mixpanel_events'] ||= [] else @env['mixpanel_events'] = [] end end |
Instance Method Details
#append(type, *args) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/mixpanel/tracker.rb', line 37 def append(type, *args) js_args = args.collect do |arg| escape_object_for_js(arg).to_json end queue << [type, js_args] end |
#queue ⇒ Object
33 34 35 |
# File 'lib/mixpanel/tracker.rb', line 33 def queue @persist ? @env['rack.session']['mixpanel_events'] : @env['mixpanel_events'] end |