mountain-goat 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,10 @@ module MetricTracking
36
36
  end
37
37
 
38
38
  def mv(metric_type, convert_type, default, opts = {}, opt = nil)
39
+ return get_metric_variant(metric_type, convert_type, default, opts, opt)[:value]
40
+ end
41
+
42
+ def mv_detailed(metric_type, convert_type, default, opts = {}, opt = nil)
39
43
  return get_metric_variant(metric_type, convert_type, default, opts, opt)
40
44
  end
41
45
 
@@ -46,6 +50,8 @@ module MetricTracking
46
50
 
47
51
  def record_conversion(convert_type, options = {})
48
52
 
53
+ metrics = {} #for user-defined metrics
54
+
49
55
  #We want some system for easy default parameter setting
50
56
  if options.include?(:refs) && options[:refs]
51
57
  options = options.merge( :ref_domain => session[:ref_domain], :ref_flyer => session[:ref_flyer], :ref_user => session[:ref_user] )
@@ -68,6 +74,13 @@ module MetricTracking
68
74
  options.delete(:invitees)
69
75
  end
70
76
 
77
+ options.each do |k, v|
78
+ if k.to_s =~ /^metric_(\w+)$/i
79
+ options.delete k
80
+ metrics.push $1, v
81
+ end
82
+ end
83
+
71
84
  logger.warn "Recording conversion #{convert_type.to_s} with options #{options.inspect}"
72
85
 
73
86
  convert = Convert.first( :conditions => { :convert_type => convert_type.to_s } )
@@ -79,6 +92,25 @@ module MetricTracking
79
92
  #we need to see what meta information we should fill based on the conversion type
80
93
  Rally.create!( { :convert_id => convert.id } ).set_meta_data(options)
81
94
 
95
+ #User-defined metric tallies
96
+ metric.each do |metric_title, variant_id|
97
+ m = Metric.find_by_title(metric_title)
98
+ if m.nil?
99
+ logger.warn "Missing user-defined metric #{metric}"
100
+ next
101
+ end
102
+
103
+ v = m.metric_variants.first( :conditions => { :id => variant_id } ) #make sure everything matches up
104
+
105
+ if v.nil?
106
+ logger.warn "Variant #{variant_id} not in metric variants for #{m.title}"
107
+ next
108
+ end
109
+
110
+ logger.warn "Tallying conversion #{convert.name} for #{m.title} - #{v.name} (#{v.value} - #{v.id})"
111
+ v.tally_convert
112
+ end
113
+
82
114
  if defined?(cookies)
83
115
  #we just converted, let's tally each of our metrics (from cookies)
84
116
  convert.metrics.each do |metric|
@@ -115,6 +147,7 @@ module MetricTracking
115
147
 
116
148
  private
117
149
 
150
+ #returns a map { :value => value, :variant_id => id }
118
151
  def get_metric_variant(metric_type, convert_type, default, opts = {}, opt = nil)
119
152
  metric_sym = "metric_#{metric_type}#{ opt.nil? ? "" : '_' + opt.to_s }".to_sym
120
153
  metric_variant_sym = "metric_#{metric_type}_variant".to_sym
@@ -132,7 +165,7 @@ module MetricTracking
132
165
  logger.warn "Serving metric #{metric_type} #{ opt.nil? ? "" : opt.to_s } without finding / tallying variant."
133
166
  end
134
167
 
135
- return cookies[metric_sym] #it's the best we can do
168
+ return { :value => cookies[metric_sym], :variant_id => cookies[metric_variant_sym] } #it's the best we can do
136
169
  else
137
170
  #we don't have the cookie, let's find a value to set
138
171
  metric, convert = get_metric_convert( metric_type, convert_type, false )
@@ -159,7 +192,7 @@ module MetricTracking
159
192
  cookies[metric_variant_sym] = { :value => metric_variant.id } #, :domain => WILD_DOMAIN
160
193
  end
161
194
 
162
- return value
195
+ return { :value => value, :variant_id => metric_variant.id }
163
196
  end
164
197
  end
165
198
 
@@ -235,6 +268,10 @@ module MetricTracking
235
268
  @controller.send(:mv, *args, &block)
236
269
  end
237
270
 
271
+ def mv_detailed(*args, &block)
272
+ @controller.send(:mv_detailed, *args, &block)
273
+ end
274
+
238
275
  def sv(*args, &block)
239
276
  @controller.send(:sv, *args, &block)
240
277
  end
