Class: Slimmer::GoogleAnalyticsConfigurator

Inherits:
Object
  • Object
show all
Defined in:
lib/slimmer/google_analytics_configurator.rb

Constant Summary collapse

PAGE_LEVEL_EVENT =
3
HEADER_MAPPING =
{
  "Section"     => "X-SLIMMER-SECTION",
  "Format"      => "X-SLIMMER-FORMAT",
  "NeedID"      => "X-SLIMMER-NEED-ID",
  "Proposition" => "X-SLIMMER-PROPOSITION",
  "ResultCount" => "X-SLIMMER-RESULT-COUNT"
}

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ GoogleAnalyticsConfigurator

Returns a new instance of GoogleAnalyticsConfigurator.



14
15
16
# File 'lib/slimmer/google_analytics_configurator.rb', line 14

def initialize(response)
  @headers = response.headers
end

Instance Method Details

#filter(src, dest) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/slimmer/google_analytics_configurator.rb', line 18

def filter(src, dest)
  custom_vars = HEADER_MAPPING.map.with_index(1) { |(name, key), slot|
    set_custom_var(slot, name, @headers[key])
  }.compact.join("\n");

  if dest.at_css("#ga-params")
    dest.at_css("#ga-params").content += custom_vars
  end
end