card-mod-google_analytics 0.13.2 → 0.15
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/README.md +29 -0
- data/set/all/google_analytics.rb +24 -11
- data/set/all/google_analytics_noscript.haml +8 -0
- data/set/all/google_analytics_snippets.haml +36 -0
- metadata +12 -16
- data/set/all/google_analytics_snippet.haml +0 -13
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/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
# @title README - mod: google analytics
|
|
3
|
+
-->
|
|
4
|
+
|
|
5
|
+
# Google Analytics mod
|
|
6
|
+
|
|
7
|
+
This mod supports the inclusion of Google Analytics snippets in the `<head>` tag
|
|
8
|
+
of Decko pages.
|
|
9
|
+
|
|
10
|
+
_Note: this mod currently supports only Universal Analytics, but GA4 support is
|
|
11
|
+
coming soon._
|
|
12
|
+
|
|
13
|
+
## Client-side tracking: Snippets
|
|
14
|
+
|
|
15
|
+
To add a snippet, Monkeys can add a universal analytics key for your GA property
|
|
16
|
+
to `config.google_analytics_key`. Sharks can also edit
|
|
17
|
+
the `:google_analytics_key` card.
|
|
18
|
+
|
|
19
|
+
## Server-side tracking (experimental)
|
|
20
|
+
|
|
21
|
+
It is possible to send information to Google Analytics about server requests
|
|
22
|
+
that never go through a browser (and therefore can't be captured using
|
|
23
|
+
snippets). Any request for which the method `#track_page_from_server?`
|
|
24
|
+
returns true for the main card will send information to the Google Analytics
|
|
25
|
+
account configured. If you want these requests to go to a different property
|
|
26
|
+
(which is recommended, because without the extra browser information, these
|
|
27
|
+
requests have far less metadata and are thus harder for GA to interpret as
|
|
28
|
+
part of continuous user journeys), then you can add a key for that property
|
|
29
|
+
using `config.google_analytics_tracker_key`.
|
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
|
-
|
|
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,31 +1,30 @@
|
|
|
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
|
-
- Ethan McCutchen
|
|
8
7
|
- Philipp Kühl
|
|
9
|
-
-
|
|
8
|
+
- Ethan McCutchen
|
|
10
9
|
autorequire:
|
|
11
10
|
bindir: bin
|
|
12
11
|
cert_chain: []
|
|
13
|
-
date: 2021-
|
|
12
|
+
date: 2021-12-23 00:00:00.000000000 Z
|
|
14
13
|
dependencies:
|
|
15
14
|
- !ruby/object:Gem::Dependency
|
|
16
15
|
name: card
|
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
|
18
17
|
requirements:
|
|
19
|
-
- -
|
|
18
|
+
- - ">="
|
|
20
19
|
- !ruby/object:Gem::Version
|
|
21
|
-
version:
|
|
20
|
+
version: '0'
|
|
22
21
|
type: :runtime
|
|
23
22
|
prerelease: false
|
|
24
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
24
|
requirements:
|
|
26
|
-
- -
|
|
25
|
+
- - ">="
|
|
27
26
|
- !ruby/object:Gem::Version
|
|
28
|
-
version:
|
|
27
|
+
version: '0'
|
|
29
28
|
- !ruby/object:Gem::Dependency
|
|
30
29
|
name: staccato
|
|
31
30
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -47,18 +46,15 @@ executables: []
|
|
|
47
46
|
extensions: []
|
|
48
47
|
extra_rdoc_files: []
|
|
49
48
|
files:
|
|
49
|
+
- README.md
|
|
50
50
|
- lib/card/mod/google_analytics.rb
|
|
51
51
|
- set/all/google_analytics.rb
|
|
52
|
-
- set/all/
|
|
53
|
-
|
|
52
|
+
- set/all/google_analytics_noscript.haml
|
|
53
|
+
- set/all/google_analytics_snippets.haml
|
|
54
|
+
homepage: http://decko.org
|
|
54
55
|
licenses:
|
|
55
56
|
- GPL-3.0
|
|
56
57
|
metadata:
|
|
57
|
-
source_code_uri: https://github.com/decko-commons/decko
|
|
58
|
-
homepage_uri: https://decko.org
|
|
59
|
-
bug_tracker_uri: https://github.com/decko-commons/decko/issues
|
|
60
|
-
wiki_uri: https://decko.org
|
|
61
|
-
documentation_url: http://docs.decko.org/
|
|
62
58
|
card-mod: google_analytics
|
|
63
59
|
post_install_message:
|
|
64
60
|
rdoc_options: []
|
|
@@ -75,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
75
71
|
- !ruby/object:Gem::Version
|
|
76
72
|
version: '0'
|
|
77
73
|
requirements: []
|
|
78
|
-
rubygems_version: 3.
|
|
74
|
+
rubygems_version: 3.2.15
|
|
79
75
|
signing_key:
|
|
80
76
|
specification_version: 4
|
|
81
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
|