guerrilla_rotate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +20 -0
  2. data/README.markdown +46 -0
  3. data/lib/guerrilla_rotate.rb +48 -0
  4. metadata +106 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jason King
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ GuerrillaRotate
2
+ ==============
3
+
4
+ This plugin lets you have multiple view pages for the one action, so that you
5
+ can rotate through different views in order to test which one is the most
6
+ effective. This is known as A/B testing, split testing or side-by-side
7
+ testing.
8
+
9
+ It will automatically switch between the different views for different web
10
+ requests (uses .rand so is pseudo random, not round-robin or anything). The
11
+ particular view is sticky for a (rails) session, so that once that view has been
12
+ chosen for that visitor they will see the same, consistent view each time.
13
+
14
+ It integrates automagically into
15
+ [Rubaidh::GoogleAnalytics](http://github.com/rubaidh/google_analytics) by
16
+ setting the override_trackpageview to the name of the unique view file (instead
17
+ of the action-based URL) so you can track it easily in Google Analytics.
18
+
19
+ Without that you'll want to track it by putting different tracking codes in each
20
+ of your view templates.
21
+
22
+ Example
23
+ -------
24
+
25
+ So, in your views you will create some new templates with something (can be
26
+ anything including nothing) between the template name and the first part of the
27
+ extension. So you might have the following files for the products/index action:
28
+
29
+ app/views/products/index.html.erb
30
+ app/views/products/index_alt.html.erb
31
+ app/views/products/index_new.html.erb
32
+
33
+ Then all you need to do is tell your controller to rotate for that action:
34
+
35
+ ### app/controllers/products_controller.rb
36
+ class ProductsController < ApplicationController
37
+ guerrilla_rotate :index, :show
38
+
39
+ # etc..
40
+
41
+ end
42
+
43
+ NB: guerrilla_rotate is also aliased as guerilla_rotate for the alternative
44
+ spelling and typos.
45
+
46
+ Copyright &copy; 2009 Jason King, released under the MIT license
@@ -0,0 +1,48 @@
1
+ module ActionController
2
+ class Base
3
+ cattr_accessor :guerrilla_paths
4
+ class << self
5
+ def guerrilla_rotate( *actions )
6
+ @@guerrilla_paths = {}
7
+ actions.each do |a|
8
+ catch (:next_path) do
9
+ view_paths.each do |vp|
10
+ Dir.chdir(vp) do
11
+ gpath = _gr_gpath(controller_name, a)
12
+ guerrilla_paths[gpath] = Dir.glob(gpath + '*') and
13
+ throw :next_path
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ alias_method :guerilla_rotate, :guerrilla_rotate
20
+ end
21
+
22
+ protected
23
+ def render_for_file_with_guerrilla_rotate( template_path, *others )
24
+ gpath = _gr_gpath(controller_name, action_name)
25
+ if guerrilla_paths.has_key?(gpath)
26
+ ga = guerrilla_paths[gpath]
27
+ session[:guerrilla_index] ||= {}
28
+ template_path = ga[ session[:guerrilla_index][gpath] ||= rand(ga.size)]
29
+ adjusted_action = template_path[%r{[^/]+(?=\.#{@template.template_format}\.)}]
30
+ if defined? Rubaidh::GoogleAnalytics
31
+ Rubaidh::GoogleAnalytics.override_trackpageview =
32
+ url_for(
33
+ :controller => controller_name,
34
+ :action => adjusted_action,
35
+ :only_path => true)
36
+ end
37
+ end
38
+ render_for_file_without_guerrilla_rotate( template_path, *others )
39
+ end
40
+ alias_method_chain :render_for_file, :guerrilla_rotate
41
+
42
+ private
43
+ def self._gr_gpath(c,a)
44
+ File.join(c.to_s, a.to_s)
45
+ end
46
+ def _gr_gpath(*p); self.class._gr_gpath(*p); end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guerrilla_rotate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason King
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-16 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: |
17
+ GuerrillaRotate
18
+ ==============
19
+
20
+ This plugin lets you have multiple view pages for the one action, so that you
21
+ can rotate through different views in order to test which one is the most
22
+ effective. This is known as A/B testing, split testing or side-by-side
23
+ testing.
24
+
25
+ It will automatically switch between the different views for different web
26
+ requests (uses .rand so is pseudo random, not round-robin or anything). The
27
+ particular view is sticky for a (rails) session, so that once that view has been
28
+ chosen for that visitor they will see the same, consistent view each time.
29
+
30
+ It integrates automagically into
31
+ [Rubaidh::GoogleAnalytics](http://github.com/rubaidh/google_analytics) by
32
+ setting the override_trackpageview to the name of the unique view file (instead
33
+ of the action-based URL) so you can track it easily in Google Analytics.
34
+
35
+ Without that you'll want to track it by putting different tracking codes in each
36
+ of your view templates.
37
+
38
+ Example
39
+ -------
40
+
41
+ So, in your views you will create some new templates with something (can be
42
+ anything including nothing) between the template name and the first part of the
43
+ extension. So you might have the following files for the products/index action:
44
+
45
+ app/views/products/index.html.erb
46
+ app/views/products/index_alt.html.erb
47
+ app/views/products/index_new.html.erb
48
+
49
+ Then all you need to do is tell your controller to rotate for that action:
50
+
51
+ ### app/controllers/products_controller.rb
52
+ class ProductsController < ApplicationController
53
+ guerrilla_rotate :index, :show
54
+
55
+ # etc..
56
+
57
+ end
58
+
59
+ NB: guerrilla_rotate is also aliased as guerilla_rotate for the alternative
60
+ spelling and typos.
61
+
62
+ Copyright &copy; 2009 Jason King, released under the MIT license
63
+
64
+ email: jk@handle.it
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - README.markdown
71
+ - LICENSE
72
+ files:
73
+ - README.markdown
74
+ - LICENSE
75
+ - lib/guerrilla_rotate.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/JasonKing/guerrilla_rotate
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --inline-source
83
+ - --charset=UTF-8
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ version:
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ version:
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.3.5
102
+ signing_key:
103
+ specification_version: 2
104
+ summary: A/B Testing made simple
105
+ test_files: []
106
+