Class: Analytical::Modules::KissMetrics

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/analytical/modules/kiss_metrics.rb

Instance Attribute Summary

Attributes included from Base

#command_store, #initialized, #options, #tracking_command_location

Instance Method Summary collapse

Methods included from Base

#init_location, #init_location?, #process_queued_commands, #protocol, #queue

Constructor Details

#initialize(options = {}) ⇒ KissMetrics

Returns a new instance of KissMetrics.



6
7
8
9
# File 'lib/analytical/modules/kiss_metrics.rb', line 6

def initialize(options={})
  super
  @tracking_command_location = :body_prepend
end

Instance Method Details

#alias_identity(old_identity, new_identity) ⇒ Object



48
49
50
# File 'lib/analytical/modules/kiss_metrics.rb', line 48

def alias_identity(old_identity, new_identity)
  "_kmq.push([\"alias\", \"#{old_identity}\", \"#{new_identity}\"]);"
end

#event(name, *args) ⇒ Object



38
39
40
41
# File 'lib/analytical/modules/kiss_metrics.rb', line 38

def event(name, *args)
  data = args.first || {}
  "_kmq.push([\"record\", \"#{name}\", #{data.to_json}]);"
end

#identify(id, *args) ⇒ Object



33
34
35
36
# File 'lib/analytical/modules/kiss_metrics.rb', line 33

def identify(id, *args)
  data = args.first || {}
  "_kmq.push([\"identify\", \"#{data[:email]}\"]);"
end

#init_javascript(location) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/analytical/modules/kiss_metrics.rb', line 11

def init_javascript(location)
  init_location(location) do
    js = <<-HTML
    <!-- Analytical Init: KissMetrics -->
    <script type="text/javascript">
      var _kmq = _kmq || [];
      function _kms(u){
        setTimeout(function(){
          var s = document.createElement('script'); var f = document.getElementsByTagName('script')[0]; s.type = 'text/javascript'; s.async = true;
          s.src = u; f.parentNode.insertBefore(s, f);
        }, 1);
      }
      _kms('//i.kissmetrics.com/i.js');_kms('#{options[:js_url_key]}');
    </script>
    <script type="text/javascript">
      _kmq.push(['pageView']);
    </script>
    HTML
    js
  end
end

#set(data) ⇒ Object



43
44
45
46
# File 'lib/analytical/modules/kiss_metrics.rb', line 43

def set(data)
  return '' if data.blank?
  "_kmq.push([\"set\", #{data.to_json}]);"
end