mirror of https://github.com/lxndrblz/anatole.git

Xen-Echo
10.40.2021 cca288b799f4a0f94e1453810e0ce96b3f3578bf
Adding support for Google Analytics 4 (#149)

1 files added
2 files modified
19 ■■■■■ changed files
README.md 7 ●●●●● patch | view | raw | blame | history
layouts/partials/footer.html 4 ●●●● patch | view | raw | blame | history
layouts/partials/google-analytics-gtag-async.html 8 ●●●●● patch | view | raw | blame | history
README.md
@@ -242,6 +242,13 @@
googleAnalytics = "UA-123-45"
```
To use the modern Google Analytics 4, include the following under `[params]` replacing the id with your own.
```toml
[params]
gtagId = "G-XXXXXXXXXX"
```
### Simple Analytics
To use Simple Analytics, it has to be enabled by setting the parameter to true. If you are using a custom subdomain to evade Adblockers, then specify the URL without a trailing slash.
layouts/partials/footer.html
@@ -16,3 +16,7 @@
{{- partial "medium-zoom.html" . -}}
{{- partial "math.html" . -}}
{{- template "_internal/google_analytics_async.html" . -}}
{{- if and (hugo.IsProduction) (.Site.Params.gtagId) -}}
    {{ partial "google-analytics-gtag-async.html" . }}
{{- end -}}
layouts/partials/google-analytics-gtag-async.html
New file
@@ -0,0 +1,8 @@
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ .Site.Params.gtagId }}"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', '{{ .Site.Params.gtagId }}');
</script>