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(funnel, *args) ⇒ 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_prepend end |
Instance Method Details
#event(funnel, *args) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/analytical/modules/mixpanel.rb', line 43 def event(funnel, *args) data = args.last || {} step = data.delete(:step) goal = data.delete(:goal) callback = data.delete(:callback) || "function(){}" return "/* API Error: Funnel is not set for 'mpmetrics.track_funnel(funnel:string, step:int, goal:string, properties:object, callback:function); */" if funnel.blank? return "/* API Error: Step is not set for 'mpmetrics.track_funnel(#{funnel}, ...); */" unless step && step.to_i >= 0 return "/* API Error: Goal is not set for 'mpmetrics.track_funnel(#{funnel}, #{step}, ...); */" if goal.blank? "mpmetrics.track_funnel('#{funnel}', '#{step}', '#{goal}', #{data.to_json}, #{callback});" end |
#identify(id, *args) ⇒ Object
39 40 41 |
# File 'lib/analytical/modules/mixpanel.rb', line 39 def identify(id, *args) "mpmetrics.identify('#{id}');" 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 |