ratel 0.0.3 → 0.0.4

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.
data/README.md CHANGED
@@ -4,6 +4,9 @@ A/B Testing on Rails
4
4
 
5
5
  Let's enjoy UX-driven development!
6
6
 
7
+ ## Supported
8
+ - Google Analytics
9
+
7
10
  ## Installation
8
11
 
9
12
  Add this line to your application's Gemfile:
@@ -34,6 +37,30 @@ Pattern A 50% / Pattern B 30% / Original 20%
34
37
  <a href="javascript: <%= screen_conversion :cassette, :click, g %>">Conversion!</a>
35
38
  <% end %>
36
39
 
40
+ ## Advanced Tips
41
+ ### Create your own Tracking System
42
+ Define the tracking class (`Ratel::Tracking::MyTrackingSystem`) and `push` method.
43
+
44
+ $ vi lib/tracking/my_tracking_system.rb
45
+ module Ratel
46
+ module Tracking
47
+ module MyTrackingSystem
48
+
49
+ # `args` equals screen_conversion's args
50
+ def push *args
51
+ # options = args.extract_options!
52
+ # ...
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+ Rails Config
59
+ Ratel.configure do |config|
60
+ config.tracking = :my_tracking_system # snake_case symbol or string
61
+ end
62
+ Execute your method (`Ratel::Tracking::MyTrackingSysmtem.push`) when `screen_conversion` method called.
63
+
37
64
  ## Contributing
38
65
 
39
66
  1. Fork it
@@ -0,0 +1,17 @@
1
+ <h1>What's the BEST color for high conversions?</h1>
2
+ <% screen_changes at: :button, to: { red: 20, pink: 20, orange: 20, green: 20, blue: 20 }, with: :reset do |g| %>
3
+ <% case g %>
4
+ <% when :red %>
5
+ <a href="/done" onclick="<%= screen_conversion :button, :click, g %>" class="<%= g %>">Conversion!</a>
6
+ <% when :pink %>
7
+ <a href="/done" onclick="<%= screen_conversion :button, :click, g %>" class="<%= g %>">Conversion!</a>
8
+ <% when :orange %>
9
+ <a href="/done" onclick="<%= screen_conversion :button, :click, g %>" class="<%= g %>">Conversion!</a>
10
+ <% when :green %>
11
+ <a href="/done" onclick="<%= screen_conversion :button, :click, g %>" class="<%= g %>">Conversion!</a>
12
+ <% when :blue %>
13
+ <a href="/done" onclick="<%= screen_conversion :button, :click, g %>" class="<%= g %>">Conversion!</a>
14
+ <% else %>
15
+ <a href="/done" onclick="<%= screen_conversion :button, :click, g %>" class="<%= g %>">Conversion!</a>
16
+ <% end %>
17
+ <% end %>
data/lib/ratel.rb CHANGED
@@ -9,7 +9,6 @@ require 'ratel/config'
9
9
  require 'ratel/helper/action_view_extension'
10
10
 
11
11
  # Tracking
12
- require 'ratel/tracking/event'
13
12
  require 'ratel/tracking/google_analytics'
14
13
 
15
14
  if defined? Rails
data/lib/ratel/engine.rb CHANGED
@@ -1,7 +1,34 @@
1
1
  module Ratel
2
2
  class Engine < ::Rails::Engine
3
3
  initializer :ratel do |app|
4
- ActionView::Base.send :include, Ratel::ActionViewExtension
4
+ Ratel::Initializer.execute
5
+ end
6
+ end
7
+
8
+ class Initializer
9
+ class << self
10
+ def execute
11
+ # include helper methods
12
+ ActionView::Base.send :include, Ratel::ActionViewExtension
13
+
14
+ define_tracking_event
15
+ end
16
+
17
+
18
+ private
19
+
20
+ def define_tracking_event
21
+ # auot-define Ratel::Tracking::Event class
22
+ Ratel::Tracking.const_set :Event, Class.new unless Ratel::Tracking.const_defined? :Event
23
+ name = "#{Ratel.config.tracking}".camelize
24
+
25
+ return if Ratel::Tracking::Event.method_defined? :push
26
+ raise NotImplementedError, "#{name} is invalid. Specify correct Ratel.config.tracking." unless Ratel::Tracking.const_defined? name
27
+
28
+ # define method that pushes conversion events
29
+ Ratel::Tracking::Event.extend Ratel::Tracking.const_get name
30
+ end
31
+
5
32
  end
