Module: Analytical::Modules::Base

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#command_storeObject (readonly)

Returns the value of attribute command_store.



5
6
7
# File 'lib/analytical/modules/base.rb', line 5

def command_store
  @command_store
end

#initializedObject (readonly)

Returns the value of attribute initialized.



4
5
6
# File 'lib/analytical/modules/base.rb', line 4

def initialized
  @initialized
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/analytical/modules/base.rb', line 4

def options
  @options
end

#tracking_command_locationObject (readonly)

Returns the value of attribute tracking_command_location.



4
5
6
# File 'lib/analytical/modules/base.rb', line 4

def tracking_command_location
  @tracking_command_location
end

Instance Method Details

#init_location(location, &block) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/analytical/modules/base.rb', line 68

def init_location(location, &block)
  if init_location?(location)
    @initialized = true
    if block_given?
      yield
    else
      ''
    end
  else
    ''
  end
end

#init_location?(location) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
# File 'lib/analytical/modules/base.rb', line 60

def init_location?(location)
  if @tracking_command_location.is_a?(Array)
    @tracking_command_location.map { |item|item.to_sym }.include?(location.to_sym)
  else
    @tracking_command_location.to_sym == location.to_sym
  end
end

#initialize(_options = {}) ⇒ Object



7
8
9
10
11
12
# File 'lib/analytical/modules/base.rb', line 7

def initialize(_options={})
  @options = _options
  @tracking_command_location = :body_prepend
  @initialized = false
  @command_store = @options[:session_store] || Analytical::CommandStore.new
end

#process_queued_commandsObject



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

def process_queued_commands
  command_strings = @command_store.collect do |c|
    send(*c) if respond_to?(c.first)
  end.compact
  @command_store.flush
  command_strings
end

#protocolObject



14
15
16
# File 'lib/analytical/modules/base.rb', line 14

def protocol
  @options[:ssl] ? 'https' : 'http'
end

#queue(*args) ⇒ Object

This method generates the initialization javascript that an analytics service uses to track your site def init_javascript(location)



44
45
46
47
48
49
50
51
# File 'lib/analytical/modules/base.rb', line 44

def queue(*args)
  return if @options[:ignore_duplicates] && @command_store.include?(args)
  if args.first==:identify
    @command_store.unshift args
  else
    @command_store << args
  end
end