caboose-cms 0.3.22 → 0.3.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/controllers/caboose/ab_options_controller.rb +2 -2
- data/app/controllers/caboose/application_controller.rb +3 -39
- data/app/controllers/caboose/page_blocks_controller.rb +10 -0
- data/app/helpers/caboose/pages_helper.rb +3 -4
- data/app/models/caboose/ab_option.rb +2 -1
- data/app/models/caboose/ab_testing.rb +38 -0
- data/app/models/caboose/ab_value.rb +12 -0
- data/app/models/caboose/ab_variant.rb +5 -10
- data/app/models/caboose/core_plugin.rb +1 -4
- data/app/models/caboose/schema.rb +11 -4
- data/app/views/caboose/ab_variants/admin_edit.html.erb +3 -5
- data/app/views/caboose/pages/show.html.erb +6 -1
- data/lib/caboose/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjRhNDNkZjU2Mjg1Yjc5ODg2ZGJjYjk5YzBjOTg2NWIwMDI2NWRjNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDUzODg4YzcyZmRjMzdiMjE2N2U3NmM0MDRjYWIxZTUxNTdiZDI0Ng==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODhkMTgwZjkyYmJkMThmNjI2NTNkZDJjNjBiODk0ZWQxZWE3OGFiODRiZDVk
|
10
|
+
N2ZhNDBkMjM2MDRiOTQ4MjkxMGY0MDkxNDFkYTU0Y2U4ZjA1Y2M4MTgwMjhj
|
11
|
+
MGI3ZWQ1MjU1YmNjNWFmYmNkZjVmNzkzNWQ0ZmEyYjBkZGNkMjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTk2MTc5MTQyZGU2NzdlYzc1OWRlOGFkZTRmNzNlZjA5YzM3YmFmM2M0MDRh
|
14
|
+
Y2U0NmMyYzQzZjFhNWViMmJmMjY4NmIzZTQ2ZmI1N2I1MDJmYmQ3ODE3Njlm
|
15
|
+
OWYwN2Y2MWU3ZTc3YWY2MTE4ZjFlMzEwYWQ5ODE1OGY2NmIxNmE=
|
@@ -13,7 +13,9 @@ module Caboose
|
|
13
13
|
@page = Page.page_with_uri(request.fullpath)
|
14
14
|
|
15
15
|
session['use_redirect_urls'] = true if session['use_redirect_urls'].nil?
|
16
|
-
|
16
|
+
|
17
|
+
# Initialize AB Testing
|
18
|
+
AbTesting.init(request.session_options[:id])
|
17
19
|
|
18
20
|
@crumb_trail = Caboose::Page.crumb_trail(@page)
|
19
21
|
@subnav = {}
|
@@ -174,44 +176,6 @@ module Caboose
|
|
174
176
|
return "" if v.nil?
|
175
177
|
return v.val
|
176
178
|
end
|
177
|
-
|
178
|
-
#===========================================================================
|
179
|
-
# AB Testing
|
180
|
-
#===========================================================================
|
181
|
-
|
182
|
-
# Sets the ab_variants for the user's session
|
183
|
-
def assign_ab_variants
|
184
|
-
return if session['ab_variants']
|
185
|
-
|
186
|
-
h = {}
|
187
|
-
arr = []
|
188
|
-
AbVariant.find_each do |var|
|
189
|
-
next if var.ab_options.nil? || var.ab_options.count == 0
|
190
|
-
i = rand(var.ab_options.count)
|
191
|
-
h[var.analytics_name] = var.ab_options[i].text
|
192
|
-
arr << "#{var.analytics_name}=#{i+1}"
|
193
|
-
end
|
194
|
-
session['ab_variants'] = h
|
195
|
-
session['ab_variants_analytics_string'] = "|#{arr.join('|')}|"
|
196
|
-
end
|
197
|
-
|
198
|
-
# Get the variant option text for the given variant name.
|
199
|
-
def ab_option_for(analytics_name)
|
200
|
-
assign_ab_variants if session['ab_variants'].nil?
|
201
|
-
return session['ab_variants'][analytics_name] if !session['ab_variants'][analytics_name].nil?
|
202
|
-
|
203
|
-
# Otherwise, add the new variant to the session
|
204
|
-
var = AbVariant.find(:analytics_name => analytics_name).first
|
205
|
-
i = rand(var.ab_options.count)
|
206
|
-
session['ab_variants'][var.analytics_name] = var.ab_options[i].text
|
207
|
-
session['ab_variants_analytics_string'] << "#{var.analytics_name}=#{i+1}|"
|
208
|
-
end
|
209
|
-
|
210
|
-
# Gets the string to be sent to google analytics
|
211
|
-
def analytics_string
|
212
|
-
assign_ab_variants if session['ab_variants_analytics_string'].nil?
|
213
|
-
return "#{session['ab_variants_analytics_string']}"
|
214
|
-
end
|
215
179
|
|
216
180
|
end
|
217
181
|
end
|
@@ -33,6 +33,11 @@ module Caboose
|
|
33
33
|
return unless user_is_allowed('pages', 'edit')
|
34
34
|
b = PageBlock.find(params[:id])
|
35
35
|
bt = b.page_block_type
|
36
|
+
if bt.nil?
|
37
|
+
bt = PageBlockType.where(:name => 'richtext').first
|
38
|
+
b.page_block_type_id = bt.id
|
39
|
+
b.save
|
40
|
+
end
|
36
41
|
html = nil
|
37
42
|
|
38
43
|
if bt.use_render_function && bt.render_function
|
@@ -55,6 +60,11 @@ module Caboose
|
|
55
60
|
p = Page.find(params[:page_id])
|
56
61
|
blocks = p.page_blocks.collect do |b|
|
57
62
|
bt = b.page_block_type
|
63
|
+
if bt.nil?
|
64
|
+
bt = PageBlockType.where(:name => 'richtext').first
|
65
|
+
b.page_block_type_id = bt.id
|
66
|
+
b.save
|
67
|
+
end
|
58
68
|
html = nil
|
59
69
|
if bt.use_render_function && bt.render_function
|
60
70
|
html = b.render_from_function(params[:empty_text])
|
@@ -19,10 +19,9 @@ module Caboose
|
|
19
19
|
str << "</li>"
|
20
20
|
return str
|
21
21
|
end
|
22
|
-
|
23
|
-
def
|
24
|
-
|
25
|
-
return "var _gaq = _gaq || [];\n_gaq.push(['_setCustomVar', 1, 'caboose_ab_variants', #{Caboose.json(str)}]);"
|
22
|
+
|
23
|
+
def ab_testing_analytics_code
|
24
|
+
return "var _gaq = _gaq || [];\n_gaq.push(['_setCustomVar', 1, 'caboose_ab_variants', #{Caboose.json(AbTesting.analytics_string)}]);"
|
26
25
|
end
|
27
26
|
|
28
27
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Caboose
|
2
|
+
class AbTesting
|
3
|
+
|
4
|
+
@@session_id = nil
|
5
|
+
|
6
|
+
# Sets the ab_variants for the user's session
|
7
|
+
def self.init(session_id)
|
8
|
+
@@session_id = "#{session_id}"
|
9
|
+
AbVariant.all.each { |var| self.create_ab_value(var) }
|
10
|
+
end
|
11
|
+
|
12
|
+
# Ensure that an ab_value exists for the given session and variant
|
13
|
+
def self.create_ab_value(var)
|
14
|
+
if AbValue.where(:session_id => @@session_id, :ab_variant_id => var.id).exists?
|
15
|
+
return AbValue.where(:session_id => @@session_id, :ab_variant_id => var.id).first
|
16
|
+
end
|
17
|
+
return AbValue.create(:session_id => @@session_id, :ab_variant_id => var.id, :ab_option_id => var.random_option.id)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get this session's ab_value value for the variant with the given analytics name
|
21
|
+
def self.[](analytics_name)
|
22
|
+
return self.value_for_name(analytics_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.value_for_name(analytics_name)
|
26
|
+
return nil if !AbVariant.where(:analytics_name => analytics_name).exists?
|
27
|
+
var = AbVariant.where(:analytics_name => analytics_name).first
|
28
|
+
abv = self.create_ab_value(var)
|
29
|
+
return abv.ab_option.value
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get the analytics string
|
33
|
+
def self.analytics_string
|
34
|
+
arr = AbValue.where(:session_id => @@session_id).all.collect { |abv| abv.keyval }
|
35
|
+
return "|#{arr.join('|')}|"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Caboose::AbValue < ActiveRecord::Base
|
2
|
+
|
3
|
+
self.table_name = "ab_values"
|
4
|
+
belongs_to :ab_variant
|
5
|
+
belongs_to :ab_option
|
6
|
+
attr_accessible :session_id, :ab_variant_id, :ab_option_id
|
7
|
+
|
8
|
+
def keyval
|
9
|
+
return "#{ab_variant.analytics_name}=#{ab_option_id}"
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -6,17 +6,12 @@ class Caboose::AbVariant < ActiveRecord::Base
|
|
6
6
|
self.table_name = "ab_variants"
|
7
7
|
|
8
8
|
has_many :ab_options, :order => 'id', :dependent => :destroy
|
9
|
+
has_many :ab_values, :dependent => :destroy
|
9
10
|
attr_accessible :name, :analytics_name
|
10
|
-
|
11
|
-
def
|
12
|
-
return
|
13
|
-
|
14
|
-
return {text: opt.text, id: opt.id}
|
11
|
+
|
12
|
+
def random_option
|
13
|
+
return nil if self.ab_options.nil? || self.ab_options.count == 0
|
14
|
+
return self.ab_options.sample
|
15
15
|
end
|
16
16
|
|
17
|
-
#def random_option
|
18
|
-
# return nil self.ab_options.nil? || self.ab_options.count == 0
|
19
|
-
# return self.ab_options.sample
|
20
|
-
#end
|
21
|
-
|
22
17
|
end
|
@@ -39,10 +39,7 @@ class Caboose::CorePlugin < Caboose::CaboosePlugin
|
|
39
39
|
item['children'] << { 'id' => 'pages' , 'text' => 'Pages' , 'href' => '/admin/pages' , 'modal' => false } if user.is_allowed('pages' , 'view')
|
40
40
|
item['children'] << { 'id' => 'posts' , 'text' => 'Posts' , 'href' => '/admin/posts' , 'modal' => false } if user.is_allowed('posts' , 'view')
|
41
41
|
|
42
|
-
nav << item if item['children'].count > 0
|
43
|
-
if user.is_allowed('ab-variants','view')
|
44
|
-
nav << { 'id' => 'ab_variants', 'text' => 'AB Testing', 'href' => '/admin/ab-variants', 'modal' => false }
|
45
|
-
end
|
42
|
+
nav << item if item['children'].count > 0
|
46
43
|
return nav
|
47
44
|
end
|
48
45
|
|
@@ -12,7 +12,9 @@ class Caboose::Schema < Caboose::Utilities::Schema
|
|
12
12
|
def self.removed_columns
|
13
13
|
{
|
14
14
|
Caboose::PageBlock => [:block_type, :value, :name],
|
15
|
-
Caboose::PageBlockField => [:model_binder_options]
|
15
|
+
Caboose::PageBlockField => [:model_binder_options],
|
16
|
+
Caboose::AbValue => [:i, :text],
|
17
|
+
Caboose::AbOption => [:text]
|
16
18
|
}
|
17
19
|
end
|
18
20
|
|
@@ -147,9 +149,14 @@ class Caboose::Schema < Caboose::Utilities::Schema
|
|
147
149
|
[ :name , :string ],
|
148
150
|
[ :analytics_name , :string ],
|
149
151
|
],
|
150
|
-
Caboose::AbOption => [
|
151
|
-
[ :
|
152
|
-
[ :
|
152
|
+
Caboose::AbOption => [
|
153
|
+
[ :ab_variant_id , :integer ],
|
154
|
+
[ :value , :string ]
|
155
|
+
],
|
156
|
+
Caboose::AbValue => [
|
157
|
+
[ :session_id , :string ],
|
158
|
+
[ :ab_variant_id , :integer ],
|
159
|
+
[ :ab_option_id , :integer ]
|
153
160
|
],
|
154
161
|
Caboose::DatabaseSession => [
|
155
162
|
[ :session_id , :string , :null => false ],
|
@@ -9,7 +9,7 @@
|
|
9
9
|
<table>
|
10
10
|
<% @variant.ab_options.each do |opt| %>
|
11
11
|
<tr>
|
12
|
-
<td><div id="aboption_<%= opt.id %>
|
12
|
+
<td><div id="aboption_<%= opt.id %>_value"></div></td>
|
13
13
|
<td><input type='button' value='Delete' onclick="delete_option(<%= opt.id %>);" /></td>
|
14
14
|
</tr>
|
15
15
|
<% end %>
|
@@ -55,9 +55,7 @@ function add_option() {
|
|
55
55
|
$.ajax({
|
56
56
|
url: '/admin/ab-variants/<%= @variant.id %>/options',
|
57
57
|
type: 'post',
|
58
|
-
data: {
|
59
|
-
text: ""
|
60
|
-
},
|
58
|
+
data: { value: "" },
|
61
59
|
success: function(resp) {
|
62
60
|
if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
|
63
61
|
if (resp.redirect) window.location.reload(true);
|
@@ -87,7 +85,7 @@ $(document).ready(function() {
|
|
87
85
|
update_url: '/admin/ab-options/<%= opt.id %>',
|
88
86
|
authenticity_token: '<%= form_authenticity_token %>',
|
89
87
|
attributes: [
|
90
|
-
{ name: '
|
88
|
+
{ name: 'value', nice_name: 'Option <%= i %>', type: 'text', value: <%= raw Caboose.json(opt.value) %> , width: 800 }
|
91
89
|
]
|
92
90
|
});
|
93
91
|
<% i = i + 1 %>
|
@@ -15,7 +15,12 @@
|
|
15
15
|
|
16
16
|
<% content_for :page_title do %><%= raw @page.title %><% end %>
|
17
17
|
<% content_for :page_content do %><% @page.blocks.each do |b|
|
18
|
-
bt = b.page_block_type
|
18
|
+
bt = b.page_block_type
|
19
|
+
if bt.nil?
|
20
|
+
bt = PageBlockType.where(:name => 'heading').first
|
21
|
+
b.page_block_type_id = bt.id
|
22
|
+
b.save
|
23
|
+
end
|
19
24
|
if bt.use_render_function && bt.render_function
|
20
25
|
%><%= raw b.render_from_function(params[:empty_text]) %><%
|
21
26
|
else
|
data/lib/caboose/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caboose-cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Barry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -189,6 +189,8 @@ files:
|
|
189
189
|
- app/helpers/caboose/permissions_helper.rb
|
190
190
|
- app/helpers/caboose/products_helper.rb
|
191
191
|
- app/models/caboose/ab_option.rb
|
192
|
+
- app/models/caboose/ab_testing.rb
|
193
|
+
- app/models/caboose/ab_value.rb
|
192
194
|
- app/models/caboose/ab_variant.rb
|
193
195
|
- app/models/caboose/approval_request.rb
|
194
196
|
- app/models/caboose/asset.rb
|