ratel 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A/B Testing on Rails
4
4
 
5
+ Let's enjoy UX-driven development!
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -18,10 +20,12 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ 1. Define the block to switch the multiple patterns (`screen_changes` method)
24
+ 2. Define the conversion (`screen_conversion` method)
22
25
 
23
26
  ### A/B Testing
24
27
  Pattern A 50% / Pattern B 30% / Original 20%
28
+
25
29
  <% screen_changes at: :cassette, to: { a: 50, b: 30 }, with: :reset do |g| %>
26
30
  <dl>
27
31
  <dt>Selected Group</dt>
@@ -41,11 +45,4 @@ Pattern A 50% / Pattern B 30% / Original 20%
41
45
  ## LICENSE
42
46
  (The MIT License)
43
47
 
44
- Copyright © 2013 yulii
45
-
46
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
47
-
48
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
49
-
50
- THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51
-
48
+ Copyright © 2013 yulii. See LICENSE.txt for further details.
@@ -6,3 +6,10 @@
6
6
  </dl>
7
7
  <a href="javascript: <%= screen_conversion :cassette, :click, g %>">Conversion!</a>
8
8
  <% end %>
9
+ <% screen_changes at: :list, to: { a: 30, b: 30, c: 30 }, with: :reset do |g| %>
10
+ <dl>
11
+ <dt>Selected Group</dt>
12
+ <dd><%= g %></dd>
13
+ </dl>
14
+ <a href="javascript: <%= screen_conversion :list, :click, g %>">Conversion!</a>
15
+ <% end %>
data/lib/ratel/config.rb CHANGED
@@ -15,6 +15,7 @@ module Ratel
15
15
 
16
16
  class Configuration #:nodoc:
17
17
  include ActiveSupport::Configurable
18
+ config_accessor :screen_key
18
19
  config_accessor :tracking
19
20
 
20
21
  def param_name
@@ -28,6 +29,7 @@ module Ratel
28
29
  end
29
30
 
30
31
  configure do |config|
31
- config.tracking = :google_analytics
32
+ config.screen_key = :_screen_key_
33
+ config.tracking = :google_analytics
32
34
  end
33
35
  end
@@ -3,25 +3,22 @@ module Ratel
3
3
 
4
4
  def screen_changes *args, &block
5
5
  options = args.extract_options!
6
+ key = :"#{Ratel.config.screen_key}#{options[:at]}"
6
7
 
7
- s = :_screen_ticket
8
-
9
- session[s] ||= {}
10
- session[s] = {} if options[:with] == :reset
11
-
12
- name = options[:at]
13
- unless session[s].key? name
8
+ if options[:with] == :reset or cookies[key].nil?
9
+ selected = '_default'
14
10
  bar = 0
15
11
  num = Time.now.usec % 100
16
12
  options[:to].each do |k,v|
17
13
  bar += v
18
14
  if num < bar
19
- session[s][name] = "_#{k}"
15
+ selected = "_#{k}"
20
16
  break
21
17
  end
22
18
  end
19
+ cookies.permanent.signed[key] = selected
23
20
  end
24
- block.call session[s][name] || ''
21
+ block.call cookies.signed[key]
25
22
  end
26
23
 
27
24
  def screen_conversion category, action, label
@@ -7,6 +7,8 @@ module Ratel
7
7
  case Ratel.config.tracking
8
8
  when :google_analytics
9
9
  self.extend Ratel::Tracking::GoogleAnalytics
10
+ else
11
+ raise NotImplementedError, "invalid Ratel.config.tracking"
10
12
  end
11
13
  _push category, action, label
12
14
  end
data/lib/ratel/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ratel
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/ratel.rb CHANGED
@@ -4,8 +4,13 @@ module Ratel
4
4
  end
5
5
 
6
6
  require 'ratel/config'
7
- require 'ratel/helper/action_view_extension.rb'
8
- require 'ratel/tracking'
7
+
8
+ # Helper
9
+ require 'ratel/helper/action_view_extension'
10
+
11
+ # Tracking
12
+ require 'ratel/tracking/event'
13
+ require 'ratel/tracking/google_analytics'
9
14
 
10
15
  if defined? Rails
11
16
  require 'ratel/engine'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -47,7 +47,6 @@ files:
47
47
  - lib/ratel/config.rb
48
48
  - lib/ratel/engine.rb
49
49
  - lib/ratel/helper/action_view_extension.rb
50
- - lib/ratel/tracking.rb
51
50
  - lib/ratel/tracking/event.rb
52
51
  - lib/ratel/tracking/google_analytics.rb
53
52
  - lib/ratel/version.rb
@@ -1,2 +0,0 @@
1
- require 'ratel/tracking/event'
2
- require 'ratel/tracking/google_analytics'