rack-tracker 1.11.0 → 1.13.0
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/.travis.yml +10 -0
- data/CHANGELOG.md +22 -0
- data/Gemfile.rails-6.0 +6 -0
- data/README.md +13 -0
- data/lib/rack/tracker.rb +10 -7
- data/lib/rack/tracker/drift/template/drift.erb +1 -1
- data/lib/rack/tracker/google_analytics/google_analytics.rb +5 -0
- data/lib/rack/tracker/google_analytics/template/google_analytics.erb +33 -33
- data/lib/rack/tracker/google_global/google_global.rb +26 -3
- data/lib/rack/tracker/google_global/template/google_global.erb +1 -1
- data/lib/rack/tracker/google_tag_manager/google_tag_manager.rb +1 -1
- data/lib/rack/tracker/google_tag_manager/template/google_tag_manager_head.erb +18 -12
- data/lib/rack/tracker/heap/heap.rb +2 -0
- data/lib/rack/tracker/heap/template/heap.erb +4 -0
- data/lib/rack/tracker/version.rb +1 -1
- data/spec/handler/google_analytics_spec.rb +16 -0
- data/spec/handler/google_tag_manager_spec.rb +23 -0
- data/spec/handler/heap_spec.rb +10 -0
- data/spec/integration/drift_integration_spec.rb +1 -1
- data/spec/integration/google_global_integration_spec.rb +19 -8
- data/spec/integration/google_tag_manager_integration_spec.rb +3 -2
- data/spec/integration/heap_integration_spec.rb +17 -0
- data/spec/integration/rails_integration_spec.rb +16 -7
- data/spec/support/metal_controller.rb +4 -0
- metadata +13 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4942ee895d5b92722012f0238986942a903a0633233f49e30d9f7da65b4496ed
|
4
|
+
data.tar.gz: 7d103f64e4153ae08e38c952fda4395c65617f0534ddd166b31840448f0df22d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8bd7a5bec291496d4f49017a8dfe5572c5f748d9a783922bea3fc9cc47e646cc504d845dd1c2ec86eccbb0cc7592a8834a02e503d4f814ea6eb5d9d9f2738a0
|
7
|
+
data.tar.gz: fbc9b64700eb94ae1ab531b1ea43c4abc6f36084c2799366300f9e9c5ed5a9d8840859ed145a537be6e0a7ca23799991334255a541f42222b917c9d4fa6cb20d
|
data/.travis.yml
CHANGED
@@ -6,8 +6,18 @@ rvm:
|
|
6
6
|
- 2.5.3
|
7
7
|
- 2.6.1
|
8
8
|
- jruby-9.1.10.0
|
9
|
+
- jruby-9.2.7.0
|
9
10
|
gemfile:
|
10
11
|
- Gemfile
|
11
12
|
- Gemfile.rails-3.2
|
12
13
|
- Gemfile.rails-4.2
|
13
14
|
- Gemfile.rails-5.2
|
15
|
+
- Gemfile.rails-6.0
|
16
|
+
matrix:
|
17
|
+
exclude:
|
18
|
+
- rvm: 2.3.8
|
19
|
+
gemfile: Gemfile.rails-6.0
|
20
|
+
- rvm: 2.4.5
|
21
|
+
gemfile: Gemfile.rails-6.0
|
22
|
+
- rvm: jruby-9.1.10.0
|
23
|
+
gemfile: Gemfile.rails-6.0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
# 1.13.0
|
2
|
+
|
3
|
+
* [ENHANCEMENT] hotwired/turbo support #160 (thx @wrozka)
|
4
|
+
* [BUGFIX] Use leftmost match for gtm tag injection #156 (thx @yutoji)
|
5
|
+
|
6
|
+
# 1.12.1
|
7
|
+
|
8
|
+
* [ENHANCEMENT] Use local variables to prevent instance state #151 (thx @bumi)
|
9
|
+
* [ENHANCEMENT] Make middleware thread safe #150 (thx @kspe)
|
10
|
+
|
11
|
+
# 1.12.0
|
12
|
+
|
13
|
+
* [ENHANCEMENT] Add support for Heap #147 (thx @mohanzhang)
|
14
|
+
|
15
|
+
# 1.11.2
|
16
|
+
|
17
|
+
* [ENHANCEMENT] Allows disabling the Google Analytics pageview send. Defaults to true #131 (thx @ChrisCoffey)
|
18
|
+
|
19
|
+
# 1.11.1
|
20
|
+
|
21
|
+
* [BUGFIX] Uncaught ReferenceError Fix: wrap Drift account ID in quotes #140 (thx @sassela)
|
22
|
+
|
1
23
|
# 1.11.0
|
2
24
|
|
3
25
|
* [ENHANCEMENT] Add support for Drift #139 (thx @sassela)
|
data/Gemfile.rails-6.0
ADDED
data/README.md
CHANGED
@@ -140,6 +140,7 @@ end
|
|
140
140
|
* `:enhanced_ecommerce` - Enables [Enhanced Ecommerce Tracking](https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce)
|
141
141
|
* `:optimize` - pass [Google Optimize container ID](https://support.google.com/360suite/optimize/answer/6262084#example-combined-snippet) as value (e.g. `optimize: 'GTM-1234'`).
|
142
142
|
* `:pageview_url_script` - a String containing a custom js script evaluating to the url that shoudl be given to the pageview event. Default to `window.location.pathname + window.location.search`.
|
143
|
+
* `:explicit_pageview` - A boolean that controls whether to send the `pageview` event on pageload. This defaults to true.
|
143
144
|
|
144
145
|
#### Events
|
145
146
|
|
@@ -614,6 +615,18 @@ config.middleware.use(Rack::Tracker) do
|
|
614
615
|
end
|
615
616
|
```
|
616
617
|
|
618
|
+
### Heap
|
619
|
+
|
620
|
+
[Heap](https://heap.io/). Heap has Projects (e.g. "Main") which have multiple
|
621
|
+
Environments (e.g. "Production" or "Development"). `env_id` is therefore the numerical ID
|
622
|
+
that represents the Environment. See Settings -> Projects -> Environments in your dashboard.
|
623
|
+
|
624
|
+
```
|
625
|
+
config.middleware.use(Rack::Tracker) do
|
626
|
+
handler :heap, env_id: 'HEAP_ID'
|
627
|
+
end
|
628
|
+
```
|
629
|
+
|
617
630
|
### Custom Handlers
|
618
631
|
|
619
632
|
Tough we give you handlers for a few tracking services right out of the box, you might
|
data/lib/rack/tracker.rb
CHANGED
@@ -26,6 +26,7 @@ require "rack/tracker/hotjar/hotjar"
|
|
26
26
|
require "rack/tracker/bing/bing"
|
27
27
|
require "rack/tracker/hubspot/hubspot"
|
28
28
|
require "rack/tracker/drift/drift"
|
29
|
+
require "rack/tracker/heap/heap"
|
29
30
|
|
30
31
|
module Rack
|
31
32
|
class Tracker
|
@@ -37,10 +38,14 @@ module Rack
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def call(env)
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
dup._call(env)
|
42
|
+
end
|
43
|
+
|
44
|
+
def _call(env)
|
45
|
+
status, headers, body = @app.call(env)
|
46
|
+
return [status, headers, body] unless headers['Content-Type'] =~ /html/
|
43
47
|
|
48
|
+
response = Rack::Response.new([], status, headers)
|
44
49
|
env[EVENT_TRACKING_KEY] ||= {}
|
45
50
|
|
46
51
|
if session = env["rack.session"]
|
@@ -51,16 +56,14 @@ module Rack
|
|
51
56
|
session[EVENT_TRACKING_KEY] = env[EVENT_TRACKING_KEY]
|
52
57
|
end
|
53
58
|
|
54
|
-
|
55
|
-
|
59
|
+
body.each { |fragment| response.write inject(env, fragment) }
|
60
|
+
body.close if body.respond_to?(:close)
|
56
61
|
|
57
62
|
response.finish
|
58
63
|
end
|
59
64
|
|
60
65
|
private
|
61
66
|
|
62
|
-
def html?; @headers['Content-Type'] =~ /html/; end
|
63
|
-
|
64
67
|
def inject(env, response)
|
65
68
|
duplicated_response = response.dup
|
66
69
|
@handlers.each(env) do |handler|
|
@@ -2,6 +2,11 @@ class Rack::Tracker::GoogleAnalytics < Rack::Tracker::Handler
|
|
2
2
|
|
3
3
|
self.allowed_tracker_options = [:cookie_domain, :user_id]
|
4
4
|
|
5
|
+
def initialize(env, options = {})
|
6
|
+
options[:explicit_pageview] = true if !options.has_key?(:explicit_pageview)
|
7
|
+
super(env, options)
|
8
|
+
end
|
9
|
+
|
5
10
|
class Send < OpenStruct
|
6
11
|
def initialize(attrs = {})
|
7
12
|
attrs.reverse_merge!(type: 'event')
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<script type="text/javascript">
|
2
1
|
<% if tracker %>
|
2
|
+
<script type="text/javascript">
|
3
3
|
if(typeof ga === 'undefined') {
|
4
4
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
5
5
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
@@ -8,37 +8,37 @@
|
|
8
8
|
|
9
9
|
ga('create', '<%= tracker %>', <%= tracker_options.to_json %>);
|
10
10
|
}
|
11
|
-
<% if options[:enhanced_link_attribution] %>
|
12
|
-
|
13
|
-
<% end %>
|
14
|
-
<% if options[:advertising] %>
|
15
|
-
|
16
|
-
<% end %>
|
17
|
-
<% if options[:enhanced_ecommerce] %>
|
18
|
-
|
19
|
-
<% end %>
|
20
|
-
<% if options[:ecommerce] %>
|
21
|
-
|
22
|
-
<% end %>
|
23
|
-
<% if options[:optimize] %>
|
24
|
-
|
25
|
-
<% end %>
|
26
|
-
<% if options[:anonymize_ip] %>
|
27
|
-
|
28
|
-
<% end %>
|
29
|
-
<% if options[:adjusted_bounce_rate_timeouts] %>
|
30
|
-
|
31
|
-
|
11
|
+
<% if options[:enhanced_link_attribution] %>
|
12
|
+
ga('require', 'linkid', 'linkid.js');
|
13
|
+
<% end %>
|
14
|
+
<% if options[:advertising] %>
|
15
|
+
ga('require', 'displayfeatures');
|
16
|
+
<% end %>
|
17
|
+
<% if options[:enhanced_ecommerce] %>
|
18
|
+
ga('require', 'ec');
|
19
|
+
<% end %>
|
20
|
+
<% if options[:ecommerce] %>
|
21
|
+
ga('require', 'ecommerce', 'ecommerce.js');
|
22
|
+
<% end %>
|
23
|
+
<% if options[:optimize] %>
|
24
|
+
ga('require', '<%= options[:optimize] %>');
|
25
|
+
<% end %>
|
26
|
+
<% if options[:anonymize_ip] %>
|
27
|
+
ga('set', 'anonymizeIp', true);
|
28
|
+
<% end %>
|
29
|
+
<% if options[:adjusted_bounce_rate_timeouts] %>
|
30
|
+
<% options[:adjusted_bounce_rate_timeouts].each do |timeout| %>
|
31
|
+
setTimeout(function() { ga('send', 'event', '<%= "#{timeout.to_s}_seconds" %>', 'read'); },<%= timeout*1000 %>);
|
32
|
+
<% end %>
|
33
|
+
<% end %>
|
34
|
+
<% events.each do |var| %>
|
35
|
+
ga(<%= var.write() %>);
|
36
|
+
<% end %>
|
37
|
+
<% if options[:ecommerce] && ecommerce_events.any? %>
|
38
|
+
ga('ecommerce:send');
|
39
|
+
<% end %>
|
40
|
+
<% if tracker && options[:explicit_pageview] %>
|
41
|
+
ga('send', 'pageview', <%= pageview_url_script %>);
|
32
42
|
<% end %>
|
33
|
-
<% end %>
|
34
|
-
<% end %>
|
35
|
-
<% events.each do |var| %>
|
36
|
-
ga(<%= var.write() %>);
|
37
|
-
<% end %>
|
38
|
-
<% if options[:ecommerce] && ecommerce_events.any? %>
|
39
|
-
ga('ecommerce:send');
|
40
|
-
<% end %>
|
41
|
-
<% if tracker %>
|
42
|
-
ga('send', 'pageview', <%= pageview_url_script %>);
|
43
|
-
<% end %>
|
44
43
|
</script>
|
44
|
+
<% end %>
|
@@ -35,9 +35,7 @@ class Rack::Tracker::GoogleGlobal < Rack::Tracker::Handler
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def trackers
|
38
|
-
|
39
|
-
tracker[:id].respond_to?(:call) ? tracker.merge(id: tracker[:id].call(env)) : tracker
|
40
|
-
}.reject { |tracker| tracker[:id].nil? }
|
38
|
+
@_trackers ||= build_trackers
|
41
39
|
end
|
42
40
|
|
43
41
|
def set_options
|
@@ -46,6 +44,31 @@ class Rack::Tracker::GoogleGlobal < Rack::Tracker::Handler
|
|
46
44
|
|
47
45
|
private
|
48
46
|
|
47
|
+
def build_trackers
|
48
|
+
options[:trackers].map(&method(:call_tracker)).reject(&method(:invalid_tracker?))
|
49
|
+
end
|
50
|
+
|
51
|
+
def call_tracker(tracker)
|
52
|
+
if tracker[:id].respond_to?(:call)
|
53
|
+
tracker.merge(id: tracker[:id].call(env))
|
54
|
+
else
|
55
|
+
tracker
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def invalid_tracker?(tracker)
|
60
|
+
if tracker[:id].to_s.strip == ''
|
61
|
+
$stdout.puts <<~WARN
|
62
|
+
WARNING: One of the trackers specified for Rack::Tracker handler 'google_global' is empty.
|
63
|
+
Trackers: #{options[:trackers]}
|
64
|
+
WARN
|
65
|
+
|
66
|
+
true
|
67
|
+
else
|
68
|
+
false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
49
72
|
def build_set_options
|
50
73
|
value = options[:set]
|
51
74
|
value.respond_to?(:call) ? value.call(env) : value
|
@@ -10,7 +10,7 @@ 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
16
|
response.sub! %r{<body.*?>} do |m|
|
@@ -1,23 +1,29 @@
|
|
1
1
|
<% if container %>
|
2
|
-
<% unless options[:turbolinks] %>
|
3
|
-
<% if events.any? %>
|
4
|
-
<script>
|
5
|
-
dataLayer = [];
|
6
|
-
dataLayer.push(<%= events.map(&:write).join(', ') %>);
|
7
|
-
</script>
|
8
|
-
<% end %>
|
9
|
-
<% end %>
|
10
|
-
|
11
2
|
<script>
|
3
|
+
dataLayer = [];
|
4
|
+
|
12
5
|
<% if options[:turbolinks] %>
|
13
6
|
document.addEventListener('turbolinks:load', function(event) {
|
14
7
|
var url = event.data.url;
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
dataLayer.push({'event':'pageView','virtualUrl': url});
|
9
|
+
});
|
10
|
+
document.addEventListener('turbo:load', function(event) {
|
11
|
+
var url = event.detail.url;
|
18
12
|
dataLayer.push({'event':'pageView','virtualUrl': url});
|
19
13
|
});
|
20
14
|
<% end %>
|
15
|
+
</script>
|
16
|
+
|
17
|
+
<% if events.any? %>
|
18
|
+
<script>
|
19
|
+
<%# Generates unique script tags to ensure that turbo/turbolinks include %>
|
20
|
+
<%# them in the document even if the same event happens more than once %>
|
21
|
+
// Unique Script ID: <%= SecureRandom.base64(8) %>
|
22
|
+
dataLayer.push(<%= events.map(&:write).join(', ') %>);
|
23
|
+
</script>
|
24
|
+
<% end %>
|
25
|
+
|
26
|
+
<script>
|
21
27
|
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
22
28
|
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
23
29
|
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<script>
|
2
|
+
window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=t.forceSSL||"https:"===document.location.protocol,a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=(r?"https:":"http:")+"//cdn.heapanalytics.com/js/heap-"+e+".js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n);for(var o=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","removeEventProperty","setEventProperties","track","unsetEventProperty"],c=0;c<p.length;c++)heap[p[c]]=o(p[c])};
|
3
|
+
heap.load("<%= options[:env_id] %>");
|
4
|
+
</script>
|
data/lib/rack/tracker/version.rb
CHANGED
@@ -284,5 +284,21 @@ RSpec.describe Rack::Tracker::GoogleAnalytics do
|
|
284
284
|
expect(subject.pageview_url_script).to eql ("{ 'page': location.pathname + location.search + location.hash }")
|
285
285
|
end
|
286
286
|
end
|
287
|
+
|
288
|
+
context 'with explicit_pageview disabled' do
|
289
|
+
subject { described_class.new(env, {tracker: 'afake', explicit_pageview: false }).render }
|
290
|
+
|
291
|
+
it 'does not send a pageview event' do
|
292
|
+
expect(subject).not_to include %q{ga('send', 'pageview',}
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
context 'defaults to sending the pageview event' do
|
297
|
+
subject { described_class.new(env, {tracker: 'afake'}).render }
|
298
|
+
|
299
|
+
it 'does not send a pageview event' do
|
300
|
+
expect(subject).to include "ga('send', 'pageview'"
|
301
|
+
end
|
302
|
+
end
|
287
303
|
end
|
288
304
|
end
|
@@ -32,4 +32,27 @@ RSpec.describe Rack::Tracker::GoogleTagManager do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
describe '#inject' do
|
36
|
+
subject { handler_object.inject(example_response) }
|
37
|
+
let(:handler_object) { described_class.new(env, container: 'somebody') }
|
38
|
+
|
39
|
+
before do
|
40
|
+
allow(handler_object).to receive(:render_head).and_return('<script>"HEAD"</script>')
|
41
|
+
allow(handler_object).to receive(:render_body).and_return('<script>"BODY"</script>')
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with one line html response' do
|
45
|
+
let(:example_response) { "<html><head></head><body></body></html>" }
|
46
|
+
|
47
|
+
it 'will have render_head content in head tag' do
|
48
|
+
expect(subject).to match(%r{<head>.*<script>"HEAD"</script>.*</head>})
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'will have render_body content in body tag' do
|
52
|
+
expect(subject).to match(%r{<body>.*<script>"BODY"</script>.*</body>})
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
35
58
|
end
|
@@ -13,6 +13,6 @@ RSpec.describe 'Drift Integration' do
|
|
13
13
|
|
14
14
|
it 'embeds the script with account_id' do
|
15
15
|
expect(page.find('script')).to have_content('js.driftt.com')
|
16
|
-
expect(page.find('script')).to have_content('DRIFT_ID')
|
16
|
+
expect(page.find('script')).to have_content('drift.load(\'DRIFT_ID\')')
|
17
17
|
end
|
18
18
|
end
|
@@ -3,28 +3,39 @@ require 'support/capybara_app_helper'
|
|
3
3
|
RSpec.describe "Google Global Integration Integration" do
|
4
4
|
before do
|
5
5
|
setup_app(action: :google_global) do |tracker|
|
6
|
-
tracker.handler :google_global,
|
6
|
+
tracker.handler :google_global, tracker_options
|
7
7
|
end
|
8
8
|
visit '/'
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
let(:tracker_options) { { trackers: [{ id: 'U-XXX-Y' }] } }
|
12
12
|
|
13
13
|
it "embeds the script tag with tracking event from the controller action" do
|
14
14
|
expect(page.find("head")).to have_content('U-XXX-Y')
|
15
15
|
end
|
16
16
|
|
17
17
|
describe 'adjust tracker position via options' do
|
18
|
-
|
19
|
-
setup_app(action: :google_global) do |tracker|
|
20
|
-
tracker.handler :google_global, trackers: [{ id: 'U-XXX-Y' }], position: :body
|
21
|
-
end
|
22
|
-
visit '/'
|
23
|
-
end
|
18
|
+
let(:tracker_options) { { trackers: [{ id: 'U-XXX-Y' }], position: :body } }
|
24
19
|
|
25
20
|
it "will be placed in the specified tag" do
|
26
21
|
expect(page.find("head")).to_not have_content('U-XXX-Y')
|
27
22
|
expect(page.find("body")).to have_content('U-XXX-Y')
|
28
23
|
end
|
29
24
|
end
|
25
|
+
|
26
|
+
describe "handles empty tracker id" do
|
27
|
+
let(:tracker_options) { { trackers: [{ id: nil }, { id: "" }, { id: " " }] } }
|
28
|
+
|
29
|
+
it "does not inject scripts" do
|
30
|
+
expect(page.find("head")).to_not have_content("<script async src='https://www.googletagmanager.com/gtag/js?id=")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "callable tracker id" do
|
35
|
+
let(:tracker_options) { { trackers: [{ id: proc { "U-XXX-Y" } }] } }
|
36
|
+
|
37
|
+
it "is injected into head with id from proc" do
|
38
|
+
expect(page.find("head")).to have_content('U-XXX-Y')
|
39
|
+
end
|
40
|
+
end
|
30
41
|
end
|
@@ -23,7 +23,7 @@ RSpec.describe "Google Tag Manager Integration" do
|
|
23
23
|
expect(page.find("body")).to have_xpath '//body/noscript/iframe[@src="https://www.googletagmanager.com/ns.html?id=GTM-ABCDEF"]'
|
24
24
|
end
|
25
25
|
|
26
|
-
it "embeds
|
26
|
+
it "embeds turbolinks and turbo observers if requested" do
|
27
27
|
visit '/'
|
28
28
|
expect(page.find("head")).to_not have_content "turbolinks:load"
|
29
29
|
setup_app(action: :google_tag_manager) do |tracker|
|
@@ -31,5 +31,6 @@ RSpec.describe "Google Tag Manager Integration" do
|
|
31
31
|
end
|
32
32
|
visit '/'
|
33
33
|
expect(page.find("head")).to have_content "turbolinks:load"
|
34
|
+
expect(page.find("head")).to have_content "turbo:load"
|
34
35
|
end
|
35
|
-
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'support/capybara_app_helper'
|
2
|
+
|
3
|
+
RSpec.describe "Heap Integration" do
|
4
|
+
before do
|
5
|
+
setup_app(action: :heap) do |tracker|
|
6
|
+
tracker.handler :heap, { env_id: '12341234' }
|
7
|
+
end
|
8
|
+
|
9
|
+
visit '/'
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { page }
|
13
|
+
|
14
|
+
it 'embeds the script with site_id' do
|
15
|
+
expect(page).to have_content('heap.load("12341234");')
|
16
|
+
end
|
17
|
+
end
|
@@ -1,10 +1,19 @@
|
|
1
1
|
require 'support/capybara_app_helper'
|
2
2
|
|
3
3
|
RSpec.describe "Rails Integration" do
|
4
|
+
let(:callable_skip_inject) do
|
5
|
+
lambda do |env|
|
6
|
+
# check for anything in the env hash to decide
|
7
|
+
# if you return the `tracker id` or `nil` to skip injection
|
8
|
+
nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
before do
|
5
13
|
setup_app(action: :index) do |tracker|
|
6
14
|
tracker.handler :track_all_the_things, { custom_key: 'SomeKey123' }
|
7
15
|
tracker.handler :another_handler, { custom_key: 'AnotherKey42' }
|
16
|
+
tracker.handler :google_analytics, { tracker: callable_skip_inject }
|
8
17
|
end
|
9
18
|
|
10
19
|
visit '/'
|
@@ -17,15 +26,15 @@ RSpec.describe "Rails Integration" do
|
|
17
26
|
<html>
|
18
27
|
<head>
|
19
28
|
<title>Metal Layout</title>
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
<script type="text/javascript">
|
30
|
+
myAwesomeFunction("tracks", "like", "no-one-else", "SomeKey123");
|
31
|
+
</script>
|
32
|
+
</head>
|
24
33
|
<body class="do-we-support-attributes-on-the-body-tag">
|
25
34
|
<h1>welcome to metal#index</h1>
|
26
|
-
|
27
|
-
|
28
|
-
|
35
|
+
<script type="text/javascript">
|
36
|
+
anotherFunction("tracks-event-from-down-under", "AnotherKey42");
|
37
|
+
</script>
|
29
38
|
</body>
|
30
39
|
</html>
|
31
40
|
HTML
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lars Brillert
|
8
8
|
- Marco Schaden
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-07-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -154,6 +154,7 @@ files:
|
|
154
154
|
- Gemfile.rails-3.2
|
155
155
|
- Gemfile.rails-4.2
|
156
156
|
- Gemfile.rails-5.2
|
157
|
+
- Gemfile.rails-6.0
|
157
158
|
- LICENSE.txt
|
158
159
|
- README.md
|
159
160
|
- Rakefile
|
@@ -184,6 +185,8 @@ files:
|
|
184
185
|
- lib/rack/tracker/google_tag_manager/template/google_tag_manager_head.erb
|
185
186
|
- lib/rack/tracker/handler.rb
|
186
187
|
- lib/rack/tracker/handler_delegator.rb
|
188
|
+
- lib/rack/tracker/heap/heap.rb
|
189
|
+
- lib/rack/tracker/heap/template/heap.erb
|
187
190
|
- lib/rack/tracker/hotjar/hotjar.rb
|
188
191
|
- lib/rack/tracker/hotjar/template/hotjar.erb
|
189
192
|
- lib/rack/tracker/hubspot/hubspot.rb
|
@@ -214,6 +217,7 @@ files:
|
|
214
217
|
- spec/handler/google_global_spec.rb
|
215
218
|
- spec/handler/google_tag_manager_spec.rb
|
216
219
|
- spec/handler/handler_spec.rb
|
220
|
+
- spec/handler/heap_spec.rb
|
217
221
|
- spec/handler/hotjar_spec.rb
|
218
222
|
- spec/handler/hubspot_spec.rb
|
219
223
|
- spec/handler/vwo_spec.rb
|
@@ -228,6 +232,7 @@ files:
|
|
228
232
|
- spec/integration/google_analytics_integration_spec.rb
|
229
233
|
- spec/integration/google_global_integration_spec.rb
|
230
234
|
- spec/integration/google_tag_manager_integration_spec.rb
|
235
|
+
- spec/integration/heap_integration_spec.rb
|
231
236
|
- spec/integration/hotjar_integration_spec.rb
|
232
237
|
- spec/integration/hubspot_integration_spec.rb
|
233
238
|
- spec/integration/rails_integration_spec.rb
|
@@ -246,7 +251,7 @@ homepage: https://github.com/railslove/rack-tracker
|
|
246
251
|
licenses:
|
247
252
|
- MIT
|
248
253
|
metadata: {}
|
249
|
-
post_install_message:
|
254
|
+
post_install_message:
|
250
255
|
rdoc_options: []
|
251
256
|
require_paths:
|
252
257
|
- lib
|
@@ -261,8 +266,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
261
266
|
- !ruby/object:Gem::Version
|
262
267
|
version: '0'
|
263
268
|
requirements: []
|
264
|
-
rubygems_version: 3.0.
|
265
|
-
signing_key:
|
269
|
+
rubygems_version: 3.0.8
|
270
|
+
signing_key:
|
266
271
|
specification_version: 4
|
267
272
|
summary: Tracking made easy
|
268
273
|
test_files:
|
@@ -284,6 +289,7 @@ test_files:
|
|
284
289
|
- spec/handler/google_global_spec.rb
|
285
290
|
- spec/handler/google_tag_manager_spec.rb
|
286
291
|
- spec/handler/handler_spec.rb
|
292
|
+
- spec/handler/heap_spec.rb
|
287
293
|
- spec/handler/hotjar_spec.rb
|
288
294
|
- spec/handler/hubspot_spec.rb
|
289
295
|
- spec/handler/vwo_spec.rb
|
@@ -298,6 +304,7 @@ test_files:
|
|
298
304
|
- spec/integration/google_analytics_integration_spec.rb
|
299
305
|
- spec/integration/google_global_integration_spec.rb
|
300
306
|
- spec/integration/google_tag_manager_integration_spec.rb
|
307
|
+
- spec/integration/heap_integration_spec.rb
|
301
308
|
- spec/integration/hotjar_integration_spec.rb
|
302
309
|
- spec/integration/hubspot_integration_spec.rb
|
303
310
|
- spec/integration/rails_integration_spec.rb
|