@@ -1,3 +1,3 @@
1
1
  class MountainGoat
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -0,0 +1,49 @@
1
+
2
+
3
+ <div id="container-main" class="mt-converts">
4
+ <div class="mountain-goat-panel centered">
5
+
6
+ <h1>Conversion Goals</h1>
7
+
8
+ <div class="conversions">
9
+ <div class="explanation">
10
+ <span class="inner">
11
+ Below are a list of conversion goals. Each goal has a set of metrics designed to achieve that goal. For each metric, there is a list of variants, each coupled with its conversation rate.</span>
12
+ </span>
13
+ </div>
14
+
15
+ <div class="converts">
16
+ <% @converts.each do |convert| %>
17
+ <h2><a href="<%= mountain_goat_convert_url :id => convert.id %>"><%=h convert.name %></a></h2>
18
+ <% convert.metrics.each do |metric| %>
19
+ <div class="metric-category">
20
+ <span class="metric"><a href="<%= mountain_goat_metric_url :id => metric.id %>"><%= metric.title %></a></span>
21
+ <% if metric.metric_variants.count == 0 %>
22
+ <span class="none">No metric variants [<a href="<%= new_mountain_goat_metric_mountain_goat_metric_variant_url :mountain_goat_metric_id => metric.id %>">Add one</a>]</span>
23
+ <% else %>
24
+ <% metric.metric_variants.each do |mv| %>
25
+ <div class="item rate">
26
+ <span class="rate-holder">
27
+ <span class="title"><a href="<%= mountain_goat_metric_variant_url mv %>"><%=h mv.name %></a></span>
28
+ <span class="rates" style="width:<%= number_to_percentage(mv.conversion_rate, :precision => 0) %>"></span>
29
+ </span>
30
+
31
+ <span class="percent-holder">
32
+ <span class="val"><%= number_to_percentage(mv.conversion_rate, :precision => 0) %></span>
33
+ (<span class="conversions"><%= mv.conversions %></span> /
34
+ <span class="served"><%= mv.served %></span>)
35
+ </span>
36
+ </div>
37
+ <% end %>
38
+ <% end %>
39
+ </div>
40
+ <% end %>
41
+ <% end %>
42
+ </div>
43
+ </div>
44
+
45
+ <div class="actions">
46
+ <a class="button" href="<%= new_mountain_goat_convert_url %>">New Goal</a>
47
+ </div>
48
+ </div>
49
+ </div>
Binary file
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ class Ocelot::OcelotConvertsControllerTest < ActionController::TestCase
4
+ test "should get index" do
5
+ get :index, {}, admin_user
6
+ assert_response :success
7
+ assert_not_nil assigns(:converts)
8
+ end
9
+
10
+ test "should get new" do
11
+ get :new, {}, admin_user
12
+ assert_response :success
13
+ end
14
+
15
+ test "should create convert" do
16
+ assert_difference('Convert.count') do
17
+ post :create, { :convert => { :name => 'my next convert', :convert_type => 'convert_type_3' } }, admin_user
18
+ end
19
+
20
+ assert_redirected_to ocelot_ocelot_convert_url assigns(:convert)
21
+ end
22
+
23
+ test "should show convert" do
24
+ get :show, { :id => converts(:one).to_param }, admin_user
25
+ assert_response :success
26
+ end
27
+
28
+ test "should get edit" do
29
+ get :edit, { :id => converts(:one).to_param }, admin_user
30
+ assert_response :success
31
+ end
32
+
33
+ test "should update convert" do
34
+ put :update, { :id => converts(:one).to_param, :convert => { } }, admin_user
35
+ assert_redirected_to ocelot_ocelot_convert_url assigns(:convert)
36
+ end
37
+
38
+ test "should destroy convert" do
39
+ assert_difference('Convert.count', -1) do
40
+ delete :destroy, { :id => converts(:one).to_param }, admin_user
41
+ end
42
+
43
+ assert_redirected_to ocelot_ocelot_converts_url
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ class Ocelot::OcelotMetricVariantsControllerTest < ActionController::TestCase
4
+ test "should get index" do
5
+ get :index, {}, admin_user
6
+ assert_response :success
7
+ assert_not_nil assigns(:metric_variants)
8
+ end
9
+
10
+ test "should get new" do
11
+ get :new, { :ocelot_metric_id => metrics(:two).id }, admin_user
12
+ assert_response :success
13
+ end
14
+
15
+ test "should create metric_variant" do
16
+ assert_difference('MetricVariant.count') do
17
+ post :create, { :metric_variant => { :metric_id => metrics(:two).id, :name => 'var', :value => 'cool' } }, admin_user
18
+ end
19
+
20
+ assert_redirected_to ocelot_ocelot_metric_url metrics(:two)
21
+ end
22
+
23
+ test "should show metric_variant" do
24
+ get :show, { :id => metric_variants(:one).to_param }, admin_user
25
+ assert_response :success
26
+ end
27
+
28
+ test "should get edit" do
29
+ get :edit, { :id => metric_variants(:one).to_param }, admin_user
30
+ assert_response :success
31
+ end
32
+
33
+ test "should update metric_variant" do
34
+ put :update, { :id => metric_variants(:one).to_param, :metric_variant => { } }, admin_user
35
+ assert_redirected_to ocelot_ocelot_metric_url assigns(:metric_variant).metric
36
+ end
37
+
38
+ test "should destroy metric_variant" do
39
+ assert_difference('MetricVariant.count', -1) do
40
+ delete :destroy, { :id => metric_variants(:one).to_param }, admin_user
41
+ end
42
+
43
+ assert_redirected_to ocelot_ocelot_metric_variants_url
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ class Ocelot::OcelotMetricsControllerTest < ActionController::TestCase
4
+ test "should get index" do
5
+ get :index, {}, admin_user
6
+ assert_response :success
7
+ assert_not_nil assigns(:metrics)
8
+ end
9
+
10
+ test "should get new" do
11
+ get :new, { :ocelot_convert_id => converts(:one).id }, admin_user
12
+ assert_response :success
13
+ end
14
+
15
+ test "should create metric" do
16
+ assert_difference('Metric.count') do
17
+ post :create, { :metric => { :metric_type => 'geoff', :title => 'hayes', :convert_id => converts(:two).id } }, admin_user
18
+ end
19
+
20
+ assert_redirected_to ocelot_ocelot_metric_url :id => assigns(:metric).id
21
+ end
22
+
23
+ test "should show metric" do
24
+ get :show, { :id => metrics(:one).to_param }, admin_user
25
+ assert_response :success
26
+ end
27
+
28
+ test "should get edit" do
29
+ get :edit, { :id => metrics(:one).to_param }, admin_user
30
+ assert_response :success
31
+ end
32
+
33
+ test "should update metric" do
34
+ put :update, { :id => metrics(:one).to_param, :metric => { } }, admin_user
35
+ assert_redirected_to ocelot_ocelot_metric_url :id => assigns(:metric).id
36
+ end
37
+
38
+ test "should destroy metric" do
39
+ assert_difference('Metric.count', -1) do
40
+ delete :destroy, { :id => metrics(:one).to_param }, admin_user
41
+ end
42
+
43
+ assert_redirected_to ocelot_ocelot_metrics_url
44
+ end
45
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class Ocelot::OcelotRalliesControllerTest < ActionController::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mountain-goat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 10
10
- version: 0.0.10
9
+ - 11
10
+ version: 0.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Geoffrey Hayes
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-07-11 00:00:00 -05:00
19
+ date: 2011-07-12 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -101,6 +101,7 @@ files:
101
101
  - lib/mountain-goat/views/mountain_goat/mountain_goat/.tmp_login.html.erb.27219~
