module Analytical module Modules class Mixpanel include Analytical::Modules::Base def initialize(options={}) super @tracking_command_location = :body_append end def init_javascript(location) init_location(location) do js = <<-HTML HTML js end end def track(event, properties = {}) callback = properties.delete(:callback) || "function(){}" "mpmetrics.track('#{event}', #{properties.to_json}, #{callback});" end # Used to set "Super Properties" - http://mixpanel.com/api/docs/guides/super-properties def set(properties) "mpmetrics.register(#{properties.to_json});" end def identify(id, *args) "mpmetrics.identify('#{id}');" end 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 end end end