rack-tracker 1.12.0 → 1.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/rack/tracker.rb +9 -7
- data/lib/rack/tracker/google_analytics/template/google_analytics.erb +31 -31
- 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/version.rb +1 -1
- data/spec/integration/google_global_integration_spec.rb +19 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ba26127c80f03ca9e62148bcc7bed290e716f268ee5b0db44ab0e8f0bfda6b7
|
4
|
+
data.tar.gz: 53c75c93dc91a11a0d55e2b415ce3f4a4045ea5c36e0bf3f606f7b2174c0ec02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a50ac45ea4aed6309bdf29b910b2d86ef25a1b1543c1d322ee51932711cc929e9ce5acd068f2785ed9dbb124ac991cb238741f3d06c6c189075b684e11b30734
|
7
|
+
data.tar.gz: 36a514edc61a4d2b1357ac347610749fba442cf7f16da4457b20749ae3545327d7ea793e75d127ad84def56b00165ccbb4cbf79fa5e2982f1636b677926e47f2
|
data/CHANGELOG.md
CHANGED
data/lib/rack/tracker.rb
CHANGED
@@ -38,10 +38,14 @@ module Rack
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def call(env)
|
41
|
-
|
42
|
-
|
43
|
-
|
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/
|
44
47
|
|
48
|
+
response = Rack::Response.new([], status, headers)
|
45
49
|
env[EVENT_TRACKING_KEY] ||= {}
|
46
50
|
|
47
51
|
if session = env["rack.session"]
|
@@ -52,16 +56,14 @@ module Rack
|
|
52
56
|
session[EVENT_TRACKING_KEY] = env[EVENT_TRACKING_KEY]
|
53
57
|
end
|
54
58
|
|
55
|
-
|
56
|
-
|
59
|
+
body.each { |fragment| response.write inject(env, fragment) }
|
60
|
+
body.close if body.respond_to?(:close)
|
57
61
|
|
58
62
|
response.finish
|
59
63
|
end
|
60
64
|
|
61
65
|
private
|
62
66
|
|
63
|
-
def html?; @headers['Content-Type'] =~ /html/; end
|
64
|
-
|
65
67
|
def inject(env, response)
|
66
68
|
duplicated_response = response.dup
|
67
69
|
@handlers.each(env) do |handler|
|
@@ -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 && options[:explicit_pageview] %>
|
42
|
-
ga('send', 'pageview', <%= pageview_url_script %>);
|
43
43
|
</script>
|
44
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
|
data/lib/rack/tracker/version.rb
CHANGED
@@ -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
|
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.12.
|
4
|
+
version: 1.12.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:
|
12
|
+
date: 2020-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|