optimize_ab 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,91 @@
1
1
  module Helpers
2
- def ab_head
2
+
3
+ ###################################################################
4
+ #
5
+ # How to use Optimize_AB
6
+ # ---------------------------------------
7
+ # Taken from but altered slightly:
8
+ # http://support.google.com/websiteoptimizer/bin/static.py?hl=en&topic=29622&guide=29619&page=guide.cs#m2
9
+ #
10
+ #
11
+ # Multi-Variate Control & Tracking Script
12
+ # ---------------------------------------
13
+ # The control script goes on your test page and makes sure that
14
+ # the experiment variations are switched randomly and that all
15
+ # variations are displayed an equal number of times.
16
+ #
17
+ # The tracking script goes on your test page ensures that visits
18
+ # to the page are recorded in the experiment.
19
+ #
20
+ # The control script immediately after the <head> tag.
21
+ #
22
+ #
23
+ # Page sections scripts
24
+ # ---------------------------------------
25
+ # The page sections script is used to mark
26
+ # the elements that will be varied during the experiment.
27
+ # Essentially, you need to use the script provided by Website
28
+ # Optimizer to define the beginning and end of each element. For
29
+ # each element, you will need to name the page section in the script.
30
+ # As an example, let's say you defined a header that welcomes
31
+ # people to your page. The starting HTML code looks like this:
32
+ #
33
+ # <h1>Welcome!</h1>
34
+ #
35
+ # After adding your section script, the header will look like this
36
+ # (with the custom name "Headline" for this section in italics):
37
+ #
38
+ # <h1>
39
+ # <%= multi_begin_section("Headline") %>
40
+ # Welcome!
41
+ # <%= multi_end_section %>
42
+ # </h1>
43
+ #
44
+ #
45
+ # Conversion Script
46
+ # ---------------------------------------
47
+ # The conversion script tracks visits to your conversion page and
48
+ # should be placed immediately before the closing </head> tag on
49
+ # your conversion page.
50
+ #
51
+ #
52
+ # OnClick Conversion Script
53
+ # ---------------------------------------
54
+ # The conversion script tracks visits to your conversion page and
55
+ # should be placed immediately before the closing </head> tag on
56
+ # your conversion page.
57
+ #
58
+ # Next, you'll need to add a snippet of text to the link or links
59
+ # that you want to track as a conversion. Let's say your link
60
+ # looks like this:
61
+ #
62
+ # <a href="http://www.example.com/promotion">Featured Products</a>
63
+ #
64
+ # To count a conversion when this link is clicked, add:
65
+ #
66
+ # onclick="doGoal(this);return false;"
67
+ #
68
+ # to the HTML tag. The new link will look like this
69
+ # (addition in bold):
70
+ #
71
+ # <a href="http://www.example.com/promotion" onclick="doGoal(this);return false;">Featured Products</a>
72
+ #
73
+ # You can modify as many links as you want to count as a conversion,
74
+ # but all of them will be counted identically as conversions in your
75
+ # experiment results. In other words, Website Optimizer will not
76
+ # differentiate between them when reporting conversions.
77
+ #
78
+ ####################################################################
79
+
80
+
81
+ ######## Multi-Variate Control & Tracking Script ########
82
+
83
+ def multi_head(k, ua, pv)
3
84
  js = <<-HTML
4
85
  <!-- Google Website Optimizer Control Script -->
5
86
  <script>
6
87
  function utmx_section(){}function utmx(){}
7
- (function(){var k='3270946421',d=document,l=d.location,c=d.cookie;function f(n){
88
+ (function(){var k="#{k}",d=document,l=d.location,c=d.cookie;function f(n){
8
89
  if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.indexOf(';',i);return escape(c.substring(i+n.
9
90
  length+1,j<0?c.length:j))}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;
10
91
  d.write('<sc'+'ript src="'+
@@ -17,8 +98,8 @@ module Helpers
17
98
  <!-- Google Website Optimizer Tracking Script -->
18
99
  <script type="text/javascript">
19
100
  var _gaq = _gaq || [];
20
- _gaq.push(['gwo._setAccount', 'UA-29835325-2']);
21
- _gaq.push(['gwo._trackPageview', '/3270946421/test']);
101
+ _gaq.push(['gwo._setAccount', "#{ua}"]);
102
+ _gaq.push(['gwo._trackPageview', "#{pv}"]);
22
103
  (function() {
23
104
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
24
105
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
@@ -29,4 +110,68 @@ module Helpers
29
110
  HTML
30
111
  return js.html_safe
31
112
  end
113
+
114
+
115
+ ######## Page Sections Scripts ########
116
+
117
+ def multi_begin_section(name)
118
+ js = <<-HTML
119
+ <script>utmx_section("#{name}")</script>
120
+ HTML
121
+ return js.html_safe
122
+ end
123
+
124
+ def multi_end_section
125
+ js = <<-HTML
126
+ </noscript>
127
+ HTML
128
+ return js.html_safe
129
+ end
130
+
131
+
132
+ ######## Mutli-Conversion Script ########
133
+
134
+ def multi_converstion(ua, pv)
135
+ js = <<-HTML
136
+ <!-- Google Website Optimizer Tracking Script -->
137
+ <script type="text/javascript">
138
+ var _gaq = _gaq || [];
139
+ _gaq.push(['gwo._setAccount', "#{ua}"]);
140
+ _gaq.push(['gwo._trackPageview', "#{pv}"]);
141
+ (function() {
142
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
143
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
144
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
145
+ })();
146
+ </script>
147
+ <!-- End of Google Website Optimizer Tracking Script -->
148
+ HTML
149
+ return js.html_safe
150
+ end
151
+
152
+ ######## OnClick Conversion Script ########
153
+
154
+ def multi_on_click_converstion(ua, pv)
155
+ js = <<-HTML
156
+ <!-- Google Website Optimizer Tracking Script -->
157
+ <script type="text/javascript">
158
+ var _gaq = _gaq || [];
159
+ _gaq.push(['gwo._setAccount', "#{ua}"]);
160
+ function doGoal(that) {
161
+ try {
162
+ _gaq.push(['gwo._trackPageview', "#{pv}"]);
163
+ setTimeout('document.location = "' + that.href + '"', 100)
164
+ }
165
+ catch(err){}
166
+ }
167
+ (function() {
168
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
169
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
170
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
171
+ })();
172
+ </script>
173
+ <!-- End of Google Website Optimizer Tracking Script -->
174
+ HTML
175
+ return js.html_safe
176
+ end
32
177
  end
@@ -1,3 +1,3 @@
1
1
  module OptimizeAb
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optimize_ab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: