rack-tracker 1.3.0 → 1.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a48bd3ebea8da26e68cf92e916f68f0dc7beabf
4
- data.tar.gz: 70724503d65e0fae7e652de8c97e8c89d66e941e
3
+ metadata.gz: 6b072f92694fc92f16f4ef3515e63ce24fd3352a
4
+ data.tar.gz: 0dd00780794ccee021b5fe148fe5271c33bc6159
5
5
  SHA512:
6
- metadata.gz: a575794387624e7c5281940caf991b35b663885974313c38184613aaf2f12e4c6f06ae40d52af4f5175d90e7f2bd29865951cd8434cf8e9ff6d3d41c96d343b2
7
- data.tar.gz: 03c9e701bc4e2167f218b986b436f9b1eb0e6e13f56257a5de2f4792e8a61165b32800dd2a568270c0c1fcd7b9844309ceb5eb17ef75f92209fa049095295987
6
+ metadata.gz: 52f70650a9e1373d9a3cb065f18576466767e3f30ed6709c426d3416e77aefc220b0cf58785c3a6600890b55b0ab6f31dee5bf5d686857047780dd6fe03d04bf
7
+ data.tar.gz: d74de4e71eb7f6ea636edb7caba6b98531782d9a749ca72db0d4b89c05d31ef32d8f88adb2c95dfd5f601609445ae21befe61e51c6cac44d534398a20edde31d
@@ -10,10 +10,10 @@ class Rack::Tracker::GoogleTagManager < Rack::Tracker::Handler
10
10
  # Sub! is enough, in well formed html there's only one head or body tag.
11
11
  # Block syntax need to be used, otherwise backslashes in input will mess the output.
12
12
  # @see http://stackoverflow.com/a/4149087/518204 and https://github.com/railslove/rack-tracker/issues/50
13
- response.sub! %r{<head>} do |m|
13
+ response.sub! %r{<head.*>} do |m|
14
14
  m.to_s << self.render_head
15
15
  end
16
- response.sub! %r{<body>} do |m|
16
+ response.sub! %r{<body.*>} do |m|
17
17
  m.to_s << self.render_body
18
18
  end
19
19
  response
@@ -1,13 +1,10 @@
1
1
  <% if container %>
2
+ <% if events.any? %>
2
3
  <script>
3
4
  dataLayer = [];
5
+ dataLayer.push(<%= events.map(&:write).join(', ') %>);
4
6
  </script>
5
-
6
- <script>
7
- dataLayer.push(
8
- <%= events.map(&:write).join(', ') %>
9
- );
10
- </script>
7
+ <% end %>
11
8
 
12
9
  <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
13
10
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Tracker
3
- VERSION = '1.3.0'
3
+ VERSION = '1.3.1'
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@
2
2
  <head>
3
3
  <title>Metal Layout</title>
4
4
  </head>
5
- <body>
5
+ <body class="do-we-support-attributes-on-the-body-tag">
6
6
  <%= yield %>
7
7
  </body>
8
8
  </html>
@@ -5,15 +5,21 @@ RSpec.describe "Google Tag Manager Integration" do
5
5
  setup_app(action: :google_tag_manager) do |tracker|
6
6
  tracker.handler :google_tag_manager, { container: 'GTM-ABCDEF' }
7
7
  end
8
- visit '/'
9
8
  end
10
9
 
11
10
  subject { page }
12
11
 
13
12
  it "embeds the script tag with tracking event from the controller action" do
13
+ visit '/'
14
14
  expect(page.find("head")).to have_content 'GTM-ABCDEF'
15
- expect(page.find("head")).to have_content "dataLayer.push( {\"click\":\"X\",\"price\":10}, {\"transactionProducts\":[{\"sku\":\"DD44\",\"name\":\"T-shirt\"},{\"sku\":\"DD66\",\"name\":\"Jeans\"}]} );"
15
+ expect(page.find("head")).to have_content "dataLayer.push({\"click\":\"X\",\"price\":10}, {\"transactionProducts\":[{\"sku\":\"DD44\",\"name\":\"T-shirt\"},{\"sku\":\"DD66\",\"name\":\"Jeans\"}]});"
16
16
  expect(page.find("body")).to have_xpath '//body/noscript/iframe[@src="https://www.googletagmanager.com/ns.html?id=GTM-ABCDEF"]'
17
17
  end
18
18
 
19
+ it "does not inject a dataLayer if no events are set " do
20
+ visit '/?no_events=true'
21
+ expect(page.find("head")).to have_content 'GTM-ABCDEF'
22
+ expect(page.find("head")).to_not have_content "dataLayer.push("
23
+ expect(page.find("body")).to have_xpath '//body/noscript/iframe[@src="https://www.googletagmanager.com/ns.html?id=GTM-ABCDEF"]'
24
+ end
19
25
  end
@@ -21,7 +21,7 @@ RSpec.describe "Rails Integration" do
21
21
  myAwesomeFunction("tracks", "like", "no-one-else", "SomeKey123");
22
22
  </script>
23
23
  </head>
24
- <body>
24
+ <body class="do-we-support-attributes-on-the-body-tag">
25
25
  <h1>welcome to metal#index</h1>
26
26
  <script type="text/javascript">
27
27
  anotherFunction("tracks-event-from-down-under", "AnotherKey42");
@@ -48,9 +48,11 @@ class MetalController < ActionController::Metal
48
48
  end
49
49
 
50
50
  def google_tag_manager
51
- tracker do |t|
52
- t.google_tag_manager :push, { click: 'X', price: 10 }
53
- t.google_tag_manager :push, transactionProducts: [{ sku: 'DD44', name: 'T-shirt' }, { sku: 'DD66', name: 'Jeans' }]
51
+ unless params[:no_events]
52
+ tracker do |t|
53
+ t.google_tag_manager :push, { click: 'X', price: 10 }
54
+ t.google_tag_manager :push, transactionProducts: [{ sku: 'DD44', name: 'T-shirt' }, { sku: 'DD66', name: 'Jeans' }]
55
+ end
54
56
  end
55
57
  render "metal/index"
56
58
  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.3.0
4
+ version: 1.3.1
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-06-09 00:00:00.000000000 Z
12
+ date: 2017-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack