diff --git a/README.md b/README.md index 332be68..2c359c3 100644 --- a/README.md +++ b/README.md @@ -126,8 +126,16 @@ Will result in the following: ```javascript window._fbq.push(["track", "123456789", {'value': 1, 'currency': 'EUR'}]); ``` +### Visual website Optimizer (VWO) +Just integrate the handler with your matching account_id and you will be ready to go -#### Custom Handlers +```ruby + use Rack::Tracker do + handler :vwo, { account_id: 'YOUR_ACCOUNT_ID' } + end +``` + +### Custom Handlers Tough we give you Google Analytics and Facebook right out of the box, you might be interested adding support for your custom tracking/analytics service. diff --git a/lib/rack/tracker.rb b/lib/rack/tracker.rb index d2ceae0..5b9627d 100644 --- a/lib/rack/tracker.rb +++ b/lib/rack/tracker.rb @@ -12,6 +12,7 @@ require "rack/tracker/controller" require "rack/tracker/google_analytics/google_analytics" require "rack/tracker/facebook/facebook" +require "rack/tracker/vwo/vwo" module Rack class Tracker diff --git a/lib/rack/tracker/vwo/template/vwo.erb b/lib/rack/tracker/vwo/template/vwo.erb new file mode 100644 index 0000000..b2d1f1e --- /dev/null +++ b/lib/rack/tracker/vwo/template/vwo.erb @@ -0,0 +1,10 @@ + + + diff --git a/lib/rack/tracker/vwo/vwo.rb b/lib/rack/tracker/vwo/vwo.rb new file mode 100644 index 0000000..3c02088 --- /dev/null +++ b/lib/rack/tracker/vwo/vwo.rb @@ -0,0 +1,5 @@ +class Vwo < Rack::Tracker::Handler + def render + Tilt.new( File.join( File.dirname(__FILE__), 'template', 'vwo.erb') ).render(self) + end +end diff --git a/spec/handler/vwo_spec.rb b/spec/handler/vwo_spec.rb new file mode 100644 index 0000000..5b4fab6 --- /dev/null +++ b/spec/handler/vwo_spec.rb @@ -0,0 +1,12 @@ +RSpec.describe Rack::Tracker::Vwo do + + def env + {misc: 'foobar'} + end + + it 'will be placed in the head' do + expect(described_class.position).to eq(:head) + expect(described_class.new(env).position).to eq(:head) + end + +end diff --git a/spec/integration/vwo_integration_spec.rb b/spec/integration/vwo_integration_spec.rb new file mode 100644 index 0000000..f8c9734 --- /dev/null +++ b/spec/integration/vwo_integration_spec.rb @@ -0,0 +1,21 @@ +require 'support/metal_controller' +require 'support/fake_handler' + +RSpec.describe "VWO Integration" do + before do + Capybara.app = Rack::Builder.new do + use Rack::Tracker do + handler :vwo, { account_id: '123456' } + end + run MetalController.action(:vwo) + end + + visit '/' + end + + subject { page } + + it "embeds the script tag" do + expect(page).to have_content("this.load('//dev.visualwebsiteoptimizer.com/j.php?a='+ '123456'") + end +end diff --git a/spec/support/metal_controller.rb b/spec/support/metal_controller.rb index ce9194c..9d02469 100644 --- a/spec/support/metal_controller.rb +++ b/spec/support/metal_controller.rb @@ -29,4 +29,8 @@ def google_analytics end render "metal/index" end + + def vwo + render "metal/index" + end end