rack-tracker 1.4.0 → 1.5.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: 369334fdcc3574d943a28e93c42476ce029c226a
4
- data.tar.gz: fcfbf2f2ead245e817a73a097b61ad3f4bf1101f
3
+ metadata.gz: 93dcd33285ad07b72e75cabe697bffa820b2212d
4
+ data.tar.gz: 2cfbf93add60fb26e91bf9f703b3dda0bc9aff95
5
5
  SHA512:
6
- metadata.gz: 7a7ec8fb308171822fb8099dc229c3b881533c0449db0e09fdd0d063682a9a509199b650644dd6b2efacbfec22c7d1c15a3597fd9ca4f3d4b6decacbbecbba46
7
- data.tar.gz: 655b2bb4713d4637bad055fba0aaa0753a9079fb5858746085bd420ba95525743acc5993cb84d7a6d3d1b88858492bbffdab962e0e26624460689d8d2e3be659
6
+ metadata.gz: c10ddd4e7a5abba1887219909bf4480c79a2b5775f81f072cab6cc40df914ec29b6dcce4eaf8609ff8087d284c154aaf6b34c64bb3ae5fb7c524d47c8b5fab26
7
+ data.tar.gz: 42310ccab992b9d71cd5817e1c6cc989cc4271d13c2ac628b3673f12712f9c1a01221e64b27528b622b41dfe4d1d01b74cb2eec9e3f1e2fc5e825a390a0e282a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.5.0
2
+
3
+ * [ENHANCEMENT] facebook pixel now supports non-standard (custom) event names #93
4
+
1
5
  # 1.4.0
2
6
 
3
7
  * [ENHANCEMENT] welcome Hotjar! #90
data/README.md CHANGED
@@ -293,6 +293,15 @@ Will result in the following:
293
293
  fbq("track", "Purchase", {"value":"100.0","currency":"USD"});
294
294
  ```
295
295
 
296
+ You can also use non-standard (custom) event names for audience building when you do not need to track or optimize for conversions.
297
+
298
+ ```
299
+ tracker do |t|
300
+ t.facebook_pixel :track_custom, { type: 'FrequentShopper', options: { purchases: 24, category: 'Sport' } }
301
+ end
302
+ ```
303
+
304
+
296
305
  ### Visual website Optimizer (VWO)
297
306
  Just integrate the handler with your matching account_id and you will be ready to go
298
307
 
@@ -1,4 +1,6 @@
1
1
  class Rack::Tracker::FacebookPixel < Rack::Tracker::Handler
2
+ self.position = :body
3
+
2
4
  class Event < OpenStruct
3
5
  def write
4
6
  options.present? ? type_to_json << options_to_json : type_to_json
@@ -15,9 +17,15 @@ class Rack::Tracker::FacebookPixel < Rack::Tracker::Handler
15
17
  end
16
18
  end
17
19
 
18
- self.position = :body
20
+ class Track < Event
21
+ def name
22
+ 'track'
23
+ end
24
+ end
19
25
 
20
- def self.track(name, *event)
21
- { name.to_s => [event.last.merge('class_name' => 'Event')] }
26
+ class TrackCustom < Event
27
+ def name
28
+ 'trackCustom'
29
+ end
22
30
  end
23
31
  end
@@ -18,7 +18,7 @@
18
18
  <% if events.any? %>
19
19
  <script type="text/javascript">
20
20
  <% events.each do |event| %>
21
- fbq("track", <%= event.write %>);
21
+ fbq("<%= event.name %>", <%= event.write %>);
22
22
  <% end %>
23
23
  </script>
24
24
  <% end %>
@@ -26,8 +26,4 @@ class Rack::Tracker::GoSquared < Rack::Tracker::Handler
26
26
  def visitor_info
27
27
  events.select{|e| e.kind_of?(VisitorInfo) }.first
28
28
  end
29
-
30
- def self.track(name, *event)
31
- { name.to_s => [event.last.merge('class_name' => event.first.to_s.classify)] }
32
- end
33
29
  end
@@ -1,11 +1,6 @@
1
1
  class Rack::Tracker::GoogleAdwordsConversion < Rack::Tracker::Handler
2
-
3
2
  class Conversion < OpenStruct
4
3
  end
5
4
 
6
5
  self.position = :body
7
-
8
- def self.track(name, *event)
9
- { name.to_s => [event.last.merge('class_name' => event.first.to_s.capitalize)] }
10
- end
11
6
  end
@@ -74,8 +74,4 @@ class Rack::Tracker::GoogleAnalytics < Rack::Tracker::Handler
74
74
  def enhanced_ecommerce_events
75
75
  events.select {|e| e.kind_of?(EnhancedEcommerce) }
76
76
  end
77
-
78
- def self.track(name, *event)
79
- { name.to_s => [event.last.merge('class_name' => event.first.to_s.classify)] }
80
- end
81
77
  end
@@ -30,8 +30,4 @@ class Rack::Tracker::GoogleTagManager < Rack::Tracker::Handler
30
30
  def render_body
31
31
  Tilt.new( File.join( File.dirname(__FILE__), 'template', 'google_tag_manager_body.erb') ).render(self)
32
32
  end
33
-
34
- def self.track(name, *event)
35
- { name.to_s => [event.last.merge('class_name' => event.first.to_s.capitalize)] }
36
- end
37
33
  end
@@ -4,8 +4,9 @@ class Rack::Tracker::Handler
4
4
  new(env).write_event(track(method_name, *args, &block))
5
5
  end
6
6
 
7
- def track(name, event)
8
- raise NotImplementedError.new("class method `#{__callee__}` is not implemented.")
7
+ # overwrite me in the handler subclass if you need more control over the event
8
+ def track(name, *event)
9
+ { name.to_s => [event.last.merge('class_name' => event.first.to_s.classify)] }
9
10
  end
