Class: Analytical::Modules::Mixpanel
- Inherits:
-
Object
- Object
- Analytical::Modules::Mixpanel
- Includes:
- Base
- Defined in:
- lib/analytical/modules/mixpanel.rb
Instance Attribute Summary
Attributes included from Base
#command_store, #initialized, #options, #tracking_command_location
Instance Method Summary collapse
- #event(name, attributes = {}) ⇒ Object
- #identify(id, *args) ⇒ Object
- #init_javascript(location) ⇒ Object
-
#initialize(options = {}) ⇒ Mixpanel
constructor
A new instance of Mixpanel.
-
#set(properties) ⇒ Object
Used to set “Super Properties” - mixpanel.com/api/docs/guides/super-properties.
- #track(event, properties = {}) ⇒ Object
Methods included from Base
#init_location, #init_location?, #process_queued_commands, #protocol, #queue
Constructor Details
#initialize(options = {}) ⇒ Mixpanel
Returns a new instance of Mixpanel.
6 7 8 9 |
# File 'lib/analytical/modules/mixpanel.rb', line 6 def initialize(={}) super @tracking_command_location = :body_append end |
Instance Method Details
#event(name, attributes = {}) ⇒ Object
46 47 48 |
# File 'lib/analytical/modules/mixpanel.rb', line 46 def event(name, attributes = {}) %(mpmetrics.track("#{name}", #{attributes.to_json});) end |
#identify(id, *args) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/analytical/modules/mixpanel.rb', line 39 def identify(id, *args) opts = args.first || {} name = opts.is_a?(Hash) ? opts[:name] : "" name_str = name.blank? ? "" : " mpmetrics.name_tag('#{name}');" %(mpmetrics.identify('#{id}');#{name_str}) end |
#init_javascript(location) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/analytical/modules/mixpanel.rb', line 11 def init_javascript(location) init_location(location) do js = <<-HTML <!-- Analytical Init: Mixpanel --> <script type="text/javascript" src="https://api.mixpanel.com/site_media/js/api/mixpanel.js"></script> <script type="text/javascript"> try { var mpmetrics = new MixpanelLib('#{[:key]}'); } catch(err) { null_fn = function () {}; var mpmetrics = { track: null_fn, track_funnel: null_fn, register: null_fn, register_once: null_fn }; } </script> HTML js end end |
#set(properties) ⇒ Object
Used to set “Super Properties” - mixpanel.com/api/docs/guides/super-properties
35 36 37 |
# File 'lib/analytical/modules/mixpanel.rb', line 35 def set(properties) "mpmetrics.register(#{properties.to_json});" end |
#track(event, properties = {}) ⇒ Object
29 30 31 32 |
# File 'lib/analytical/modules/mixpanel.rb', line 29 def track(event, properties = {}) callback = properties.delete(:callback) || "function(){}" %(mpmetrics.track("#{event}", #{properties.to_json}, #{callback});) end |