Class: Analytical::Modules::Totango

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/analytical/modules/totango.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 = {}) ⇒ Totango

Returns a new instance of Totango.



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

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

Instance Method Details

#event(name, *args) ⇒ Object



42
43
44
45
# File 'lib/analytical/modules/totango.rb', line 42

def event(name, *args)
  data = args.first || {}
  "tracker.track(\"#{name}\", \"#{data[:module]}\");"
end

#identify(id, *args) ⇒ Object



37
38
39
40
# File 'lib/analytical/modules/totango.rb', line 37

def identify(id, *args)
  data = args.first || {}
  "tracker.identify(\"#{data[:organization]}\",\"#{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
32
33
34
35
# File 'lib/analytical/modules/totango.rb', line 11

def init_javascript(location)
  init_location(location) do
    js = <<-HTML
    <!-- Analytical Init: Totango -->
    <!-- step 1: include the loader script -->
    <script src='//s3.amazonaws.com/totango-cdn/sdr.js'></script>

    <!-- step 2: initialize tracking  -->
    <script type="text/javascript">
    try {
    	var tracker = new __sdr(\"#{options[:key]}\");
    } catch (err) {
    	// uncomment the alert below for debugging only
    	// alert ("Totango tracking code load failure, tracking will be ignored");
    	quite = function () {};
    	var tracker = {
    		track: quite,
    		identify: quite
    	};
    }
    </script>
    HTML
    js
  end
end