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 +4 -4
- data/lib/rack/tracker/google_tag_manager/google_tag_manager.rb +2 -2
- data/lib/rack/tracker/google_tag_manager/template/google_tag_manager_head.erb +3 -6
- data/lib/rack/tracker/version.rb +1 -1
- data/spec/fixtures/views/layouts/application.html.erb +1 -1
- data/spec/integration/google_tag_manager_integration_spec.rb +8 -2
- data/spec/integration/rails_integration_spec.rb +1 -1
- data/spec/support/metal_controller.rb +5 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b072f92694fc92f16f4ef3515e63ce24fd3352a
|
4
|
+
data.tar.gz: 0dd00780794ccee021b5fe148fe5271c33bc6159
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
13
|
+
response.sub! %r{<head.*>} do |m|
|
14
14
|
m.to_s << self.render_head
|
15
15
|
end
|
16
|
-
response.sub! %r{<body
|
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],
|
data/lib/rack/tracker/version.rb
CHANGED
@@ -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(
|
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
|
-
|
52
|
-
|
53
|
-
|
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.
|
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-
|
12
|
+
date: 2017-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|