Class: Slimmer::GoogleAnalyticsConfigurator

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

Constant Summary collapse

HEADER_MAPPING =
{
  "Section"     => "X-SLIMMER-SECTION",
  "Format"      => "X-SLIMMER-FORMAT",
  "NeedID"      => "X-SLIMMER-NEED-ID",
  "Proposition" => "X-SLIMMER-PROPOSITION",
}

Instance Method Summary collapse

Constructor Details

#initialize(headers) ⇒ GoogleAnalyticsConfigurator

Returns a new instance of GoogleAnalyticsConfigurator.



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

def initialize(headers)
  @headers = normalise_headers(headers)
end

Instance Method Details

#filter(src, dest) ⇒ Object



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

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