Skip to content

Commit

Permalink
Adding support for Google Analytics 4 version change
Browse files Browse the repository at this point in the history
  • Loading branch information
Balasundaram committed Jan 4, 2021
1 parent 1785f77 commit b94d995
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ paginate = 6

custom_css = ["css/custom.css"]

[params.analytics]
type=""
trackingID = ""

[params.copyright]
name = "bool"
link = "https://bool.netlify.com"
Expand Down
20 changes: 16 additions & 4 deletions layouts/partials/analytics.html
Original file line number Diff line number Diff line change
@@ -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>
</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 }}

0 comments on commit b94d995

Please sign in to comment.