rack-tracker 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7967cb6b637c7fbcbef964f3e12a198a3e18b4d3
4
- data.tar.gz: 090e46d7451bf2d2d3a449b04a0162bf39e8fd6e
3
+ metadata.gz: f8b00e842917a8b4a5860ba6b66fc31d007330e4
4
+ data.tar.gz: ddcef1305f6638771741e5b1dcb0a95093cf1d30
5
5
  SHA512:
6
- metadata.gz: 0da5aef1623fe668fd12b9c646cc80c262bbcd610bb6686af8fb01b0c201a722191020fa6b4a45ab22e9bf5f33561f7ece544bd9890b88b5f0c85552f0ba6319
7
- data.tar.gz: 8ff3380ee3229d099f78eba30914e7cb67a991013810ab0209db287b3b119a93319966015c6cab06f94dd7e3ec1fe7492ab8763d51cf2302c06afd146a6a9ea0
6
+ metadata.gz: ec3e26414ba7877d46661e8f8eca1b2d80192d8f1eedd4d789f06dd5302937ea59f5ebf83a370bfc04d85ca890a242840c95187aaebf3f8b0d27a574494a292a
7
+ data.tar.gz: 7b9c3a9e365ca61ae867e9a5cc971daad4706d10c96aebffcfb7d65f8de7aa2eaa3a6de95cfc51a39645564657a0e254ddcc13c1829cdbebe0ed13cb1112dea6
@@ -1,11 +1,17 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.5
7
- - 2.2.3
8
- - jruby
4
+ - 2.1.10
5
+ - 2.2.7
6
+ - 2.3.4
7
+ - 2.4.1
8
+ - jruby-9.1.10.0
9
9
  gemfile:
10
+ - Gemfile
10
11
  - Gemfile.rails-3.2
11
12
  - Gemfile.rails-4.2
13
+ - Gemfile.rails-5.1
14
+ matrix:
15
+ exclude:
16
+ - rvm: 2.1.10
17
+ gemfile: Gemfile.rails-5.1 # rails 5 needs ruby >= 2.2.2
@@ -1,3 +1,10 @@
1
+ # 1.2.0
2
+
3
+ * Added Facebook Pixel support #75
4
+ * Datalayer position fix #72
5
+ * Dropped support for Ruby 1.9
6
+ * Rails 5.x compatibility
7
+
1
8
  # 1.1.0
2
9
 
