bandit 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -63,6 +63,21 @@ To see a dashboard with relevant information, go to:
63
63
 
64
64
  http://<yourhost>/bandit
65
65
 
66
+ = User Tracking
67
+ There are a few different ways that users/conversions can be tracked. Instead of calling bandit_choose and bandit_convert! in your code, you may alternatively use one of the following method combinations:
68
+
69
+ bandit_simple_choose/bandit_simple_convert! (no cookies involved, same as raw impressions)
70
+ bandit_session_choose/bandit_session_convert! (session cookie, same as bandit_choose with a fix)
71
+ bandit_sticky_choose/bandit_sticky_convert! (persistent cookies)
72
+
73
+ bandit_sticky_convert! creates a _converted cookie which stops additional conversions from being counted. For example, if you are collecting email addresses, a user may enter their email address more than once, but you may want to count all these attempts as one conversion.
74
+
75
+ You may also use the bandit_sticky_choose/bandit_session_convert! combination if you wish to use persistent cookies but allow each user to convert multiple times. This way visitors are always presented with the same alternative until they convert, at which point they are presented with another and so on.
76
+
77
+ Finally, if you use bandit_simple_convert!, please remember the second argument (alternative) is not optional, as we have no cookie to read from.
78
+
79
+ The default bandit_choose/bandit_convert methods use the session based choose/convert.
80
+
66
81
  = Tests
67
82
  To run tests:
68
83
 
@@ -25,8 +25,8 @@ module Bandit
25
25
  alt = default
26
26
  else
27
27
  alt = Bandit.player.choose_alternative(self)
28
+ @storage.incr_participants(self, alt)
28
29
  end
29
- @storage.incr_participants(self, alt)
30
30
  alt
31
31
  end
32
32
 
@@ -3,32 +3,42 @@ require 'active_support/concern'
3
3
  module Bandit
4
4
  module ControllerConcerns
5
5
  extend ActiveSupport::Concern
6
-
6
+
7
7
  module ClassMethods
8
-
9
8
  end
10
9
 
11
10
  module InstanceMethods
11
+ # default convert is a session based conversion
12
12
  def bandit_convert!(exp, alt=nil, count=1)
13
+ bandit_session_convert!(exp, alt, count)
14
+ end
15
+
16
+ # look mum, no cookies
17
+ def bandit_simple_convert!(exp, alt, count=1)
18
+ Bandit.get_experiment(exp).convert!(alt, count)
19
+ end
20
+
21
+ # expects a session cookie, deletes it, will convert again
22
+ def bandit_session_convert!(exp, alt=nil, count=1)
13
23
  cookiename = "bandit_#{exp}".intern
24
+ cookiename_converted = "bandit_#{exp}_converted".intern
14
25
  alt ||= cookies.signed[cookiename]
15
- unless alt.nil?
26
+ unless alt.nil? or cookies.signed[cookiename_converted]
16
27
  Bandit.get_experiment(exp).convert!(alt, count)
17
- # delete cookie so we don't double track
18
28
  cookies.delete(cookiename)
19
29
  end
20
30
  end
21
31
 
22
- def bandit_choose(exp)
23
- name = "bandit_#{exp}".intern
24
-
25
- # choose url param with preference
26
- value = params[name].nil? ? cookies.signed[name] : params[name]
27
-
28
- # choose with default, and set cookie
29
- cookies.signed[name] = Bandit.get_experiment(exp).choose(value)
32
+ # creates a _converted cookie, prevents multiple conversions
33
+ def bandit_sticky_convert!(exp, alt=nil, count=1)
34
+ cookiename = "bandit_#{exp}".intern
35
+ cookiename_converted = "bandit_#{exp}_converted".intern
36
+ alt ||= cookies.signed[cookiename]
37
+ unless alt.nil? or cookies.signed[cookiename_converted]
38
+ cookies.permanent.signed[cookiename_converted] = "true"
39
+ Bandit.get_experiment(exp).convert!(alt, count)
40
+ end
30
41
  end
31
42
  end
32
-
33
43
  end
34
44
  end
@@ -3,22 +3,44 @@ require 'active_support/concern'
3
3
  module Bandit
4
4
  module ViewConcerns
5
5
  extend ActiveSupport::Concern
6
-
6
+
7
7
  module ClassMethods
8
-
9
8
  end
10
9
 
11
10
  module InstanceMethods
11
+ # default choose is a session based choice
12
12
  def bandit_choose(exp)
13
- name = "bandit_#{exp}".intern
13
+ bandit_session_choose(exp)
14
+ end
14
15
 
16
+ # always choose something new and increase the participant count
17
+ def bandit_simple_choose(exp)
18
+ Bandit.get_experiment(exp).choose(nil)
19
+ end
20
+
21
+ # stick to one alternative for the entire browser session
22
+ def bandit_session_choose(exp)
23
+ name = "bandit_#{exp}".intern
15
24
  # choose url param with preference
16
25
  value = params[name].nil? ? cookies.signed[name] : params[name]
17
-
18
26
  # choose with default, and set cookie
19
27
  cookies.signed[name] = Bandit.get_experiment(exp).choose(value)
20
28
  end
21
- end
22
29
 
30
+ # stick to one alternative until user deletes cookies or changes browser
31
+ def bandit_sticky_choose(exp)
32
+ name = "bandit_#{exp}".intern
33
+ # choose url param with preference
34
+ value = params[name].nil? ? cookies.signed[name] : params[name]
35
+ # sticky choice may outlast a given alternative
36
+ alternative = if Bandit.get_experiment(exp).alternatives.include?(value)
37
+ value
38
+ else
39
+ Bandit.get_experiment(exp).choose(value)
40
+ end
41
+ # re-set cookie
42
+ cookies.permanent.signed[name] = alternative
43
+ end
44
+ end
23
45
  end
24
46
  end
@@ -1,3 +1,3 @@
1
1
  module Bandit
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bandit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Muller
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-09 00:00:00 Z
18
+ date: 2012-05-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails