class Satellite::Adapters::GoogleAnalytics::Utme::CustomVariables
Public Class Methods
new()
click to toggle source
# File lib/satellite/adapters/google_analytics.rb, line 218 def initialize @contents = { } end
Public Instance Methods
set_custom_variable(slot, custom_variable)
click to toggle source
# File lib/satellite/adapters/google_analytics.rb, line 222 def set_custom_variable(slot, custom_variable) raise ArgumentError, "Cannot set a slot other than #{@@valid_keys}. Given #{slot}" if not @@valid_keys.include?(slot) @contents[slot] = custom_variable end
to_s()
click to toggle source
follows google custom variable format
8(NAMES)9(VALUES)11(SCOPES)
best explained by examples
1) pageTracker._setCustomVar(1,“foo”, “val”, 1)
> 8(foo)9(bar)11(1)¶ ↑
2) pageTracker._setCustomVar(1,“foo”, “val”, 1) pageTracker._setCustomVar(2,“bar”, “vok”, 3)
> 8(foo*bar)9(val*vok)11(1*3)¶ ↑
3) pageTracker._setCustomVar(1,“foo”, “val”, 1) pageTracker._setCustomVar(2,“bar”, “vok”, 3) pageTracker._setCustomVar(4,“baz”, “vol”, 1)
> 8(foo*bar*4!baz)9(val*vak*4!vol)11(1*3*4!1)¶ ↑
4) pageTracker._setCustomVar(4,“foo”, “bar”, 1)
> 8(4!foo)9(4!bar)11(4!1)¶ ↑
# File lib/satellite/adapters/google_analytics.rb, line 257 def to_s return '' if @contents.empty? ordered_keys = @contents.keys.sort names = values = scopes = '' ordered_keys.each do |slot| custom_variable = @contents[slot] predecessor = @contents[slot-1] has_predecessor = !!predecessor has_scoped_predecessor = !!(predecessor.try(:opt_scope)) star = names.empty? ? '' : '*' bang = (slot == 1 || has_predecessor) ? '' : "#{slot}!" scope_star = scopes.empty? ? '' : '*' scope_bang = (slot == 1 || has_scoped_predecessor) ? '' : "#{slot}!" names += "#{star}#{bang}#{custom_variable.name}" values += "#{star}#{bang}#{custom_variable.value}" scopes += "#{scope_star}#{scope_bang}#{custom_variable.opt_scope}" if custom_variable.opt_scope end output = "8(#{names})9(#{values})" output += "11(#{scopes})" if not scopes.empty? output end
unset_custom_variable(slot)
click to toggle source
# File lib/satellite/adapters/google_analytics.rb, line 227 def unset_custom_variable(slot) raise ArgumentError, "Cannot unset a slot other than #{@@valid_keys}. Given #{slot}" if not @@valid_keys.include?(slot) @contents.delete(slot) end