102
102
  - lib/mountain-goat/views/mountain_goat/mountain_goat/login.html.erb
103
103
  - lib/mountain-goat/views/mountain_goat/mountain_goat_converts/.tmp_index.html.erb.22467~
104
+ - lib/mountain-goat/views/mountain_goat/mountain_goat_converts/.tmp_index.html.erb.64368~
104
105
  - lib/mountain-goat/views/mountain_goat/mountain_goat_converts/_convert_form.html.erb
105
106
  - lib/mountain-goat/views/mountain_goat/mountain_goat_converts/_convert_meta_type_form.html.erb
106
107
  - lib/mountain-goat/views/mountain_goat/mountain_goat_converts/edit.html.erb
@@ -120,6 +121,7 @@ files:
120
121
  - migrations/20090716093747_create_metric_tracking_tables.rb
121
122
  - migrations/20110710193220_mountain_goat_add_mg_options_table.rb
122
123
  - mountain-goat-0.0.1.gem
124
+ - mountain-goat-0.0.10.gem
123
125
  - mountain-goat-0.0.2.gem
124
126
  - mountain-goat-0.0.3.gem
125
127
  - mountain-goat-0.0.4.gem
@@ -128,6 +130,10 @@ files:
128
130
  - mountain-goat-0.0.8.gem
129
131
  - mountain-goat-0.0.9.gem
130
132
  - mountain-goat.gemspec
133
+ - test/ocelot_converts_controller_test.rb
134
+ - test/ocelot_metric_variants_controller_test.rb
135
+ - test/ocelot_metrics_controller_test.rb
136
+ - test/ocelot_rallies_controller_test.rb
131
137
  has_rdoc: true
132
138
  homepage: http://github.com/hayesgm/mountain_goat
133
139
  licenses: []