6
33
  end
7
34
  end
@@ -4,15 +4,17 @@ module Ratel
4
4
  def screen_changes *args, &block
5
5
  options = args.extract_options!
6
6
  key = :"#{Ratel.config.screen_key}#{options[:at]}"
7
-
7
+
8
+ ## TODO A/B テストの停止ロジック
9
+ # redis などのkey-value 対応 or 設定ファイルでの制御?
8
10
  if options[:with] == :reset or cookies[key].nil?
9
- selected = '_default'
11
+ selected = :default
10
12
  bar = 0
11
13
  num = Time.now.usec % 100
12
14
  options[:to].each do |k,v|
13
15
  bar += v
14
16
  if num < bar
15
- selected = "_#{k}"
17
+ selected = k
16
18
  break
17
19
  end
18
20
  end
@@ -22,6 +24,7 @@ module Ratel
22
24
  end
23
25
 
24
26
  def screen_conversion category, action, label
27
+ # Ratel::Tracking::Event class is auto-defined
25
28
  Ratel::Tracking::Event.push category, action, label
26
29
  end
27
30
 
@@ -2,8 +2,9 @@ module Ratel
2
2
  module Tracking
3
3
  module GoogleAnalytics
4
4
 
5
- def _push category, action, label, options = {}
6
- s = "_gaq.push(['_trackEvent', '#{category}', '#{action}', '#{label}'"
5
+ def push *args
6
+ options = args.extract_options!
7
+ s = "_gaq.push(['_trackEvent', '#{options[:category]||args[0]}', '#{options[:action]||args[1]}', '#{options[:label]||args[2]}'"
7
8
  s << ", #{options[:value]}" if options.key? :value
8
9
  s << ", #{options[:noninteraction]}" if options.key? :noninteraction
9
10
  s << "]);"
data/lib/ratel/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ratel
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -10,17 +10,22 @@ app.config.generators do |g|
10
10
  end
11
11
  app.initialize!
12
12
 
13
+ ACTIONS = [:index, :button]
14
+
13
15
  # routing
14
16
  app.routes.draw do
15
- get "/" =>"ratel#index" ,as: :index
17
+ ACTIONS.each do |e|
18
+ get "/#{e}" =>"ratel##{e}" ,as: e
19
+ end
16
20
  end
17
21
 
18
22
  # controllers
19
23
  class ApplicationController < ActionController::Base ; end
20
24
 
21
25
  class RatelController < ApplicationController
22
- def index
23
-
26
+ ACTIONS.each do |e|
27
+ define_method e do
28
+ end
24
29
  end
25
30
  end
26
31
 