10
11
  end
11
12
 
@@ -25,8 +26,8 @@ class Rack::Tracker::Handler
25
26
  end
26
27
 
27
28
  def events
28
- events = env.fetch('tracker', {})[self.class.to_s.demodulize.underscore] || []
29
- events.map{ |ev| "#{self.class}::#{ev['class_name']}".constantize.new(ev.except('class_name')) }
29
+ events = env.fetch('tracker', {})[handler_name] || []
30
+ events.map { |ev| "#{self.class}::#{ev['class_name']}".constantize.new(ev.except('class_name')) }
30
31
  end
31
32
 
32
33
  def render
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Tracker
3
- VERSION = '1.4.0'
3
+ VERSION = '1.5.0'
4
4
  end
5
5
  end
@@ -36,9 +36,4 @@ class Rack::Tracker::Zanox < Rack::Tracker::Handler
36
36
  def sale_events
37
37
  events.select{ |event| event.class.to_s.demodulize == 'Sale' }
38
38
  end
39
-
40
- # this is called with additional arguments to t.zanox
41
- def self.track(name, *event)
42
- { name.to_s => [event.last.merge('class_name' => event.first.to_s.capitalize)] }
43
- end
44
39
  end
@@ -1,13 +1,4 @@
1
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
2
  def env
12
3
  {}
13
4
  end
@@ -37,12 +28,20 @@ RSpec.describe Rack::Tracker::FacebookPixel do
37
28
  [
38
29
  {
39
30
  'type' => 'Purchase',
40
- 'class_name' => 'Event',
31
+ 'class_name' => 'Track',
41
32
  'options' =>
42
33
  {
43
34
  'value' => '23',
44
35
  'currency' => 'EUR'
45
36
  }
37
+ },{
38
+ 'type' => 'FrequentShopper',
39
+ 'class_name' => 'TrackCustom',
40
+ 'options' =>
41
+ {
42
+ 'purchases' => 8,
43
+ 'category' => 'Sport'
44
+ }
46
45
  }
47
46
  ]
48
47
  }
@@ -52,6 +51,7 @@ RSpec.describe Rack::Tracker::FacebookPixel do
52
51
 
53
52
  it 'will push the tracking events to the queue' do
54
53
  expect(subject).to match(%r{"track", "Purchase", \{"value":"23","currency":"EUR"\}})
54
+ expect(subject).to match(%r{"trackCustom", "FrequentShopper", \{"purchases":8,"category":"Sport"\}})
55
55
  end
56
56
 
57
57
  it 'will add the noscript fallback' do
@@ -14,4 +14,13 @@ RSpec.describe "Facebook Pixel Integration" do
14
14
  expect(page).to have_content("fbq('init', 'PIXEL_ID');")
15
15
  expect(page.body).to include('https://www.facebook.com/tr?id=PIXEL_ID&ev=PageView&noscript=1')
16
16
  end
17
+
18
+ it 'tracks multiple events' do
19
+ expect(page.body).to match(/fbq\("track", "Purchase", {\"value\":42,\"currency\":\"USD\"}\);/)
20
+ expect(page.body).to match(/fbq\("track", "CompleteRegistration", {\"value\":0.75,\"currency\":\"EUR\"}\);/)
21
+ end
22
+
23
+ it "can use non-standard event names for audience building" do
24
+ expect(page.body).to match(/fbq\("trackCustom", "FrequentShopper", {\"purchases\":24,\"category\":\"Sport\"}/)
25
+ end
17
26
  end
@@ -43,7 +43,9 @@ class MetalController < ActionController::Metal
43
43
 
44
44
  def facebook_pixel
45
45
  tracker do |t|
46
- t.facebook_pixel :track, { id: 'conversion-event', value: '1', currency: 'EUR' }
46
+ t.facebook_pixel :track, { type: 'Purchase', options: { value: 42, currency: 'USD' } }
47
+ t.facebook_pixel :track, { type: 'CompleteRegistration', options: { value: 0.75, currency: 'EUR' } }
48
+ t.facebook_pixel :track_custom, { type: 'FrequentShopper', options: { purchases: 24, category: 'Sport' } }
47
49
  end
48
50
  render "metal/index"
49
51
  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: 1.4.0
4
+ version: 1.5.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: 2017-08-25 00:00:00.000000000 Z
12
+ date: 2017-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack