Module: Bacchanalytics::WebsiteOptimizerTrackingCode

Included in:
WebsiteOptimizer
Defined in:
lib/bacchanalytics/website_optimizer.rb

Instance Method Summary collapse

Instance Method Details

#website_optimizer_tracking_code(page, account_id, ab) ⇒ Object

Construct the Google WebSite Optimizer tracking code.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bacchanalytics/website_optimizer.rb', line 6

def website_optimizer_tracking_code(page, , ab)
  if page.blank? || .blank? || !ab_options_valid?(ab)
    return ""
  end

  gotc = ""
  begin
    goal_keys = [] # Multiple tests and the same goal
    for key in ab.keys do
      value = ab[key]
      next unless value[:locales].nil? || [value[:locales]].flatten.map(&:to_s).include?(I18n.locale.to_s)

      a = value[:a].to_a
      b = value[:b].to_a
      g = value[:goal].to_a

      # Check the requested page, to include the A, B or goal tracking code.
      if a.include?(page)
        gotc = a_tracking_code(, key)
        break
      elsif b.include?(page)
        gotc = b_tracking_code(, key)
        break
      elsif g.include?(page)
        goal_keys << key
      end
    end

    if gotc.blank?
      gotc = goal_tracking_code(, goal_keys)
    end

  rescue Exception => e
    logger.debug "#{e.message}"
    gotc = ""
  end

  gotc
end