Class: Analytical::Modules::Clicky

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

Returns a new instance of Clicky.



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

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

Instance Method Details

#identify(id, *args) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/analytical/modules/clicky.rb', line 46

def identify(id, *args)
  data = { :id=>id }.merge(args.first || {})
  code = <<-HTML
  <script type='text/javascript'>
    var clicky_custom_session = #{data.to_json};
  </script>
  HTML
  code
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
36
37
38
39
40
# File 'lib/analytical/modules/clicky.rb', line 11

def init_javascript(location)
  init_location(location) do
    js = <<-HTML
    <!-- Analytical Init: Clicky -->
    <script type="text/javascript">
      var clicky_site_ids = clicky_site_ids || [];
      clicky_site_ids.push(#{@options[:key]});
      (function() {
        var s = document.createElement('script');
        s.type = 'text/javascript';
        s.async = true;
        s.src = '//static.getclicky.com/js';
        ( document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0] ).appendChild( s );
      })();
    </script>
    <noscript><p><img alt="Clicky" width="1" height="1" src="//in.getclicky.com/#{@options[:key]}ns.gif" /></p></noscript>
    HTML

    identify_commands = []
    @command_store.commands.each do |c|
      if c[0] == :identify
        identify_commands << identify(*c[1..-1])
      end
    end
    js = identify_commands.join("\n") + "\n" + js
    @command_store.commands = @command_store.commands.delete_if {|c| c[0] == :identify }

    js
  end
end

#track(*args) ⇒ Object



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

def track(*args)
  "clicky.log(\"#{args.first}\");"
end