class Satellite::Adapters::GoogleAnalytics::Utme
Constants
- CustomVariable
- Event
Public Class Methods
from_string(str)
click to toggle source
# File lib/satellite/adapters/google_analytics.rb, line 150 def from_string(str) utme = self.new # parse event str.gsub!(@@regex_event) do |match| utme.set_event($1, $2, $4, $6) '' end # parse custom variables str.gsub!(@@regex_custom_variables) do |match| custom_vars = { } match_names, match_values, match_scopes = $1, $2, $4 names = match_names.to_s.split('*') values = match_values.to_s.split('*') scopes = match_scopes.to_s.split('*') raise ArgumentError, "Each custom variable must have a value defined." if names.length != values.length names.each_with_index do |raw_name, i| match_data = raw_name.match(@@regex_custom_variable_value) slot, name = (match_data[2] || i+1).to_i, match_data[3] custom_vars[slot] = { :name => name } end values.each_with_index do |raw_value, i| match_data = raw_value.match(@@regex_custom_variable_value) slot, value = (match_data[2] || i+1).to_i, match_data[3] custom_vars[slot][:value] = value end scopes.each_with_index do |raw_scope, i| match_data = raw_scope.match(@@regex_custom_variable_value) slot, scope = (match_data[2] || i+1).to_i, match_data[3] # silently ignore scope if there's no corresponding custom variable custom_vars[slot][:scope] = scope if custom_vars[slot] end # finally set all the gathered custom vars custom_vars.each do |key, custom_var| utme.set_custom_variable(key, custom_var[:name], custom_var[:value], custom_var[:scope]) end '' end utme end
new()
click to toggle source
# File lib/satellite/adapters/google_analytics.rb, line 107 def initialize @custom_variables = CustomVariables.new end
parse(args)
click to toggle source
# File lib/satellite/adapters/google_analytics.rb, line 138 def parse(args) return self.new if args.nil? case args when String return self.from_string(args.dup) when self return args else raise ArgumentError, "Could parse argument neither as String nor GATracker::Utme" end end
Public Instance Methods
set_custom_variable(slot, name, value, scope=nil)
click to toggle source
# File lib/satellite/adapters/google_analytics.rb, line 116 def set_custom_variable(slot, name, value, scope=nil) @custom_variables.set_custom_variable(slot, CustomVariable.new(name, value, scope)) self end
set_event(category, action, label=nil, value=nil)
click to toggle source
# File lib/satellite/adapters/google_analytics.rb, line 111 def set_event(category, action, label=nil, value=nil) @event = Event.new(category, action, label, value) self end
to_s()
click to toggle source
# File lib/satellite/adapters/google_analytics.rb, line 126 def to_s @event.to_s + @custom_variables.to_s end
Also aliased as: to_param
unset_custom_variable(slot)
click to toggle source
# File lib/satellite/adapters/google_analytics.rb, line 121 def unset_custom_variable(slot) @custom_variables.unset_custom_variable(slot) self end