diff options
author | Roger Gonzalez <roger@rogs.me> | 2023-01-08 22:12:24 -0300 |
---|---|---|
committer | Roger Gonzalez <roger@rogs.me> | 2023-01-08 22:12:24 -0300 |
commit | b15ab4adb837e43409e5e3cf3a40a83ef4dbf62f (patch) | |
tree | 3b7d7e5dc84aabc839dd1d9174c4593cbd6b2f82 /themes/hugo-whisper-theme/layouts/partials/google-analytics.html |
Initial commit
Diffstat (limited to 'themes/hugo-whisper-theme/layouts/partials/google-analytics.html')
-rw-r--r-- | themes/hugo-whisper-theme/layouts/partials/google-analytics.html | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/themes/hugo-whisper-theme/layouts/partials/google-analytics.html b/themes/hugo-whisper-theme/layouts/partials/google-analytics.html new file mode 100644 index 0000000..63c84ab --- /dev/null +++ b/themes/hugo-whisper-theme/layouts/partials/google-analytics.html @@ -0,0 +1,26 @@ +{{- if .Site.IsServer -}} + <!-- Dont add Google analytics to localhost --> +{{ else }} + {{ $gid := (getenv "HUGO_GOOGLE_ANALYTICS_ID") }} + {{ if $gid }} + <!-- Global site tag (gtag.js) - Google Analytics --> + <script async src="https://www.googletagmanager.com/gtag/js?id={{- $gid -}}"></script> + <script> + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', '{{- $gid -}}'); + </script> + {{ else }} + {{ if .Site.Params.google_analytics_id }} + <!-- Global site tag (gtag.js) - Google Analytics --> + <script async src="https://www.googletagmanager.com/gtag/js?id={{- .Site.Params.google_analytics_id -}}"></script> + <script> + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', '{{- .Site.Params.google_analytics_id -}}'); + </script> + {{ end }} + {{ end}} +{{ end }}
\ No newline at end of file |