diff options
author | Hugo Aguirre <bul-ikana@users.noreply.github.com> | 2021-11-01 02:13:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-01 02:13:08 +0300 |
commit | e953bf3bbd01dabece14e86fd76d275325674e61 (patch) | |
tree | aa4b2782a57fc3e3bbf3d0662db711cd54541215 | |
parent | 1785f7722183aca70c3f84b9841a0f0d8cd88519 (diff) | |
parent | b94d995c1c182b7a1843f269bb61af00ffbb3f25 (diff) |
Merge pull request #21 from Balasundaram/master
Adding support for Google Analytics 4 version change
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | exampleSite/config.toml | 4 | ||||
-rw-r--r-- | layouts/partials/analytics.html | 20 |
3 files changed, 21 insertions, 5 deletions
@@ -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 |