moviepilot-gwo 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gwo.rb +24 -24
- data/spec/lib/gwo_spec.rb +15 -11
- metadata +1 -1
data/lib/gwo.rb
CHANGED
@@ -18,13 +18,14 @@ module GWO
|
|
18
18
|
# * <b>sections</b> name of the section(s) your page will include; pass in one symbol/string or an array of symbols/strings here
|
19
19
|
# * <b>options</b> hash of possible options:
|
20
20
|
# * <b>:conditions</b> 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 <tt>:conditions => !logged_in?</tt> here.
|
21
|
+
# * <b>:google_analytics</b> a hash for google analytics tracking:
|
22
|
+
# * <b>:account_number</b>
|
23
|
+
# * <b>:virtual_url</b>
|
21
24
|
# * <b>:ga_tracking</b> executes a <tt>trackPageView(...)</tt> for google analytics tracking. It adds parameters to the URL, so you can identify which variant (or combination) the user saw (handy if you want to check on the exit rate with GA)
|
22
25
|
# * <b>:ga_base_url</b> set a static base URL for google analytics: Say your variant is in a 'show' view, GA would track a lot of different URLs (as the show view url contains the ID). If you are just interested about the variants in GA, set a static URL here (i.e. hbp://<your domain>/ab-testing ) and GA tracking will always be that static domain + parameters with information about the variant the user saw.
|
23
26
|
def gwo_experiment(id, uacct, sections = [], options = {}, &block)
|
24
27
|
options = {
|
25
28
|
:conditions => true,
|
26
|
-
:ga_tracking => false,
|
27
|
-
:ga_base_url => nil
|
28
29
|
}.update(options)
|
29
30
|
|
30
31
|
src = gwo_start(id, sections, options)
|
@@ -55,8 +56,8 @@ module GWO
|
|
55
56
|
'.google-analytics.com/ga.js"></sc'+'ript>')</script>
|
56
57
|
<script type="text/javascript">
|
57
58
|
try {
|
58
|
-
var
|
59
|
-
|
59
|
+
var gwoPageTracker=_gat._getTracker("#{uacct}");
|
60
|
+
gwoPageTracker._trackPageview("/#{id}/goal");
|
60
61
|
}catch(err){}</script>
|
61
62
|
}
|
62
63
|
|
@@ -141,27 +142,26 @@ module GWO
|
|
141
142
|
sections.each do |section|
|
142
143
|
section_definitions += "<!-- utmx section name='#{section}' -->\n"
|
143
144
|
|
144
|
-
variable_assignments += %{
|
145
|
-
var GWO_#{section}_name = utmx("variation_content", "#{section}")
|
146
|
-
if( GWO_#{section}
|
147
|
-
|
148
|
-
var GWO_#{section}_number = utmx("variation_number", "#{section}");\
|
149
|
-
if( GWO_#{section}_number == undefined) GWO_#{section}_number = 0;\
|
150
|
-
\
|
151
|
-
#{ js_logger("'variant: ' + GWO_#{section}_name") }\
|
145
|
+
variable_assignments += %{
|
146
|
+
var GWO_#{section}_name = utmx("variation_content", "#{section}");if( GWO_#{section}_name == undefined) GWO_#{section}_name = 'original';
|
147
|
+
var GWO_#{section}_number = utmx("variation_number", "#{section}");if( GWO_#{section}_number == undefined) GWO_#{section}_number = 0;
|
148
|
+
#{ js_logger("'variant: ' + GWO_#{section}_name") }
|
152
149
|
}
|
153
|
-
google_analytics_info += "google_analytics_info += \"&#{section}=\" + GWO_#{section}_name;" if options[:
|
150
|
+
google_analytics_info += "google_analytics_info += \"&#{section}=\" + GWO_#{section}_name;" if options[:google_analytics]
|
154
151
|
end
|
155
152
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
153
|
+
# GOOGLE TRACKER:
|
154
|
+
if options[:google_analytics]
|
155
|
+
base_url = options[:google_analytics][:virtual_url] ? "\"#{options[:google_analytics][:virtual_url]}\"" : "document.location"
|
156
|
+
variable_assignments += %{
|
157
|
+
window.onload = function(){
|
158
|
+
var google_analytics_info = ''; #{google_analytics_info};
|
159
|
+
try{
|
160
|
+
var gwoGaPageTracker=_gat._getTracker("#{options[:google_analytics][:account_id]}");
|
161
|
+
gwoGaPageTracker._trackPageview(#{base_url} + "?ab_test=#{id}" + google_analytics_info);
|
162
|
+
}catch(err){ #{js_logger("\"error executing google analytics request\"")} }
|
163
|
+
#{js_logger("\"tracking \" + #{base_url} + \"?ab_test=#{id}\" + google_analytics_info + \" to account #{options[:google_analytics][:account_id]}\"")}
|
164
|
+
}
|
165
165
|
}
|
166
166
|
end
|
167
167
|
|
@@ -179,8 +179,8 @@ module GWO
|
|
179
179
|
'.google-analytics.com/ga.js"></sc'+'ript>')</script>
|
180
180
|
<script type="text/javascript">
|
181
181
|
try {
|
182
|
-
var
|
183
|
-
|
182
|
+
var gwoPageTracker=_gat._getTracker("#{uacct}");
|
183
|
+
gwoPageTracker._trackPageview("/#{id}/test");
|
184
184
|
}catch(err){}</script>
|
185
185
|
}
|
186
186
|
|
data/spec/lib/gwo_spec.rb
CHANGED
@@ -7,28 +7,32 @@ describe GWO do
|
|
7
7
|
describe "google analytics stuff" do
|
8
8
|
it "should not create any google analytics stuff by default" do
|
9
9
|
gwo_start("gwo_id", "section_name").should_not =~ /google_analytics_info \+= \"§ion_name=\" \+ GWO_section_name_name;/
|
10
|
-
gwo_start("gwo_id", "section_name").should_not =~ /
|
10
|
+
gwo_start("gwo_id", "section_name").should_not =~ /gwoGaPageTracker\(document.location \+ \"\?ab_test=gwo_id\" \+ google_analytics_info\)/
|
11
11
|
end
|
12
12
|
it "should not create google analytics stuff if option is disabled" do
|
13
|
-
gwo_start("gwo_id", "section_name"
|
14
|
-
gwo_start("gwo_id", "section_name"
|
13
|
+
gwo_start("gwo_id", "section_name").should_not =~ /google_analytics_info \+= \"§ion_name=\" \+ GWO_section_name_name;/
|
14
|
+
gwo_start("gwo_id", "section_name").should_not =~ /gwoGaPageTracker\(document.location \+ \"\?ab_test=gwo_id\" \+ google_analytics_info\)/
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should create correct google analytics stuff for default urls" do
|
18
|
-
gwo_start("gwo_id", "section_name", :
|
19
|
-
gwo_start("gwo_id", "section_name", :
|
18
|
+
gwo_start("gwo_id", "section_name", :google_analytics => {:account_id => "123456789"}).should =~ /google_analytics_info \+= \"§ion_name=\" \+ GWO_section_name_name;/
|
19
|
+
gwo_start("gwo_id", "section_name", :google_analytics => {:account_id => "123456789"}).should =~ /gwoGaPageTracker._trackPageview\(document.location \+ \"\?ab_test=gwo_id\" \+ google_analytics_info\)/
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should create correct google analytics stuff for static urls" do
|
23
|
-
gwo_start("gwo_id", "section_name", :
|
24
|
-
|
23
|
+
gwo_start("gwo_id", "section_name", :google_analytics => {:account_id => "123456789", :virtual_url => "http://example.com"}).should =~
|
24
|
+
/google_analytics_info \+= \"§ion_name=\" \+ GWO_section_name_name;/
|
25
|
+
gwo_start("gwo_id", "section_name", :google_analytics => {:account_id => "123456789", :virtual_url => "http://example.com"}).should =~
|
26
|
+
/var gwoGaPageTracker=_gat._getTracker\(\"123456789\"\);/
|
27
|
+
gwo_start("gwo_id", "section_name", :google_analytics => {:account_id => "123456789", :virtual_url => "http://example.com"}).should =~
|
28
|
+
/gwoGaPageTracker._trackPageview\(\"http:\/\/example\.com\" \+ \"\?ab_test=gwo_id\" \+ google_analytics_info\)/
|
25
29
|
end
|
26
30
|
|
27
31
|
it "should create correct google analytics stuff for several sections" do
|
28
|
-
gwo_start("gwo_id", ["section_name1", "section_name2", "section_name3"], :
|
29
|
-
gwo_start("gwo_id", ["section_name1", "section_name2", "section_name3"], :
|
30
|
-
gwo_start("gwo_id", ["section_name1", "section_name2", "section_name3"], :
|
31
|
-
gwo_start("gwo_id", ["section_name1", "section_name2", "section_name3"], :
|
32
|
+
gwo_start("gwo_id", ["section_name1", "section_name2", "section_name3"], :google_analytics => {:account_id => "123456789"}).should =~ /google_analytics_info \+= \"§ion_name1=\" \+ GWO_section_name1_name;/
|
33
|
+
gwo_start("gwo_id", ["section_name1", "section_name2", "section_name3"], :google_analytics => {:account_id => "123456789"}).should =~ /google_analytics_info \+= \"§ion_name2=\" \+ GWO_section_name2_name;/
|
34
|
+
gwo_start("gwo_id", ["section_name1", "section_name2", "section_name3"], :google_analytics => {:account_id => "123456789"}).should =~ /google_analytics_info \+= \"§ion_name3=\" \+ GWO_section_name3_name;/
|
35
|
+
gwo_start("gwo_id", ["section_name1", "section_name2", "section_name3"], :google_analytics => {:account_id => "123456789"}).should =~ /gwoGaPageTracker._trackPageview\(document.location \+ \"\?ab_test=gwo_id\" \+ google_analytics_info\)/
|
32
36
|
end
|
33
37
|
|
34
38
|
end
|