@@ -0,0 +1,29 @@
1
+ # coding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ # auto-define class
5
+ describe Ratel::Initializer do
6
+
7
+ before do
8
+ Ratel.configure do |config|
9
+ config.tracking = tracking
10
+ end
11
+ end
12
+
13
+ context "implemented tracking system" do
14
+ let(:tracking) { :google_analytics }
15
+ before { Ratel::Initializer.execute }
16
+
17
+ it "expects to be called `push` method" do
18
+ expect(Ratel::Tracking::Event.methods.include? :push).to be_true
19
+ end
20
+ end
21
+
22
+ context "NOT implemented tracking system" do
23
+ let(:tracking) { :unknown }
24
+
25
+ it "expects to raise NotImplementedError" do
26
+ expect { Ratel::Initializer.execute }.to raise_error NotImplementedError
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ # coding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Ratel::ActionViewExtension do
5
+
6
+ before do
7
+ Ratel.configure do |config|
8
+ config.tracking = tracking
9
+ end
10
+ Ratel::Initializer.execute
11
+ end
12
+
13
+ let(:tracking) { :google_analytics }
14
+
15
+ before do
16
+ visit "/index"
17
+ end
18
+
19
+ subject { page }
20
+ it { should have_content "TEST" }
21
+ end
@@ -0,0 +1,26 @@
1
+ # coding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Ratel::Tracking::GoogleAnalytics do
5
+
6
+ let(:object) do
7
+ Class.new do
8
+ extend Ratel::Tracking::GoogleAnalytics
9
+ end
10
+ end
11
+
12
+ describe "conversion's method `push`" do
13
+ it "expects to be called" do
14
+ expect(object.methods.include? :push).to be_true
15
+ end
16
+
17
+ context "call `push` method" do
18
+ let(:result) { object.push category: "A/B Testing", action: "click", label: "button" }
19
+
20
+ it "expects to return same results" do
21
+ expect(object.push "A/B Testing", :click, :button).to eq(result)
22
+ end
23
+ end
24
+ end
25
+
26
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,5 +6,8 @@ require 'ratel'
6
6
  require 'capybara/rails'
7
7
  RSpec.configure do |config|
8
8
  config.mock_with :rspec
9
+ config.expect_with :rspec do |c|
10
+ c.syntax = :expect # disables `should`
11
+ end
9
12
  config.include Capybara::DSL
10
13
  end
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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-06 00:00:00.000000000 Z
12
+ date: 2013-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -41,18 +41,20 @@ files:
41
41
  - README.md
42
42
  - Rakefile
43
43
  - app/views/layouts/application.html.erb
44
+ - app/views/ratel/button.html.erb
44
45
  - app/views/ratel/index.html.erb
45
46
  - deploy_gem.sh
46
47
  - lib/ratel.rb
47
48
  - lib/ratel/config.rb
48
49
  - lib/ratel/engine.rb
49
50
  - lib/ratel/helper/action_view_extension.rb
50
- - lib/ratel/tracking/event.rb
51
51
  - lib/ratel/tracking/google_analytics.rb
52
52
  - lib/ratel/version.rb
53
53
  - ratel.gemspec
54
- - spec/helper/action_view_extension_spec.rb
55
54
  - spec/rails_spec_app.rb
55
+ - spec/ratel/engine_spec.rb
56
+ - spec/ratel/helper/action_view_extension_spec.rb
57
+ - spec/ratel/tracking/google_analytics_spec.rb
56
58
  - spec/ratel_spec.rb
57
59
  - spec/spec_helper.rb
58
60
  homepage: https://github.com/yulii/ratel
@@ -80,7 +82,9 @@ signing_key:
80
82
  specification_version: 3
81
83
  summary: a/b testing module
82
84
  test_files:
83
- - spec/helper/action_view_extension_spec.rb
84
85
  - spec/rails_spec_app.rb
86
+ - spec/ratel/engine_spec.rb
87
+ - spec/ratel/helper/action_view_extension_spec.rb
88
+ - spec/ratel/tracking/google_analytics_spec.rb
85
89
  - spec/ratel_spec.rb
86
90
  - spec/spec_helper.rb
@@ -1,18 +0,0 @@
1
- module Ratel
2
- module Tracking
3
- class Event
4
-
5
- class << self
6
- def push category, action, label
7
- case Ratel.config.tracking
8
- when :google_analytics
9
- self.extend Ratel::Tracking::GoogleAnalytics
10
- else
11
- raise NotImplementedError, "invalid Ratel.config.tracking"
12
- end
13
- _push category, action, label
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,14 +0,0 @@
1
- # coding: UTF-8
2
- require 'spec_helper'
3
-
4
- include Ratel::ActionViewExtension
5
- describe Ratel::ActionViewExtension do
6
-
7
- before do
8
- visit "/"
9
- puts page.html
10
- end
11
-
12
- subject { page }
13
- it { should have_content "TEST" }
14
- end