rack-tracker 0.1.1 → 0.1.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +8 -6
- data/lib/rack/tracker/google_analytics/google_analytics.rb +5 -1
- data/lib/rack/tracker/google_analytics/template/google_analytics.erb +4 -0
- data/lib/rack/tracker/version.rb +1 -1
- data/spec/handler/google_analytics_spec.rb +27 -4
- data/spec/integration/google_analytics_integration_spec.rb +22 -0
- data/spec/support/metal_controller.rb +8 -0
- data/spec/tracker/controller_spec.rb +11 -23
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee9ff19b84fd4c1015a6fcb45ed4058730690a18
|
4
|
+
data.tar.gz: bee999355979d360bd8304cfd874ef9fb17fe905
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa80a05b10f7fbd960127453a5c83deb0888c1b04f57164a70a78cb12edf986d96ea8957af416951c9daa86e07f00c10593babe2aa08bee8bdfec43c3e904c72
|
7
|
+
data.tar.gz: dc886bd2cbd1c9ee963bf94a14d54e43c89cf5497ac1f4fa83d41b2c3c78d5cf62ab242e0aa2d2ac1ca7608444a5c65b3755eba19794558ca91afa8502d39ecf
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# 0.1.3
|
2
|
+
|
3
|
+
* [BUGFIX] ecommerce events weren't created properly
|
4
|
+
|
5
|
+
# 0.1.2
|
6
|
+
|
7
|
+
* cart is now auto submitted to when ecommerce is turned on and items or transactions are in the queue
|
8
|
+
|
9
|
+
# 0.1.1
|
10
|
+
|
11
|
+
* [BUGFIX] return value of the `tracker`-block is kinda unpredictabel, so we skip further processing
|
12
|
+
|
13
|
+
# 0.1.0
|
14
|
+
|
15
|
+
* README
|
16
|
+
* unified facebook and google handler `#track`-signature (3009b3834ad07caf8818484ddd86d8a0eb128fe5)
|
17
|
+
|
18
|
+
# 0.0.4
|
19
|
+
|
20
|
+
* keep events over multiple redirectes
|
21
|
+
* allow multiple calls of the same handler in one `tracker` block
|
data/README.md
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
|
5
5
|
[](https://travis-ci.org/railslove/rack-tracker)
|
6
6
|
|
7
|
+
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Add this line to your application's Gemfile:
|
@@ -57,7 +59,7 @@ To issue [Events](https://developers.google.com/analytics/devguides/collection/a
|
|
57
59
|
It will render the following to the site source:
|
58
60
|
|
59
61
|
```javascript
|
60
|
-
ga('send', { 'hitType': 'event', 'eventCategory': 'button', 'eventAction': 'click', 'eventLabel': 'X' })
|
62
|
+
ga('send', { 'hitType': 'event', 'eventCategory': 'button', 'eventAction': 'click', 'eventLabel': 'nav-buttons', 'value': 'X' })
|
61
63
|
```
|
62
64
|
|
63
65
|
#### Ecommerce
|
@@ -67,7 +69,7 @@ You can even trigger ecommerce directly from within your controller:
|
|
67
69
|
```ruby
|
68
70
|
def show
|
69
71
|
tracker do |t|
|
70
|
-
t.google_analytics :ecommerce, { type: 'addItem',
|
72
|
+
t.google_analytics :ecommerce, { type: 'addItem', id: '1234', affiliation: 'Acme Clothing', revenue: '11.99', shipping: '5', tax: '1.29' }
|
71
73
|
end
|
72
74
|
end
|
73
75
|
```
|
@@ -93,7 +95,7 @@ take care of the plugin on your own.
|
|
93
95
|
|
94
96
|
* `custom_audience` - adds the [Custom audience](https://developers.facebook.com/docs/reference/ads-api/custom-audience-website-faq) segmentation pixel
|
95
97
|
|
96
|
-
####
|
98
|
+
#### Conversions
|
97
99
|
|
98
100
|
To track [Conversions](https://www.facebook.com/help/435189689870514) from the server side just call the `tracker` method in your controller.
|
99
101
|
|
@@ -111,7 +113,7 @@ Will result in the following:
|
|
111
113
|
window._fbq.push(["track", "123456789", {'value': 1, 'currency': 'EUR'}]);
|
112
114
|
```
|
113
115
|
|
114
|
-
|
116
|
+
#### Custom Handlers
|
115
117
|
|
116
118
|
Tough we give you Google Analytics and Facebook right out of the box, you might
|
117
119
|
be interested adding support for your custom tracking/analytics service.
|
@@ -132,7 +134,7 @@ template.
|
|
132
134
|
|
133
135
|
```ruby
|
134
136
|
def render
|
135
|
-
Tilt.new( File.join( File.dirname(__FILE__), 'template' 'my_handler.erb') ).render(self)
|
137
|
+
Tilt.new( File.join( File.dirname(__FILE__), 'template', 'my_handler.erb') ).render(self)
|
136
138
|
end
|
137
139
|
```
|
138
140
|
|
@@ -168,7 +170,7 @@ class MyHandler < Rack::Tracker::Handler
|
|
168
170
|
end
|
169
171
|
```
|
170
172
|
|
171
|
-
The
|
173
|
+
The snippit will then be rendered right before `</body>`.
|
172
174
|
|
173
175
|
|
174
176
|
## Contributing
|
@@ -32,7 +32,11 @@ class Rack::Tracker::GoogleAnalytics < Rack::Tracker::Handler
|
|
32
32
|
Tilt.new( File.join( File.dirname(__FILE__), 'template', 'google_analytics.erb') ).render(self)
|
33
33
|
end
|
34
34
|
|
35
|
+
def ecommerce_events
|
36
|
+
events.select{|e| e.kind_of?(Ecommerce) }
|
37
|
+
end
|
38
|
+
|
35
39
|
def self.track(name, *event)
|
36
|
-
{ name.to_s => [
|
40
|
+
{ name.to_s => [const_get(event.first.to_s.capitalize).new(event.last)] }
|
37
41
|
end
|
38
42
|
end
|
data/lib/rack/tracker/version.rb
CHANGED
@@ -9,6 +9,26 @@ RSpec.describe Rack::Tracker::GoogleAnalytics do
|
|
9
9
|
expect(described_class.new(env).position).to eq(:head)
|
10
10
|
end
|
11
11
|
|
12
|
+
describe '#ecommerce_events' do
|
13
|
+
subject { described_class.new(env) }
|
14
|
+
|
15
|
+
describe 'with stored ecommerce events' do
|
16
|
+
before { allow(subject).to receive(:events).and_return([Rack::Tracker::GoogleAnalytics::Send.new, Rack::Tracker::GoogleAnalytics::Ecommerce.new]) }
|
17
|
+
|
18
|
+
it 'will just return the ecommerce events' do
|
19
|
+
expect(subject.ecommerce_events).to match_array(Rack::Tracker::GoogleAnalytics::Ecommerce)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'without stored ecommerce events' do
|
24
|
+
before { allow(subject).to receive(:events).and_return([Rack::Tracker::GoogleAnalytics::Send.new]) }
|
25
|
+
|
26
|
+
it 'will be empty' do
|
27
|
+
expect(subject.ecommerce_events).to be_empty
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
12
32
|
describe "with events" do
|
13
33
|
describe "default" do
|
14
34
|
def env
|
@@ -19,7 +39,7 @@ RSpec.describe Rack::Tracker::GoogleAnalytics do
|
|
19
39
|
}}
|
20
40
|
end
|
21
41
|
|
22
|
-
subject { described_class.new(env, tracker: 'somebody'
|
42
|
+
subject { described_class.new(env, tracker: 'somebody').render }
|
23
43
|
it "will show events" do
|
24
44
|
expect(subject).to match(%r{ga\(\"send\",{\"hitType\":\"event\",\"eventCategory\":\"Users\",\"eventAction\":\"Login\",\"eventLabel\":\"Standard\"}\)})
|
25
45
|
end
|
@@ -32,7 +52,7 @@ RSpec.describe Rack::Tracker::GoogleAnalytics do
|
|
32
52
|
]}}
|
33
53
|
end
|
34
54
|
|
35
|
-
subject { described_class.new(env, tracker: 'somebody'
|
55
|
+
subject { described_class.new(env, tracker: 'somebody').render }
|
36
56
|
it "will show events with values" do
|
37
57
|
expect(subject).to match(%r{ga\(\"send\",{\"hitType\":\"event\",\"eventCategory\":\"Users\",\"eventAction\":\"Login\",\"eventLabel\":\"Standard\",\"eventValue\":5}\)},)
|
38
58
|
end
|
@@ -49,10 +69,13 @@ RSpec.describe Rack::Tracker::GoogleAnalytics do
|
|
49
69
|
}}
|
50
70
|
end
|
51
71
|
|
52
|
-
subject { described_class.new(env, tracker: 'somebody',
|
53
|
-
it "will
|
72
|
+
subject { described_class.new(env, tracker: 'somebody', ecommerce: true).render }
|
73
|
+
it "will add items" do
|
54
74
|
expect(subject).to match(%r{ga\(\"ecommerce:addItem\",#{{id: '1234', affiliation: 'Acme Clothing', revenue: 11.99, shipping: '5', tax: '1.29', currency: 'EUR'}.to_json}})
|
55
75
|
end
|
76
|
+
it "will submit cart" do
|
77
|
+
expect(subject).to match(%r{ga\('send:ecommerce'\);})
|
78
|
+
end
|
56
79
|
end
|
57
80
|
end
|
58
81
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'support/metal_controller'
|
2
|
+
require 'support/fake_handler'
|
3
|
+
|
4
|
+
RSpec.describe "Facebook Integration" do
|
5
|
+
before do
|
6
|
+
Capybara.app = Rack::Builder.new do
|
7
|
+
use Rack::Tracker do
|
8
|
+
handler :google_analytics, { tracker: 'U-XXX-Y' }
|
9
|
+
end
|
10
|
+
run MetalController.action(:google_analytics)
|
11
|
+
end
|
12
|
+
|
13
|
+
visit '/'
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { page }
|
17
|
+
|
18
|
+
it "embeds the script tag with tracking event from the controller action" do
|
19
|
+
expect(page).to have_content('ga("ecommerce:addItem",{"id":"1234","affiliation":"Acme Clothing","revenue":"11.99","shipping":"5","tax":"1.29"})')
|
20
|
+
expect(page).to have_content('ga("send",{"hitType":"event","eventCategory":"button","eventAction":"click","eventLabel":"nav-buttons","eventValue":"X"})')
|
21
|
+
end
|
22
|
+
end
|
@@ -21,4 +21,12 @@ class MetalController < ActionController::Metal
|
|
21
21
|
end
|
22
22
|
render "metal/index"
|
23
23
|
end
|
24
|
+
|
25
|
+
def google_analytics
|
26
|
+
tracker do |t|
|
27
|
+
t.google_analytics :ecommerce, { type: 'addItem', id: '1234', affiliation: 'Acme Clothing', revenue: '11.99', shipping: '5', tax: '1.29' }
|
28
|
+
t.google_analytics :send, { type: 'event', category: 'button', action: 'click', label: 'nav-buttons', value: 'X' }
|
29
|
+
end
|
30
|
+
render "metal/index"
|
31
|
+
end
|
24
32
|
end
|
@@ -11,29 +11,17 @@ end
|
|
11
11
|
|
12
12
|
RSpec.describe Rack::Tracker::Controller do
|
13
13
|
describe '#tracker' do
|
14
|
-
|
15
|
-
|
16
|
-
# let(:controller) { TestController.new({}) }
|
14
|
+
let(:event) { Rack::Tracker::GoogleAnalytics::Send.new(category: 'foo') }
|
15
|
+
let(:controller) { TestController.new({}) }
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# it 'returns only the handlers' do
|
28
|
-
# expect(
|
29
|
-
# controller.tracker do |t|
|
30
|
-
# t.google_analytics category: 'foo'
|
31
|
-
# 2.times do
|
32
|
-
# t.facebook some: 'thing'
|
33
|
-
# end
|
34
|
-
# end
|
35
|
-
# ).to eql([:google_analytics, :facebook])
|
36
|
-
# end
|
37
|
-
# end
|
17
|
+
context 'controller' do
|
18
|
+
it 'writes the event into env' do
|
19
|
+
expect {
|
20
|
+
controller.index
|
21
|
+
}.to change {
|
22
|
+
controller.env
|
23
|
+
}.from({}).to('tracker' => {'google_analytics' => [event]})
|
24
|
+
end
|
25
|
+
end
|
38
26
|
end
|
39
27
|
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.1.
|
4
|
+
version: 0.1.3
|
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-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- ".gitignore"
|
150
150
|
- ".rspec"
|
151
151
|
- ".travis.yml"
|
152
|
+
- CHANGELOG.md
|
152
153
|
- Gemfile
|
153
154
|
- LICENSE.txt
|
154
155
|
- README.md
|
@@ -173,6 +174,7 @@ files:
|
|
173
174
|
- spec/handler/facebook_spec.rb
|
174
175
|
- spec/handler/google_analytics_spec.rb
|
175
176
|
- spec/integration/facebook_integration_spec.rb
|
177
|
+
- spec/integration/google_analytics_integration_spec.rb
|
176
178
|
- spec/integration/rails_integration_spec.rb
|
177
179
|
- spec/spec_helper.rb
|
178
180
|
- spec/support/fake_handler.rb
|
@@ -214,6 +216,7 @@ test_files:
|
|
214
216
|
- spec/handler/facebook_spec.rb
|
215
217
|
- spec/handler/google_analytics_spec.rb
|
216
218
|
- spec/integration/facebook_integration_spec.rb
|
219
|
+
- spec/integration/google_analytics_integration_spec.rb
|
217
220
|
- spec/integration/rails_integration_spec.rb
|
218
221
|
- spec/spec_helper.rb
|
219
222
|
- spec/support/fake_handler.rb
|