Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bul-ikana/hugo-cards.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbalabtech <balabtech@hotmail.com>2021-01-05 01:47:14 +0300
committerbalabtech <balabtech@hotmail.com>2021-01-05 01:47:14 +0300
commitb94d995c1c182b7a1843f269bb61af00ffbb3f25 (patch)
treeaa4b2782a57fc3e3bbf3d0662db711cd54541215
parent1785f7722183aca70c3f84b9841a0f0d8cd88519 (diff)
Adding support for Google Analytics 4 version change
-rw-r--r--README.md2
-rw-r--r--exampleSite/config.toml4
-rw-r--r--layouts/partials/analytics.html20
3 files changed, 21 insertions, 5 deletions
diff --git a/README.md b/README.md
index 87cd681..328f188 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ The title of the like box. This text will be shown while the box is loading.
### Tracking and comments
#### analytics
-The Google Analytics tracking ID
+The Google Analytics tracking ID supporting both Universal Analytics and GA4
#### disqus
The disqus_thread ID
diff --git a/exampleSite/config.toml b/exampleSite/config.toml
index c1b498e..b134895 100644
--- a/exampleSite/config.toml
+++ b/exampleSite/config.toml
@@ -25,6 +25,10 @@ paginate = 6
custom_css = ["css/custom.css"]
+ [params.analytics]
+ type=""
+ trackingID = ""
+
[params.copyright]
name = "bool"
link = "https://bool.netlify.com"
diff --git a/layouts/partials/analytics.html b/layouts/partials/analytics.html
index caa8fe1..ddeeb3e 100644
--- a/layouts/partials/analytics.html
+++ b/layouts/partials/analytics.html
@@ -1,10 +1,22 @@
- <!-- Google Analytics Tracking code -->
-<script>
+{{ if eq .type "UA" }}
+ <!-- UA Tracking type Google Analytics Tracking code -->
+ <script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
- ga('create', '{{.}}', 'auto');
+ ga('create', '{{ .trackingID }}', 'auto');
ga('send', 'pageview');
-</script> \ No newline at end of file
+</script>
+{{ else }}
+<!-- GA4 type - Global site tag (gtag.js) - Google Analytics -->
+<script async src="https://www.googletagmanager.com/gtag/js?id={{ .trackingID }}"></script>
+<script>
+ window.dataLayer = window.dataLayer || [];
+ function gtag(){dataLayer.push(arguments);}
+ gtag('js', new Date());
+
+ gtag('config', '{{ .trackingID }}');
+</script>
+{{ end }} \ No newline at end of file