Class: Analytical::Modules::Console

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

Constant Summary collapse

CONSOLE_JS_ESCAPE_MAP =
{
  '\\' => '\\\\',
  '</' => '<\/',
  "\r\n" => '\n',
  "\n" => '\n',
  "\r" => '\n',
  '"' => '\\"',
  "'" => "\\'"
}

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 = {}) ⇒ Console

Returns a new instance of Console.



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

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

Instance Method Details

#alias_identity(old_identity, new_identity) ⇒ Object



54
55
56
57
58
# File 'lib/analytical/modules/console.rb', line 54

def alias_identity(old_identity,new_identity)
  check_for_console <<-HERE
  console.log("Analytical Alias: #{old_identity} => #{new_identity}");
  HERE
end

#event(name, *args) ⇒ Object



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

def event(name, *args)
  data = args.first || {}
  check_for_console <<-HERE
  console.log("Analytical Event: "+"#{escape name}");
  console.log(#{data.to_json});
  HERE
end

#identify(id, *args) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/analytical/modules/console.rb', line 31

def identify(id, *args)
  data = args.first || {}
  check_for_console <<-HERE
  console.log("Analytical Identify: "+"#{escape id}");
  console.log(#{data.to_json});
  HERE
end

#init_javascript(location) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/analytical/modules/console.rb', line 11

def init_javascript(location)
  init_location(location) do
    js = <<-HTML
    <!-- Analytical Init: Console -->
    <script type="text/javascript">
      if(typeof(console) !== 'undefined' && console != null) {
        console.log('Analytical Init: Console');
      }
    </script>
    HTML
    js
  end
end

#set(data) ⇒ Object



47
48
49
50
51
52
# File 'lib/analytical/modules/console.rb', line 47

def set(data)
  check_for_console <<-HERE
  console.log("Analytical Set: ");
  console.log(#{data.to_json});
  HERE
end

#track(*args) ⇒ Object



25
26
27
28
29
# File 'lib/analytical/modules/console.rb', line 25

def track(*args)
  check_for_console <<-HERE
  console.log("Analytical Track: "+"#{escape args.first}");
  HERE
end