Module: GWO::Helper

Includes:
ActionView::Helpers::CaptureHelper, ActionView::Helpers::TagHelper
Defined in:
lib/gwo.rb

Instance Method Summary collapse

Instance Method Details

#gwo_conversion(id, uacct, options = {}) ⇒ Object

to be included on the conversion page.

Params:

  • id & uacct see gwo_experiment

  • options

    • :conditions as in gwo_experiment



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/gwo.rb', line 76

def gwo_conversion(id, uacct, options = {})  
  options = {
    :conditions => (ENV['RAILS_ENV'] == 'test' ? false : true)
  }.update(options)

  return js_logger("skipping conversion snippet: a/b variation test switched off", true) if options[:conditions] == false

  %{
  <script type="text/javascript">
  #{ js_logger("'conversion for test with id #{id} and uacct #{uacct}'") }
  if(typeof(_gat)!='object')document.write('<sc'+'ript src="http'+
  (document.location.protocol=='https:'?'s://ssl':'://www')+
  '.google-analytics.com/ga.js"></sc'+'ript>')</script>
  <script type="text/javascript">
  try {
  var gwoPageTracker=_gat._getTracker("#{uacct}");
  gwoPageTracker._trackPageview("/#{id}/goal");
  }catch(err){}</script>
  }

end

#gwo_experiment(id, uacct, sections = [], options = {}, &block) ⇒ Object

start a gwo_experiment

Params:

  • id the id of the experiment (in the google Tracking Script look for something like pageTracker._trackPageview("/<ID>/test"); )

  • uacct account number (in the google Tracking Script look for something like var pageTracker=_gat._getTracker("<UACCT>"); )

  • sections name of the section(s) your page will include; pass in one symbol/string or an array of symbols/strings here

  • options hash of possible options:

    • :conditions if set to false, the experiment won’t be executed – only the source code of the :original (or 0) variants would be shown. No JavaScript code will be produced. It serves as a kill switch for the gwo experiment. If, for example, you only want to execute an experiment for users that are not logged in, you could pass :conditions => !logged_in? here.

    • :google_analytics a hash for google analytics tracking: it will call the google analytics script with either the document.location or a virtual url if you provide it. At the end of the url, gwo appends information about which a/b test was executed and which section was the user had in the form of url parameters (s.th. like http://&lt;url&gt;?ab_test=&lt;id&gt;&section=&lt;section name &gt; )

      • :account_number the google analytics account id where the tracking should take place

      • :virtual_url if you want to choose a different tracking url then the document.location for tracking

      • :goal_is_bounce_rate if true, every click on a link on the current view is counted as a goal (NOTE: this includes external links as well)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gwo.rb', line 27

def gwo_experiment(id, uacct, sections = [], options = {}, &block)
  options = {
    :conditions => (ENV['RAILS_ENV'] == 'test' ? false : true),
    :goal_is_bounce_rate => false
  }.update(options)

  src  = gwo_start(id, sections, options)
  src += capture(&block) if block
  src += gwo_end(id, uacct, options)

  if options[:goal_is_bounce_rate]
    src +=<<JS
<script type="text/javascript"><!--
function addEvent( obj, type, fn ) {
   if (obj.addEventListener) {
      obj.addEventListener( type, fn, false );
   } else if (obj.attachEvent) {
      obj["e"+type+fn] = fn;
      obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
      obj.attachEvent( "on"+type, obj[type+fn] );
   }
}


addEvent(document, "click", function(event) { 
  if( event.target.nodeName === "A" ) {
    #{js_logger("'bounce rate goal reached'")}
    try {
      var gwoPageTracker=_gat._getTracker("#{uacct}");
      gwoPageTracker._trackPageview("/#{id}/goal");
    }catch(err){}
  }
});
#{js_logger("'set goal to bounce rate minimization'")}
  //-->
</script>
JS
  end

  src
end

#gwo_section(section = "gwo_section", variation_ids = nil, options = {}, &block) ⇒ Object

identify a section which is only visible in certain variants

Params:

  • section name of the section

  • variation_ids identifiers of the variants in which this content is to be shown. Can be either a name of the variant (== the content of a variant in the GWO web interface) or a number. The original content has the reserved name :original or the number 0 respectivly. If the content should be shown in more than one variant, pass in an array of identifiers. Mixing numbered and named variant ids will result in an exception.

  • options

    • :conditions as in gwo_experiment



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/gwo.rb', line 106

def gwo_section(section = "gwo_section", variation_ids = nil, options = {}, &block)
  options = {
    :conditions => (ENV['RAILS_ENV'] == 'test' ? false : true)
  }.update(options)

  variation_ids = [*variation_ids].compact
  src = ""
  if is_default_section?(variation_ids)
    if options[:conditions] == false
      src += capture(&block)
    else
      conditions = (named_variations?(variation_ids) ? variation_ids.map{|x| "GWO_#{section}_name != \"#{x}\""} : variation_ids.map{|x| "GWO_#{section}_number != #{x}"}).join(" && ")

      src += %{ <script>
      if ( #{ conditions } ) document.write('<no' + 'script>');
      </script>
        #{capture(&block) if block_given?}
      </noscript>
      }
    end
  elsif options[:conditions] == true
    if !variation_ids.empty?
      conditions = (named_variations?(variation_ids) ? variation_ids.map{|x| "GWO_#{section}_name == \"#{x}\""} : variation_ids.map{|x| "GWO_#{section}_number == #{x}"}).join(" || ") 
         
      src += %{<script>
      if ( #{ conditions } ) document.write('</noscript a="');
      </script><!--">
        #{capture(&block) if block_given?}
      <script>document.write('<'+'!'+'-'+'-')</script>-->
      }
    end
  else
    src =  js_logger("skipping snippet for #{variation_ids.join(", ")} variations: a/b variation test switched off", true) 
  end
  src
end