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



37
38
39
40
41
42
43
44
45
# File 'lib/analytical/modules/clicky.rb', line 37

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
# File 'lib/analytical/modules/clicky.rb', line 11

def init_javascript(location)
  init_location(location) do
    js = <<-HTML
    <!-- Analytical Init: Clicky -->
    <script src="#{protocol}://static.getclicky.com/js" type="text/javascript"></script>
    <script type="text/javascript">clicky.init('#{@options[:key]}');</script>
    <noscript><p><img alt="Clicky" width="1" height="1" src="#{protocol}://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



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

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