Last active
April 12, 2021 10:40
-
-
Save n0nuser/0a77fe4412298a2d9815f406d19a3572 to your computer and use it in GitHub Desktop.
Using Google Analytics 4 with GoHugo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Page settings | |
baseURL = "baseurl" | |
languageCode = "en" | |
title = "Hey! I'm using GA4" | |
[markup] | |
[markup.goldmark] | |
[markup.goldmark.renderer] | |
unsafe = true | |
[params] | |
# Google Analytics | |
GA4 = "G-XXXXXXXXXX" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ $googleID := (printf "%#s" $.Site.Params.ga4 ) }} | |
{{ $googleURL := (printf "https://www.googletagmanager.com/gtag/js?id=%s" $googleID) }} | |
<!-- Global site tag (gtag.js) - Google Analytics --> | |
{{ with $googleURL }}<script async src="{{ . }}"></script>{{ end }} | |
{{ with $googleID }}<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments);} | |
gtag('js', new Date()); | |
gtag('config', '{{ . }}'); | |
</script> {{ end }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment