Class: Mixpanel::Tracker

Inherits:
Object
  • Object
show all
Extended by:
Async
Includes:
Event, Person
Defined in:
lib/mixpanel/tracker.rb

Constant Summary

Constants included from Async

Async::WORKER_MUTEX

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

Methods included from Async

dispose_worker, worker

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, options={})
  @token = token
  @async = !!options.fetch(:async, false)
  @persist = !!options.fetch(:persist, false)
  @env = options.fetch :env, {}
  @api_key = options.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

#queueObject



33
34
35
# File 'lib/mixpanel/tracker.rb', line 33

def queue
  @persist ? @env['rack.session']['mixpanel_events'] : @env['mixpanel_events']
end