Add Google Analytics Partial

This commit is contained in:
Benjamin Hays 2025-05-26 11:29:45 -04:00
parent e6d2204df1
commit 1733418a49
Signed by: BenHays42
GPG Key ID: CE14B8B296ABEFB1
2 changed files with 11 additions and 0 deletions

View File

@ -4,6 +4,7 @@
<head>
{{ partial "head.html" . }}
{{ partial "ga4.html" . }}
</head>
{{ $theme := "auto"}}

10
layouts/partials/ga4.html Normal file
View File

@ -0,0 +1,10 @@
{{ if and (.Site.Params.googleAnalytics.enabled) (.Site.Params.googleAnalytics.ID) }}
<!-- Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ .Site.Params.googleAnalytics.ID }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ .Site.Params.googleAnalytics.ID }}');
</script>
{{ end }}