module Analytical
module Modules
class Adwords
include Analytical::Modules::Base
def initialize(options={})
super
@tracking_command_location = :body_append
end
def init_javascript(location)
init_location(location) do
@initializing = true
html = "\n"
event_commands = []
@commands.each do |c|
if c[0] == :event
event_commands << event(*c[1..-1])
end
end
html += event_commands.join("\n")
@commands = @commands.delete_if {|c| c[0] == :event }
@initializing = false
html
end
end
#
# Define conversion events in analytical.yml like:
#
# adwords:
# 'Some Event':
# id: 4444555555
# language: en
# format: 2
# color: ffffff
# label: xxxxxxxxxxxxxxxx
# value: 0
# 'Another Event':
# id: 1111333333
# language: en
# format: 2
# color: ffffff
# label: yyyyyyyyyyyyyyyy
# value: 0
#
def event(name, *args)
return '' unless @initializing
data = args.first || {}
if conversion = options[name.to_sym]
conversion.symbolize_keys!
js = <<-HTML
HTML
js
else
""
end
end
end
end
end