Sha256: 4c187cb668313c7f447e911b10937eb4e8a23b48dc6c6462bd63de3f4f833cb8
Contents?: true
Size: 1.42 KB
Versions: 2
Compression:
Stored size: 1.42 KB
Contents
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 <!-- 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('#{options[: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 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(name, attributes = {}) "mpmetrics.track('#{name}', #{attributes.to_json});" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
analytical-3.0.9 | lib/analytical/modules/mixpanel.rb |
analytical-3.0.8 | lib/analytical/modules/mixpanel.rb |