card-mod-google_analytics 0.14 → 0.15
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c957d1bd240ffbdb77a69deb65a4c19837bdf554fdf7aa2e9365405b4881558b
|
4
|
+
data.tar.gz: bbd312be50e17bed094781042b2bd56a3f8e552a430c8cbae0ca52b7b853fa9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e2dd623747ace80b0149f8fc5ec399d843e16011ce35d17a50f2cfe8d5c9f66c44c4da1f976b0af606d3e62237004f016b6869ad2cbb1c2651d26bbf11afb0c
|
7
|
+
data.tar.gz: e7a718192871a2cd1f5c1cbd092c789c594d7d5a0ffe05da9c04702d5f229ceaa1096114ce5ebd7babe82899962e220d2818453ff20bd64915c9e81cce37b4f1
|
data/set/all/google_analytics.rb
CHANGED
@@ -8,20 +8,19 @@ def track_page!
|
|
8
8
|
tracker.pageview tracker_options
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
Card.config.google_analytics_key
|
11
|
+
def google_analytics_keys
|
12
|
+
@google_analytics_keys ||= Array.wrap(
|
13
|
+
Card::Rule.global_setting(:google_analytics_key) || Card.config.google_analytics_key
|
14
|
+
)
|
16
15
|
end
|
17
16
|
|
18
17
|
def tracker
|
19
18
|
tracker_key && ::Staccato.tracker(tracker_key) # , nil, ssl: true
|
20
19
|
end
|
21
20
|
|
22
|
-
# can
|
21
|
+
# can have separate keys for web and API
|
23
22
|
def tracker_key
|
24
|
-
Card.config.google_analytics_tracker_key ||
|
23
|
+
Card.config.google_analytics_tracker_key || google_analytics_keys.first
|
25
24
|
end
|
26
25
|
|
27
26
|
def tracker_options
|
@@ -41,14 +40,28 @@ def track_page_from_server?
|
|
41
40
|
end
|
42
41
|
|
43
42
|
format :html do
|
44
|
-
delegate :
|
43
|
+
delegate :google_analytics_keys, to: :card
|
44
|
+
|
45
|
+
def body_tag klasses=""
|
46
|
+
super { "#{render(:google_analytics_noscript)}\n\n#{yield}" }
|
47
|
+
end
|
45
48
|
|
46
49
|
def views_in_head
|
47
|
-
super
|
50
|
+
super.unshift :google_analytics_snippets
|
51
|
+
end
|
52
|
+
|
53
|
+
view :google_analytics_snippets, unknown: true, perms: :none do
|
54
|
+
haml :google_analytics_snippets if google_analytics_keys.present?
|
55
|
+
end
|
56
|
+
|
57
|
+
view :google_analytics_noscript, unknown: true, perms: :none do
|
58
|
+
haml :google_analytics_noscript if google_tag_manager_keys.present?
|
48
59
|
end
|
49
60
|
|
50
|
-
|
51
|
-
|
61
|
+
def google_tag_manager_keys
|
62
|
+
@google_tag_manager_keys ||= google_analytics_keys.find_all do |key|
|
63
|
+
key.match?(/^GTM-/)
|
64
|
+
end
|
52
65
|
end
|
53
66
|
|
54
67
|
def google_analytics_snippet_vars
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/ Google Tag Manager (noscript)
|
2
|
+
- google_tag_manager_keys.each do |ga_key|
|
3
|
+
%noscript
|
4
|
+
%iframe{ src: "https://www.googletagmanager.com/ns.html?id=#{ga_key}",
|
5
|
+
height: "0",
|
6
|
+
width: "0",
|
7
|
+
style: "display:none;visibility:hidden" }
|
8
|
+
/ End Google Tag Manager (noscript)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/ Google Analytics
|
2
|
+
- google_analytics_keys.each do |ga_key|
|
3
|
+
- case ga_key
|
4
|
+
- when /^UA-/
|
5
|
+
/ Universal Analytics Tag (analytics.js)
|
6
|
+
%script
|
7
|
+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
8
|
+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
9
|
+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
10
|
+
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
11
|
+
|
12
|
+
ga('create', '#{ga_key}', 'auto');
|
13
|
+
- google_analytics_snippet_vars.each do |key, value|
|
14
|
+
- value = "'#{value}'" if value.is_a? String
|
15
|
+
ga('set', '#{key}', #{value})
|
16
|
+
ga('send', 'pageview');
|
17
|
+
|
18
|
+
- when /^G-/
|
19
|
+
/ Global site tag (gtag.js)
|
20
|
+
%script{ async: true, src: "https://www.googletagmanager.com/gtag/js?id=#{ga_key}" }
|
21
|
+
%script
|
22
|
+
window.dataLayer = window.dataLayer || [];
|
23
|
+
function gtag(){dataLayer.push(arguments);}
|
24
|
+
gtag('js', new Date());
|
25
|
+
= "gtag('config', '#{ga_key}');"
|
26
|
+
|
27
|
+
- when /^GTM-/
|
28
|
+
/ Google Tag Manager (gtm.js)
|
29
|
+
%script
|
30
|
+
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
31
|
+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
32
|
+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
33
|
+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
34
|
+
})(window,document,'script','dataLayer','#{ga_key}');
|
35
|
+
|
36
|
+
/ End Google Analytics
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: card-mod-google_analytics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.15'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philipp Kühl
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: card
|
@@ -49,7 +49,8 @@ files:
|
|
49
49
|
- README.md
|
50
50
|
- lib/card/mod/google_analytics.rb
|
51
51
|
- set/all/google_analytics.rb
|
52
|
-
- set/all/
|
52
|
+
- set/all/google_analytics_noscript.haml
|
53
|
+
- set/all/google_analytics_snippets.haml
|
53
54
|
homepage: http://decko.org
|
54
55
|
licenses:
|
55
56
|
- GPL-3.0
|
@@ -70,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
71
|
- !ruby/object:Gem::Version
|
71
72
|
version: '0'
|
72
73
|
requirements: []
|
73
|
-
rubygems_version: 3.2.
|
74
|
+
rubygems_version: 3.2.15
|
74
75
|
signing_key:
|
75
76
|
specification_version: 4
|
76
77
|
summary: Google Analytics support for decko
|
@@ -1,13 +0,0 @@
|
|
1
|
-
/ Google Analytics
|
2
|
-
%script
|
3
|
-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
4
|
-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
5
|
-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
6
|
-
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
7
|
-
|
8
|
-
ga('create', '#{google_analytics_key}', 'auto');
|
9
|
-
- google_analytics_snippet_vars.each do |key, value|
|
10
|
-
- value = "'#{value}'" if value.is_a? String
|
11
|
-
ga('set', '#{key}', #{value})
|
12
|
-
ga('send', 'pageview');
|
13
|
-
/ End Google Analytics
|