3
10
  * [BREAKING] Google Tag Manager #59
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'activesupport', '~> 5.1.0'
6
+ gem 'actionpack', '~> 5.1.0'
data/README.md CHANGED
@@ -88,10 +88,10 @@ request.env['tracker'] = {
88
88
 
89
89
  * `:anonymize_ip` - sets the tracker to remove the last octet from all IP addresses, see https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApi_gat?hl=de#_gat._anonymizeIp for details.
90
90
  * `:cookie_domain` - sets the domain name for the [GATC cookies](https://developers.google.com/analytics/devguides/collection/analyticsjs/domains#implementation). If not set its the website domain, with the www. prefix removed.
91
- * `:user_id` - defines a proc to set the [userId](https://developers.google.com/analytics/devguides/collection/analyticsjs/user-id). Ex: `user_id: lambda { |env| env['rack.session']['user_id'] }` would return the user_id from the session.
91
+ * `:user_id` - defines a proc to set the [userId](https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#user_id). Ex: `user_id: lambda { |env| env['rack.session']['user_id'] }` would return the user_id from the session.
92
92
  * `:site_speed_sample_rate` - Defines a new sample set size for Site Speed data collection, see https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiBasicConfiguration?hl=de#_gat.GA_Tracker_._setSiteSpeedSampleRate
93
93
  * `:adjusted_bounce_rate_timeouts` - An array of times in seconds that the tracker will use to set timeouts for adjusted bounce rate tracking. See http://analytics.blogspot.ca/2012/07/tracking-adjusted-bounce-rate-in-google.html for details.
94
- * `:enhanced_link_attribution` - Enables [Enhanced Link Attribution](https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#enhancedlink).
94
+ * `:enhanced_link_attribution` - Enables [Enhanced Link Attribution](https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-link-attribution).
95
95
  * `:advertising` - Enables [Display Features](https://developers.google.com/analytics/devguides/collection/analyticsjs/display-features).
96
96
  * `:ecommerce` - Enables [Ecommerce Tracking](https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce).
97
97
  * `:enhanced_ecommerce` - Enables [Enhanced Ecommerce Tracking](https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce)
@@ -254,16 +254,26 @@ To add events or variables to the dataLayer from the server side, just call the
254
254
 
255
255
  ### Facebook
256
256
 
257
- * `custom_audience` - adds the [Custom audience](https://developers.facebook.com/docs/reference/ads-api/custom-audience-website-faq) segmentation pixel
257
+ * `Facebook Pixel` - adds the [Facebook Pixel](https://www.facebook.com/business/help/952192354843755)
258
258
 
259
- #### Conversions
259
+ Use in conjunction with the [Facebook Helper](https://developers.facebook.com/docs/facebook-pixel/pixel-helper) to confirm your event fires correctly.
260
260
 
261
- To track [Conversions](https://www.facebook.com/help/435189689870514) from the server side just call the `tracker` method in your controller.
261
+ First, add the following to your config:
262
+
263
+ ```ruby
264
+ config.middleware.use(Rack::Tracker) do
265
+ handler :facebook_pixel, { id: 'PIXEL_ID' }
266
+ end
267
+ ```
268
+
269
+ #### Standard Events
270
+
271
+ To track Standard Events from the server side just call the `tracker` method in your controller.
262
272
 
263
273
  ```ruby
264
274
  def show
265
275
  tracker do |t|
266
- t.facebook :track, { id: '123456789', value: 1, currency: 'EUR' }
276
+ t.facebook_pixel :track, { type: 'Purchase', options: { value: 100, currency: 'USD' } }
267
277
  end
268
278
  end
269
279
  ```
@@ -271,8 +281,9 @@ To track [Conversions](https://www.facebook.com/help/435189689870514) from the s
271
281
  Will result in the following:
272
282
 
273
283
  ```javascript
274
- window._fbq.push(["track", "123456789", {'value': 1, 'currency': 'EUR'}]);
284
+ fbq("track", "Purchase", {"value":"100.0","currency":"USD"});
275
285
  ```
286
+
276
287
  ### Visual website Optimizer (VWO)
277
288
  Just integrate the handler with your matching account_id and you will be ready to go
278
289
 
@@ -538,6 +549,12 @@ end
538
549
  Checkout the existing handlers in `lib/rack/tracker` for some inspiration. :)
539
550
 
540
551
 
552
+ ## Please note
553
+
554
+ Most tracking is done using some kind of Javascript and any tracking data is simply passed on.
555
+ Using unvalidated user input in the tracking might result in [XSS issues](https://en.wikipedia.org/wiki/Cross-site_scripting). Do only use secure data.
556
+
557
+
541
558
  ## Contributing
542
559
 
543
560
  First of all, **thank** you for your help! :green_heart:
@@ -16,6 +16,7 @@ require "rack/tracker/google_analytics/google_analytics"
16
16
  require "rack/tracker/google_tag_manager/google_tag_manager"
17
17
  require "rack/tracker/google_adwords_conversion/google_adwords_conversion"
18
18
  require "rack/tracker/facebook/facebook"
19
+ require "rack/tracker/facebook_pixel/facebook_pixel"
19
20
  require "rack/tracker/vwo/vwo"
20
21
  require "rack/tracker/go_squared/go_squared"
21
22
  require "rack/tracker/criteo/criteo"
@@ -3,7 +3,7 @@ module Rack
3
3
  module Controller
4
4
  def tracker(&block)
5
5
  if block_given?
6
- yield(Rack::Tracker::HandlerDelegator.new(env))
6
+ yield(Rack::Tracker::HandlerDelegator.new(respond_to?(:request) ? request.env : env))
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,3 @@
1
+ PLEAE NOTE! ATTENTION! OBACHT! ACHTUNG!
2
+
3
+ The facebook handler is deprecated. Please use the facebook_pixel handler.
@@ -0,0 +1,27 @@
1
+ class Rack::Tracker::FacebookPixel < Rack::Tracker::Handler
2
+ class Event < OpenStruct
3
+ def write
4
+ options.present? ? type_to_json << options_to_json : type_to_json
5
+ end
6
+
7
+ private
8
+
9
+ def type_to_json
10
+ type.to_json
11
+ end
12
+
13
+ def options_to_json
14
+ ", #{options.to_json}"
15
+ end
16
+ end
17
+
18
+ self.position = :body
19
+
20
+ def render
21
+ Tilt.new( File.join( File.dirname(__FILE__), 'template/facebook_pixel.erb') ).render(self)
22
+ end
23
+
24
+ def self.track(name, *event)
25
+ { name.to_s => [event.last.merge('class_name' => 'Event')] }
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ <script type="text/javascript">
2
+ if (typeof fbq == 'undefined') {
3
+
4
+ !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
5
+ n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
6
+ n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
7
+ t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
8
+ document,'script','//connect.facebook.net/en_US/fbevents.js');
9
+
10
+ fbq('init', '<%= options[:id] %>');
11
+ fbq('track', "PageView");
12
+ }
13
+ </script>
14
+ <noscript>
15
+ <img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=<%= options[:id] %>&ev=PageView&noscript=1"/>
16
+ </noscript>
17
+
18
+ <% if events.any? %>
19
+ <script type="text/javascript">
20
+ <% events.each do |event| %>
21
+ fbq("track", <%= event.write %>);
22
+ <% end %>
23
+ </script>
24
+ <% end %>
@@ -3,6 +3,12 @@
3
3
  dataLayer = [];
4
4
  </script>
5
5
 
6
+ <script>
7
+ dataLayer.push(
8
+ <%= events.map(&:write).join(', ') %>
9
+ );
10
+ </script>
11
+
6
12
  <noscript><iframe src="//www.googletagmanager.com/ns.html?id=<%= container %>"
7
13
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
8
14
  <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
@@ -11,9 +17,4 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
11
17
  '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
12
18
  })(window,document,'script','dataLayer','<%= container %>');</script>
13
19
 
14
- <script>
15
- dataLayer.push(
16
- <%= events.map(&:write).join(', ') %>
17
- );
18
- </script>
19
20
  <% end %>
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Tracker
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
@@ -28,4 +28,8 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "rspec", "~> 3.2"
29
29
  spec.add_development_dependency "capybara", "~> 2.4"
30
30
  spec.add_development_dependency "pry"
31
+ if RUBY_VERSION < "2.0"
32
+ spec.add_development_dependency "mime-types", "< 3.0"
33
+ spec.add_development_dependency "addressable", "< 2.5"
34
+ end
31
35
  end
@@ -0,0 +1,61 @@
1
+ RSpec.describe Rack::Tracker::FacebookPixel do
2
+ # describe Rack::Tracker::FacebookPixel::Event do
3
+
4
+ # subject { described_class.new({id: 'id', foo: 'bar'}) }
5
+
6
+ # describe '#write' do
7
+ # specify { expect(subject.write).to eq(['track', 'id', {foo: 'bar'}].to_json) }
8
+ # end
9
+ # end
10
+
11
+ def env
12
+ {}
13
+ end
14
+
15
+ it 'will be placed in the body' do
16
+ expect(described_class.position).to eq(:body)
17
+ expect(described_class.new(env).position).to eq(:body)
18
+ end
19
+
20
+ describe 'with id' do
21
+ subject { described_class.new(env, id: 'PIXEL_ID').render }
22
+
23
+ it 'will push the tracking events to the queue' do
24
+ expect(subject).to match(%r{fbq\('init', 'PIXEL_ID'\)})
25
+ end
26
+
27
+ it 'will add the noscript fallback' do
28
+ expect(subject).to match(%r{https://www.facebook.com/tr\?id=PIXEL_ID&ev=PageView&noscript=1})
29
+ end
30
+ end
31
+
32
+ describe 'with events' do
33
+ def env
34
+ {
35
+ 'tracker' => {
36
+ 'facebook_pixel' =>
37
+ [
38
+ {
39
+ 'type' => 'Purchase',
40
+ 'class_name' => 'Event',
41
+ 'options' =>
42
+ {
43
+ 'value' => '23',
44
+ 'currency' => 'EUR'
45
+ }
46
+ }
47
+ ]
48
+ }
49
+ }
50
+ end
51
+ subject { described_class.new(env).render }
52
+
53
+ it 'will push the tracking events to the queue' do
54
+ expect(subject).to match(%r{"track", "Purchase", \{"value":"23","currency":"EUR"\}})
55
+ end
56
+
57
+ it 'will add the noscript fallback' do
58
+ expect(subject).to match(%r{https://www.facebook.com/tr\?id=&ev=PageView&noscript=1})
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,17 @@
1
+ require 'support/capybara_app_helper'
2
+
3
+ RSpec.describe "Facebook Pixel Integration" do
4
+ before do
5
+ setup_app(action: :facebook_pixel) do |tracker|
6
+ tracker.handler :facebook_pixel, { id: 'PIXEL_ID' }
7
+ end
8
+ visit '/'
9
+ end
10
+
11
+ subject { page }
12
+
13
+ it "embeds the script tag with tracking event from the controller action" do
14
+ expect(page).to have_content("fbq('init', 'PIXEL_ID');")
15
+ expect(page.body).to include('https://www.facebook.com/tr?id=PIXEL_ID&ev=PageView&noscript=1')
16
+ end
17
+ end
@@ -29,6 +29,13 @@ class MetalController < ActionController::Metal
29
29
  render "metal/index"
30
30
  end
31
31
 
32
+ def facebook_pixel
33
+ tracker do |t|
34
+ t.facebook_pixel :track, { id: 'conversion-event', value: '1', currency: 'EUR' }
35
+ end
36
+ render "metal/index"
37
+ end
38
+
32
39
  def google_analytics
33
40
  tracker do |t|
34
41
  t.google_analytics :ecommerce, { type: 'addTransaction', id: 1234, affiliation: 'Acme Clothing', revenue: 11.99, shipping: 5, tax: 1.29 }
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: 1.1.0
4
+ version: 1.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: 2015-11-10 00:00:00.000000000 Z
12
+ date: 2017-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -153,6 +153,7 @@ files:
153
153
  - Gemfile
154
154
  - Gemfile.rails-3.2
155
155
  - Gemfile.rails-4.2
156
+ - Gemfile.rails-5.1
156
157
  - LICENSE.txt
157
158
  - README.md
158
159
  - Rakefile
@@ -161,8 +162,11 @@ files:
161
162
  - lib/rack/tracker/criteo/criteo.rb
162
163
  - lib/rack/tracker/criteo/template/criteo.erb
163
164
  - lib/rack/tracker/extensions.rb
165
+ - lib/rack/tracker/facebook/README.md
164
166
  - lib/rack/tracker/facebook/facebook.rb
165
167
  - lib/rack/tracker/facebook/template/facebook.erb
168
+ - lib/rack/tracker/facebook_pixel/facebook_pixel.rb
169
+ - lib/rack/tracker/facebook_pixel/template/facebook_pixel.erb
166
170
  - lib/rack/tracker/go_squared/go_squared.rb
167
171
  - lib/rack/tracker/go_squared/template/go_squared.erb
168
172
  - lib/rack/tracker/google_adwords_conversion/google_adwords_conversion.rb
@@ -187,6 +191,7 @@ files:
187
191
  - spec/fixtures/views/layouts/application.html.erb
188
192
  - spec/fixtures/views/metal/index.html.erb
189
193
  - spec/handler/criteo_spec.rb
194
+ - spec/handler/facebook_pixel_spec.rb
190
195
  - spec/handler/facebook_spec.rb
191
196
  - spec/handler/go_squared_spec.rb
192
197
  - spec/handler/google_adwords_conversion_spec.rb
@@ -196,6 +201,7 @@ files:
196
201
  - spec/handler/zanox_spec.rb
197
202
  - spec/integration/criteo_integration_spec.rb
198
203
  - spec/integration/facebook_integration_spec.rb
204
+ - spec/integration/facebook_pixel_integration_spec.rb
199
205
  - spec/integration/go_squared_integration_spec.rb
200
206
  - spec/integration/google_adwords_conversion_integration_spec.rb
201
207
  - spec/integration/google_analytics_integration_spec.rb
@@ -232,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
238
  version: '0'
233
239
  requirements: []
234
240
  rubyforge_project:
235
- rubygems_version: 2.4.5.1
241
+ rubygems_version: 2.4.8
236
242
  signing_key:
237
243
  specification_version: 4
238
244
  summary: Tracking made easy
@@ -243,6 +249,7 @@ test_files:
243
249
  - spec/fixtures/views/layouts/application.html.erb
244
250
  - spec/fixtures/views/metal/index.html.erb
245
251
  - spec/handler/criteo_spec.rb
252
+ - spec/handler/facebook_pixel_spec.rb
246
253
  - spec/handler/facebook_spec.rb
247
254
  - spec/handler/go_squared_spec.rb
248
255
  - spec/handler/google_adwords_conversion_spec.rb
@@ -252,6 +259,7 @@ test_files:
252
259
  - spec/handler/zanox_spec.rb
253
260
  - spec/integration/criteo_integration_spec.rb
254
261
  - spec/integration/facebook_integration_spec.rb
262
+ - spec/integration/facebook_pixel_integration_spec.rb
255
263
  - spec/integration/go_squared_integration_spec.rb
256
264
  - spec/integration/google_adwords_conversion_integration_spec.rb
257
265
  - spec/integration/google_analytics_integration_spec.rb