rack-tracker 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +113 -10
- data/lib/rack/tracker.rb +3 -0
- data/lib/rack/tracker/go_squared/go_squared.rb +37 -0
- data/lib/rack/tracker/go_squared/template/go_squared.erb +47 -0
- data/lib/rack/tracker/version.rb +1 -1
- data/lib/rack/tracker/vwo/template/vwo.erb +10 -0
- data/lib/rack/tracker/vwo/vwo.rb +5 -0
- data/spec/handler/go_squared_spec.rb +46 -0
- data/spec/handler/vwo_spec.rb +12 -0
- data/spec/integration/facebook_integration_spec.rb +3 -8
- data/spec/integration/go_squared_integration_spec.rb +72 -0
- data/spec/integration/google_analytics_integration_spec.rb +3 -8
- data/spec/integration/rails_integration_spec.rb +4 -8
- data/spec/integration/vwo_integration_spec.rb +17 -0
- data/spec/support/capybara_app_helper.rb +27 -0
- data/spec/support/metal_controller.rb +12 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e83bc3662d5297183050ac1210f0707773bcc3c
|
4
|
+
data.tar.gz: b1dc4f2fee0a5965559641a347562ccdb07c9da3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d0fe52d68d0e7109d2b2bd420179f2ce9973661c2159d15cf302e63b3e008f807a4a6fbb1da23cf1c4e4009e3a1b6be8a37fb9293cb35999444fec4b7182aa1
|
7
|
+
data.tar.gz: 0f6e8f2d08eab9e53716bb19813e40120cc3b6d34f7b621c9f2bb27d004ad6b3b97c9920b0424ea4a9abbc4f7fa0d78933dc3b91a13c4a25ff7948d2de4f01ba
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,24 @@
|
|
1
1
|
# Rack::Tracker
|
2
2
|
|
3
|
-
[![Code Climate](https://codeclimate.com/github/railslove/rack-tracker/badges/gpa.svg)](https://codeclimate.com/github/railslove/rack-tracker)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
[![Code Climate](https://codeclimate.com/github/railslove/rack-tracker/badges/gpa.svg)](https://codeclimate.com/github/railslove/rack-tracker) [![Build Status](https://travis-ci.org/railslove/rack-tracker.svg?branch=master)](https://travis-ci.org/railslove/rack-tracker)
|
4
|
+
|
5
|
+
## Rationale
|
6
|
+
|
7
|
+
Most of the applications we're working on are using some sort of tracking/analytics service,
|
8
|
+
Google Analytics comes first but its likely that more are added as the project grows.
|
9
|
+
Normally you'd go ahead and add some partials to your application that will render out the
|
10
|
+
needed tracking codes. As time passes by you'll find yourself with lots of tracking
|
11
|
+
snippets, that will clutter your codebase :) When just looking at Analytics there are
|
12
|
+
solutions like `rack-google-analytics` but they just soley tackle the existence of one
|
13
|
+
service.
|
14
|
+
|
15
|
+
We wanted a solution that ties all services together in one place and offers
|
16
|
+
an easy interface to drop in new services. This is why we created `rack-tracker`, a
|
17
|
+
rack middleware that can be hooked up to multiple services and exposing them in a unified
|
18
|
+
fashion. It comes in two parts, the first one is the actual middleware that you can add
|
19
|
+
to the middleware stack the second part are the service-handlers that you're going to use
|
20
|
+
in your application. We're shipping support for Google and Facebook, to add your own please
|
21
|
+
read about [custom handlers](#custom-handlers).
|
8
22
|
|
9
23
|
## Installation
|
10
24
|
|
@@ -80,8 +94,8 @@ Will give you this:
|
|
80
94
|
ga('ecommerce:addItem', { 'id': '1234', 'affiliation': 'Acme Clothing', 'revenue': '11.99', 'shipping': '5', 'tax': '1.29' })
|
81
95
|
```
|
82
96
|
|
83
|
-
To load the `ecommerce`-plugin, add some configuration to the middleware initialization
|
84
|
-
|
97
|
+
To load the `ecommerce`-plugin, add some configuration to the middleware initialization.
|
98
|
+
This is _not_ needed for the above to work, but recommened, so you don't have to
|
85
99
|
take care of the plugin on your own.
|
86
100
|
|
87
101
|
```ruby
|
@@ -112,8 +126,97 @@ Will result in the following:
|
|
112
126
|
```javascript
|
113
127
|
window._fbq.push(["track", "123456789", {'value': 1, 'currency': 'EUR'}]);
|
114
128
|
```
|
129
|
+
### Visual website Optimizer (VWO)
|
130
|
+
Just integrate the handler with your matching account_id and you will be ready to go
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
use Rack::Tracker do
|
134
|
+
handler :vwo, { account_id: 'YOUR_ACCOUNT_ID' }
|
135
|
+
end
|
136
|
+
```
|
137
|
+
|
138
|
+
### GoSquared
|
139
|
+
|
140
|
+
To enable GoSquared tracking:
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
config.middleware.use(Rack::Tracker) do
|
144
|
+
handler :go_squared, { tracker: 'ABCDEFGH' }
|
145
|
+
end
|
146
|
+
````
|
147
|
+
|
148
|
+
This will add the tracker to the page like so:
|
149
|
+
|
150
|
+
``` javascript
|
151
|
+
_gs('ABCDEFGH');
|
152
|
+
```
|
153
|
+
|
154
|
+
You can also set multiple named trackers if need be:
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
config.middleware.use(Rack::Tracker) do
|
158
|
+
handler :go_squared, {
|
159
|
+
trackers: {
|
160
|
+
primaryTracker: 'ABCDEFGH',
|
161
|
+
secondaryTracker: '1234567',
|
162
|
+
}
|
163
|
+
}
|
164
|
+
end
|
165
|
+
````
|
166
|
+
|
167
|
+
This will add the specified trackers to the page like so:
|
168
|
+
|
169
|
+
``` javascript
|
170
|
+
_gs('ABCDEFGH', 'primaryTracker');
|
171
|
+
_gs('1234567', 'secondaryTracker');
|
172
|
+
```
|
173
|
+
|
174
|
+
You can set [a variety of options](https://www.gosquared.com/developer/tracker/configuration/) by passing the following settings. If you don't set any of the following options, they will be omitted from the rendered code.
|
175
|
+
|
176
|
+
* `:anonymize_ip`
|
177
|
+
* `:cookie_domain`
|
178
|
+
* `:use_cookies`
|
179
|
+
* `:track_hash`
|
180
|
+
* `:track_local`
|
181
|
+
* `:track_params`
|
182
|
+
|
183
|
+
#### Visitor Name
|
184
|
+
|
185
|
+
To track the [visitor name](https://www.gosquared.com/developer/tracker/tagging/) from the server side, just call the `tracker` method in your controller.
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
def show
|
189
|
+
tracker do |t|
|
190
|
+
t.go_squared :visitor_name, { name: 'John Doe' }
|
191
|
+
end
|
192
|
+
end
|
193
|
+
```
|
194
|
+
|
195
|
+
It will render the following to the site source:
|
196
|
+
|
197
|
+
```javascript
|
198
|
+
_gs("set", "visitorName", "John Doe");
|
199
|
+
```
|
200
|
+
|
201
|
+
#### Visitor Properties
|
202
|
+
|
203
|
+
To track [visitor properties](https://www.gosquared.com/developer/tracker/tagging/) from the server side, just call the `tracker` method in your controller.
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
def show
|
207
|
+
tracker do |t|
|
208
|
+
t.go_squared :visitor_info, { age: 35, favorite_food: 'pizza' }
|
209
|
+
end
|
210
|
+
end
|
211
|
+
```
|
212
|
+
|
213
|
+
It will render the following to the site source:
|
214
|
+
|
215
|
+
```javascript
|
216
|
+
_gs("set", "visitor", { "age": 35, "favorite_food": "pizza" });
|
217
|
+
```
|
115
218
|
|
116
|
-
|
219
|
+
### Custom Handlers
|
117
220
|
|
118
221
|
Tough we give you Google Analytics and Facebook right out of the box, you might
|
119
222
|
be interested adding support for your custom tracking/analytics service.
|
@@ -156,8 +259,8 @@ Lets give it a try! We need to mount our new handler in the `Rack::Tracker` midd
|
|
156
259
|
end
|
157
260
|
````
|
158
261
|
|
159
|
-
Everything you're passing to the `handler` will be
|
160
|
-
template,
|
262
|
+
Everything you're passing to the `handler` will be available as `#options` in your
|
263
|
+
template, so you'll also gain access to the `env`-hash belonging to the current request.
|
161
264
|
|
162
265
|
Run your application and make a request, the result of the above template can be
|
163
266
|
found right before `</head>`. You can change the position in your handler-code:
|
data/lib/rack/tracker.rb
CHANGED
@@ -3,6 +3,7 @@ require "tilt"
|
|
3
3
|
require "active_support/core_ext/class/attribute"
|
4
4
|
require "active_support/core_ext/hash"
|
5
5
|
require "active_support/json"
|
6
|
+
require "active_support/inflector"
|
6
7
|
|
7
8
|
require "rack/tracker/version"
|
8
9
|
require "rack/tracker/extensions"
|
@@ -12,6 +13,8 @@ require "rack/tracker/handler_delegator"
|
|
12
13
|
require "rack/tracker/controller"
|
13
14
|
require "rack/tracker/google_analytics/google_analytics"
|
14
15
|
require "rack/tracker/facebook/facebook"
|
16
|
+
require "rack/tracker/vwo/vwo"
|
17
|
+
require "rack/tracker/go_squared/go_squared"
|
15
18
|
|
16
19
|
module Rack
|
17
20
|
class Tracker
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Rack::Tracker::GoSquared < Rack::Tracker::Handler
|
2
|
+
class VisitorName < OpenStruct
|
3
|
+
def write
|
4
|
+
['set', 'visitorName', self.name].to_json.gsub(/\[|\]/, '')
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class VisitorInfo < OpenStruct
|
9
|
+
def write
|
10
|
+
['set', 'visitor', to_h].to_json.gsub(/\[|\]/, '')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def tracker
|
15
|
+
options[:tracker]
|
16
|
+
end
|
17
|
+
|
18
|
+
def trackers
|
19
|
+
options[:trackers]
|
20
|
+
end
|
21
|
+
|
22
|
+
def render
|
23
|
+
Tilt.new( File.join( File.dirname(__FILE__), 'template', 'go_squared.erb') ).render(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def visitor_name
|
27
|
+
events.select{|e| e.kind_of?(VisitorName) }.first
|
28
|
+
end
|
29
|
+
|
30
|
+
def visitor_info
|
31
|
+
events.select{|e| e.kind_of?(VisitorInfo) }.first
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.track(name, *event)
|
35
|
+
{ name.to_s => [const_get(event.first.to_s.classify).new(event.last)] }
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<script>
|
2
|
+
!function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push(
|
3
|
+
arguments)};d=s.createElement(q);q=s.getElementsByTagName(q)[0];
|
4
|
+
d.src='//d1l6p2sc9645hc.cloudfront.net/tracker.js';q.parentNode.
|
5
|
+
insertBefore(d,q)}(window,document,'script','_gs');
|
6
|
+
<% if tracker %>
|
7
|
+
_gs('<%= tracker %>');
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<% if trackers %>
|
11
|
+
<% trackers.each do |name, code| %>
|
12
|
+
_gs('<%= code %>', '<%= name %>');
|
13
|
+
<% end %>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<% if options[:anonymize_ip] %>
|
17
|
+
_gs('set', 'anonymizeIp', <%= options[:anonymize_ip] %>);
|
18
|
+
<% end %>
|
19
|
+
|
20
|
+
<% if options[:cookie_domain] %>
|
21
|
+
_gs('set', 'cookieDomain', '<%= options[:cookie_domain] %>');
|
22
|
+
<% end %>
|
23
|
+
|
24
|
+
<% if options[:use_cookies] %>
|
25
|
+
_gs('set', 'useCookies', <%= options[:use_cookies] %>);
|
26
|
+
<% end %>
|
27
|
+
|
28
|
+
<% if options[:track_hash] %>
|
29
|
+
_gs('set', 'trackHash', <%= options[:track_hash] %>);
|
30
|
+
<% end %>
|
31
|
+
|
32
|
+
<% if options[:track_local] %>
|
33
|
+
_gs('set', 'trackLocal', <%= options[:track_local] %>);
|
34
|
+
<% end %>
|
35
|
+
|
36
|
+
<% if options[:track_params] %>
|
37
|
+
_gs('set', 'trackParams', <%= options[:track_params] %>);
|
38
|
+
<% end %>
|
39
|
+
|
40
|
+
<% if visitor_name %>
|
41
|
+
_gs(<%= visitor_name.write() %>);
|
42
|
+
<% end %>
|
43
|
+
|
44
|
+
<% if visitor_info %>
|
45
|
+
_gs(<%= visitor_info.write() %>);
|
46
|
+
<% end %>
|
47
|
+
</script>
|
data/lib/rack/tracker/version.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
<!-- Start Visual Website Optimizer Asynchronous Code -->
|
2
|
+
<script type='text/javascript'>
|
3
|
+
var _vwo_code=(function(){
|
4
|
+
settings_tolerance=2000,
|
5
|
+
library_tolerance=2500,
|
6
|
+
use_existing_jquery=false,
|
7
|
+
// DO NOT EDIT BELOW THIS LINE
|
8
|
+
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();
|
9
|
+
</script>
|
10
|
+
<!-- End Visual Website Optimizer Asynchronous Code -->
|
@@ -0,0 +1,46 @@
|
|
1
|
+
RSpec.describe Rack::Tracker::GoSquared do
|
2
|
+
|
3
|
+
def env
|
4
|
+
{misc: 'foobar'}
|
5
|
+
end
|
6
|
+
|
7
|
+
it 'will be placed in the head' do
|
8
|
+
expect(described_class.position).to eq(:head)
|
9
|
+
expect(described_class.new(env).position).to eq(:head)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "with events" do
|
13
|
+
describe "visitor name" do
|
14
|
+
def env
|
15
|
+
{'tracker' => {
|
16
|
+
'go_squared' => [
|
17
|
+
Rack::Tracker::GoSquared::VisitorName.new(name: "John Doe")
|
18
|
+
]
|
19
|
+
}}
|
20
|
+
end
|
21
|
+
|
22
|
+
subject { described_class.new(env, tracker: '12345').render }
|
23
|
+
|
24
|
+
it "will show the right name" do
|
25
|
+
expect(subject).to match(%r{_gs\(\"set\",\"visitorName\",\"John Doe\"\)})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "visitor details" do
|
30
|
+
def env
|
31
|
+
{'tracker' => {
|
32
|
+
'go_squared' => [
|
33
|
+
Rack::Tracker::GoSquared::VisitorInfo.new(age: 35, favorite_food: 'pizza')
|
34
|
+
]
|
35
|
+
}}
|
36
|
+
end
|
37
|
+
|
38
|
+
subject { described_class.new(env, tracker: '12345').render }
|
39
|
+
|
40
|
+
it "will show the right properties" do
|
41
|
+
expect(subject).to match(%r{_gs\(\"set\",\"visitor\",{\"age\":35,\"favorite_food\":\"pizza\"}\)})
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -1,15 +1,10 @@
|
|
1
|
-
require 'support/
|
2
|
-
require 'support/fake_handler'
|
1
|
+
require 'support/capybara_app_helper'
|
3
2
|
|
4
3
|
RSpec.describe "Facebook Integration" do
|
5
4
|
before do
|
6
|
-
|
7
|
-
|
8
|
-
handler :facebook, { custom_audience: 'my-audience' }
|
9
|
-
end
|
10
|
-
run MetalController.action(:facebook)
|
5
|
+
setup_app(action: :facebook) do |tracker|
|
6
|
+
tracker.handler :facebook, { custom_audience: 'my-audience' }
|
11
7
|
end
|
12
|
-
|
13
8
|
visit '/'
|
14
9
|
end
|
15
10
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'support/capybara_app_helper'
|
2
|
+
|
3
|
+
RSpec.describe "GoSquared Integration" do
|
4
|
+
subject { page }
|
5
|
+
|
6
|
+
before do
|
7
|
+
setup_app(action: :go_squared) do |tracker|
|
8
|
+
tracker.handler :go_squared, {
|
9
|
+
tracker: '123456',
|
10
|
+
anonymize_ip: true,
|
11
|
+
cookie_domain: 'domain.com',
|
12
|
+
use_cookies: true,
|
13
|
+
track_hash: true,
|
14
|
+
track_local: true,
|
15
|
+
track_params: true
|
16
|
+
}
|
17
|
+
end
|
18
|
+
visit '/'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "adds the tracker to the page" do
|
22
|
+
expect(page).to have_content("_gs('123456');")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "adds the visitorName to the page" do
|
26
|
+
expect(page).to have_content('_gs("set","visitorName","John Doe");')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "adds the visitor to the page" do
|
30
|
+
expect(page).to have_content('_gs("set","visitor",{"age":35,"favorite_food":"pizza"});')
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets anonymizeIp" do
|
34
|
+
expect(page).to have_content("_gs('set', 'anonymizeIp', true);")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "sets cookieDomain" do
|
38
|
+
expect(page).to have_content("_gs('set', 'cookieDomain', 'domain.com');")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "sets useCookies" do
|
42
|
+
expect(page).to have_content("_gs('set', 'useCookies', true);")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "sets trackHash" do
|
46
|
+
expect(page).to have_content("_gs('set', 'trackHash', true);")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "sets trackLocal" do
|
50
|
+
expect(page).to have_content("_gs('set', 'trackLocal', true);")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "sets trackParams" do
|
54
|
+
expect(page).to have_content("_gs('set', 'trackParams', true);")
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'multiple trackers are passed in' do
|
58
|
+
before do
|
59
|
+
setup_app(action: :go_squared) do |tracker|
|
60
|
+
tracker.handler :go_squared, {
|
61
|
+
trackers: { primaryTracker: '12345', secondaryTracker: '67890' }
|
62
|
+
}
|
63
|
+
end
|
64
|
+
visit '/'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "adds the tracker to the page" do
|
68
|
+
expect(page).to have_content("_gs('12345', 'primaryTracker');")
|
69
|
+
expect(page).to have_content("_gs('67890', 'secondaryTracker');")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -1,15 +1,10 @@
|
|
1
|
-
require 'support/
|
2
|
-
require 'support/fake_handler'
|
1
|
+
require 'support/capybara_app_helper'
|
3
2
|
|
4
3
|
RSpec.describe "Facebook Integration" do
|
5
4
|
before do
|
6
|
-
|
7
|
-
|
8
|
-
handler :google_analytics, { tracker: 'U-XXX-Y' }
|
9
|
-
end
|
10
|
-
run MetalController.action(:google_analytics)
|
5
|
+
setup_app(action: :google_analytics) do |tracker|
|
6
|
+
tracker.handler :google_analytics, { tracker: 'U-XXX-Y' }
|
11
7
|
end
|
12
|
-
|
13
8
|
visit '/'
|
14
9
|
end
|
15
10
|
|
@@ -1,14 +1,10 @@
|
|
1
|
-
require 'support/
|
2
|
-
require 'support/fake_handler'
|
1
|
+
require 'support/capybara_app_helper'
|
3
2
|
|
4
3
|
RSpec.describe "Rails Integration" do
|
5
4
|
before do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
handler :another_handler, { custom_key: 'AnotherKey42' }
|
10
|
-
end
|
11
|
-
run MetalController.action(:index)
|
5
|
+
setup_app(action: :index) do |tracker|
|
6
|
+
tracker.handler :track_all_the_things, { custom_key: 'SomeKey123' }
|
7
|
+
tracker.handler :another_handler, { custom_key: 'AnotherKey42' }
|
12
8
|
end
|
13
9
|
|
14
10
|
visit '/'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'support/capybara_app_helper'
|
2
|
+
|
3
|
+
RSpec.describe "VWO Integration" do
|
4
|
+
before do
|
5
|
+
setup_app(action: :vwo) do |tracker|
|
6
|
+
tracker.handler :vwo, { account_id: '123456' }
|
7
|
+
end
|
8
|
+
|
9
|
+
visit '/'
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { page }
|
13
|
+
|
14
|
+
it "embeds the script tag" do
|
15
|
+
expect(page).to have_content("this.load('//dev.visualwebsiteoptimizer.com/j.php?a='+ '123456'")
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'support/metal_controller'
|
2
|
+
|
3
|
+
# helper to configure the middleware stack with custom handlers
|
4
|
+
# and capybara app setup for more convenient testing.
|
5
|
+
# You can use this in your integration spec by placing it in a before block.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
#
|
9
|
+
# before do
|
10
|
+
# setup_app(action: :your_controller_action) do |tracker|
|
11
|
+
# tracker.handler :your_new_handler, { custom_tracker_key: 'SomeKey123' }
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# By default this dispatches to a metal controller as a simple rack endpoint
|
16
|
+
# like rails would do, but without booting up a full rails environment.
|
17
|
+
def setup_app(options={}, &block)
|
18
|
+
rack_endpoint = options[:endpoint] || MetalController
|
19
|
+
controller_action = options[:action]
|
20
|
+
|
21
|
+
Capybara.app = Rack::Builder.new do
|
22
|
+
use Rack::Tracker do
|
23
|
+
block[self]
|
24
|
+
end
|
25
|
+
run rack_endpoint.action(controller_action)
|
26
|
+
end
|
27
|
+
end
|
@@ -29,4 +29,16 @@ class MetalController < ActionController::Metal
|
|
29
29
|
end
|
30
30
|
render "metal/index"
|
31
31
|
end
|
32
|
+
|
33
|
+
def vwo
|
34
|
+
render "metal/index"
|
35
|
+
end
|
36
|
+
|
37
|
+
def go_squared
|
38
|
+
tracker do |t|
|
39
|
+
t.go_squared :visitor_name, { name: 'John Doe' }
|
40
|
+
t.go_squared :visitor_info, { age: 35, favorite_food: 'pizza' }
|
41
|
+
end
|
42
|
+
render "metal/index"
|
43
|
+
end
|
32
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lars Brillert
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-09-
|
12
|
+
date: 2014-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -159,12 +159,16 @@ files:
|
|
159
159
|
- lib/rack/tracker/extensions.rb
|
160
160
|
- lib/rack/tracker/facebook/facebook.rb
|
161
161
|
- lib/rack/tracker/facebook/template/facebook.erb
|
162
|
+
- lib/rack/tracker/go_squared/go_squared.rb
|
163
|
+
- lib/rack/tracker/go_squared/template/go_squared.erb
|
162
164
|
- lib/rack/tracker/google_analytics/google_analytics.rb
|
163
165
|
- lib/rack/tracker/google_analytics/template/google_analytics.erb
|
164
166
|
- lib/rack/tracker/handler.rb
|
165
167
|
- lib/rack/tracker/handler_delegator.rb
|
166
168
|
- lib/rack/tracker/railtie.rb
|
167
169
|
- lib/rack/tracker/version.rb
|
170
|
+
- lib/rack/tracker/vwo/template/vwo.erb
|
171
|
+
- lib/rack/tracker/vwo/vwo.rb
|
168
172
|
- rack-tracker.gemspec
|
169
173
|
- spec/fixtures/another_handler.erb
|
170
174
|
- spec/fixtures/dummy.erb
|
@@ -172,11 +176,16 @@ files:
|
|
172
176
|
- spec/fixtures/views/layouts/application.html.erb
|
173
177
|
- spec/fixtures/views/metal/index.html.erb
|
174
178
|
- spec/handler/facebook_spec.rb
|
179
|
+
- spec/handler/go_squared_spec.rb
|
175
180
|
- spec/handler/google_analytics_spec.rb
|
181
|
+
- spec/handler/vwo_spec.rb
|
176
182
|
- spec/integration/facebook_integration_spec.rb
|
183
|
+
- spec/integration/go_squared_integration_spec.rb
|
177
184
|
- spec/integration/google_analytics_integration_spec.rb
|
178
185
|
- spec/integration/rails_integration_spec.rb
|
186
|
+
- spec/integration/vwo_integration_spec.rb
|
179
187
|
- spec/spec_helper.rb
|
188
|
+
- spec/support/capybara_app_helper.rb
|
180
189
|
- spec/support/fake_handler.rb
|
181
190
|
- spec/support/metal_controller.rb
|
182
191
|
- spec/tracker/controller_spec.rb
|
@@ -214,11 +223,16 @@ test_files:
|
|
214
223
|
- spec/fixtures/views/layouts/application.html.erb
|
215
224
|
- spec/fixtures/views/metal/index.html.erb
|
216
225
|
- spec/handler/facebook_spec.rb
|
226
|
+
- spec/handler/go_squared_spec.rb
|
217
227
|
- spec/handler/google_analytics_spec.rb
|
228
|
+
- spec/handler/vwo_spec.rb
|
218
229
|
- spec/integration/facebook_integration_spec.rb
|
230
|
+
- spec/integration/go_squared_integration_spec.rb
|
219
231
|
- spec/integration/google_analytics_integration_spec.rb
|
220
232
|
- spec/integration/rails_integration_spec.rb
|
233
|
+
- spec/integration/vwo_integration_spec.rb
|
221
234
|
- spec/spec_helper.rb
|
235
|
+
- spec/support/capybara_app_helper.rb
|
222
236
|
- spec/support/fake_handler.rb
|
223
237
|
- spec/support/metal_controller.rb
|
224
238
|
- spec/tracker/controller_spec.rb
|