Class: Analytical::Modules::Adwords
- Inherits:
-
Object
- Object
- Analytical::Modules::Adwords
- Includes:
- Base
- Defined in:
- lib/analytical/modules/adwords.rb
Instance Attribute Summary
Attributes included from Base
#command_store, #initialized, #options, #tracking_command_location
Instance Method Summary collapse
-
#event(name, *args) ⇒ Object
Define conversion events in analytical.yml like:.
- #init_javascript(location) ⇒ Object
-
#initialize(options = {}) ⇒ Adwords
constructor
A new instance of Adwords.
Methods included from Base
#init_location, #init_location?, #process_queued_commands, #protocol, #queue
Constructor Details
#initialize(options = {}) ⇒ Adwords
6 7 8 9 |
# File 'lib/analytical/modules/adwords.rb', line 6 def initialize(={}) super @tracking_command_location = :body_append end |
Instance Method Details
#event(name, *args) ⇒ Object
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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/analytical/modules/adwords.rb', line 48 def event(name, *args) return '' unless @initializing data = args.first || {} if conversion = [name.to_sym] conversion.symbolize_keys! js = " <script type=\"text/javascript\">\n /* <![CDATA[ */\n var google_conversion_id = \#{conversion[:id]};\n var google_conversion_language = \"\#{conversion[:language]}\";\n var google_conversion_format = \"\#{conversion[:format]}\";\n var google_conversion_color = \"\#{conversion[:color]}\";\n var google_conversion_label = \"\#{conversion[:label]}\";\n var google_conversion_value = \#{data[:value] || conversion[:value]};\n /* ]]> */\n </script>\n <script type=\"text/javascript\" src=\"\#{protocol}://www.googleadservices.com/pagead/conversion.js\"></script>\n <noscript>\n <div style=\"display:inline;\">\n <img height=\"1\" width=\"1\" style=\"border-style:none;\" alt=\"\" src=\"\#{protocol}://www.googleadservices.com/pagead/conversion/\#{conversion[:id]}/?label=\#{conversion[:label]}&guid=ON&script=0\"/>\n </div>\n </noscript>\n HTML\n js\n else\n \"<!-- No Adwords Conversion for: \#{name} -->\"\n end\nend\n" |
#init_javascript(location) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/analytical/modules/adwords.rb', line 11 def init_javascript(location) init_location(location) do @initializing = true html = "<!-- Analytical Init: Google Adwords -->\n" event_commands = [] @command_store.commands.each do |c| if c[0] == :event event_commands << event(*c[1..-1]) end end html += event_commands.join("\n") @command_store.commands = @command_store.commands.delete_if {|c| c[0] == :event } @initializing = false html end end |