Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/rack/tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/rack/tracker/vwo/template/vwo.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- Start Visual Website Optimizer Asynchronous Code -->
<script type='text/javascript'>
var _vwo_code=(function(){
settings_tolerance=2000,
library_tolerance=2500,
use_existing_jquery=false,
// DO NOT EDIT BELOW THIS LINE
f=false,d=document;return{use_existing_jquery:function(){return use_existing_jquery;},library_tolerance:function(){return library_tolerance;},finish:function(){if(!f){f=true;var a=d.getElementById('_vis_opt_path_hides');if(a)a.parentNode.removeChild(a);}},finished:function(){return f;},load:function(a){var b=d.createElement('script');b.src=a;b.type='text/javascript';b.innerText;b.onerror=function(){_vwo_code.finish();};d.getElementsByTagName('head')[0].appendChild(b);},init:function(){settings_timer=setTimeout('_vwo_code.finish()',settings_tolerance);this.load('//dev.visualwebsiteoptimizer.com/j.php?a='+ '<%= options[:account_id] %>' + '&u='+encodeURIComponent(d.URL)+'&r='+Math.random());var a=d.createElement('style'),b='body{opacity:0 !important;filter:alpha(opacity=0) !important;background:none !important;}',h=d.getElementsByTagName('head')[0];a.setAttribute('id','_vis_opt_path_hides');a.setAttribute('type','text/css');if(a.styleSheet)a.styleSheet.cssText=b;else a.appendChild(d.createTextNode(b));h.appendChild(a);return settings_timer;}};}());_vwo_settings_timer=_vwo_code.init();
</script>
<!-- End Visual Website Optimizer Asynchronous Code -->
5 changes: 5 additions & 0 deletions lib/rack/tracker/vwo/vwo.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions spec/handler/vwo_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
RSpec.describe Rack::Tracker::Vwo do

def env
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not let(:env) ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at your very own facebook_spec.rb :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, gotcha. haven't seen that :)
then it seems like @kangguru is fine with that.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let was not working somehow

{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
21 changes: 21 additions & 0 deletions spec/integration/vwo_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions spec/support/metal_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ def google_analytics
end
render "metal/index"
end

def vwo
render "metal/index"
end
end