mirror of
https://github.com/imfing/hextra.git
synced 2025-08-25 23:06:43 -04:00
feat(analytics): add Umami and Matomo (#784)
This commit is contained in:

committed by
GitHub

parent
524af14bd1
commit
c149af0f74
19
layouts/_partials/components/analytics/analytics.html
Normal file
19
layouts/_partials/components/analytics/analytics.html
Normal file
@@ -0,0 +1,19 @@
|
||||
{{- if hugo.IsProduction -}}
|
||||
|
||||
<!-- Google Analytics -->
|
||||
{{- if .Site.Config.Services.GoogleAnalytics.ID }}
|
||||
<link rel="preconnect" href="https://www.googletagmanager.com" crossorigin />
|
||||
{{ partial "google-analytics.html" . -}}
|
||||
{{- end }}
|
||||
|
||||
<!-- Umami -->
|
||||
{{- if .Site.Params.analytics.umami -}}
|
||||
{{ partial "components/analytics/umami.html" . }}
|
||||
{{- end }}
|
||||
|
||||
<!-- Matomo -->
|
||||
{{- if .Site.Params.analytics.matomo -}}
|
||||
{{ partial "components/analytics/matomo.html" . }}
|
||||
{{- end }}
|
||||
|
||||
{{- end }}
|
13
layouts/_partials/components/analytics/google-analytics.html
Normal file
13
layouts/_partials/components/analytics/google-analytics.html
Normal file
@@ -0,0 +1,13 @@
|
||||
{{- with site.Config.Services.GoogleAnalytics.ID }}
|
||||
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag() {
|
||||
dataLayer.push(arguments);
|
||||
}
|
||||
gtag("js", new Date());
|
||||
|
||||
gtag("config", "{{ . }}");
|
||||
</script>
|
||||
{{ end -}}
|
19
layouts/_partials/components/analytics/matomo.html
Normal file
19
layouts/_partials/components/analytics/matomo.html
Normal file
@@ -0,0 +1,19 @@
|
||||
{{- /*
|
||||
Matomo Analytics.
|
||||
https://developer.matomo.org/guides/tracking-javascript-guide
|
||||
*/ -}}
|
||||
|
||||
<!-- Matomo -->
|
||||
<script type="text/javascript">
|
||||
var _paq = window._paq = window._paq || [];
|
||||
_paq.push(['trackPageView']);
|
||||
_paq.push(['enableLinkTracking']);
|
||||
(function() {
|
||||
var u="//{{ .serverURL }}/";
|
||||
_paq.push(['setTrackerUrl', u+'matomo.php']);
|
||||
_paq.push(['setSiteId', {{ .websiteID }}]);
|
||||
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
||||
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
|
||||
})();
|
||||
</script>
|
||||
<!-- End Matomo Code -->
|
57
layouts/_partials/components/analytics/umami.html
Normal file
57
layouts/_partials/components/analytics/umami.html
Normal file
@@ -0,0 +1,57 @@
|
||||
{{- /*
|
||||
Umami Analytics
|
||||
https://umami.is/docs/tracker-configuration
|
||||
*/ -}}
|
||||
|
||||
{{- with .Site.Params.analytics.umami -}}
|
||||
|
||||
{{- if not .serverURL }}
|
||||
{{- errorf "Missing Umami 'serverURL' configuration. See TODO" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not .websiteID }}
|
||||
{{- errorf "Missing Umami 'websiteID' configuration. See TODO" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $attributes := newScratch -}}
|
||||
|
||||
{{- $attributes.SetInMap "umami" "src" (printf "%s/%s" .serverURL (.scriptName | default "umami.js")) -}}
|
||||
{{- $attributes.SetInMap "umami" "data-website-id" .websiteID -}}
|
||||
|
||||
{{- if .hostURL -}}
|
||||
{{- /* https://umami.is/docs/tracker-configuration#data-host-url */ -}}
|
||||
{{- $attributes.SetInMap "umami" "data-host-url" .hostURL -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if .autoTrack -}}
|
||||
{{- /* https://umami.is/docs/tracker-configuration#data-auto-track */ -}}
|
||||
{{- $attributes.SetInMap "umami" "data-auto-track" .autoTrack -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if .tag -}}
|
||||
{{- /* https://umami.is/docs/tracker-configuration#data-tag */ -}}
|
||||
{{- $attributes.SetInMap "umami" "data-tag" .tag -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if .excludeSearch -}}
|
||||
{{- /* https://umami.is/docs/tracker-configuration#data-exclude-search */ -}}
|
||||
{{- $attributes.SetInMap "umami" "data-exclude-search" .excludeSearch -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if .excludeHash -}}
|
||||
{{- /* https://umami.is/docs/tracker-configuration#data-exclude-hash */ -}}
|
||||
{{- $attributes.SetInMap "umami" "data-exclude-hash" .excludeHash -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if .doNotTrack -}}
|
||||
{{- /* https://umami.is/docs/tracker-configuration#data-do-not-track */ -}}
|
||||
{{- $attributes.SetInMap "umami" "data-do-not-track" .doNotTrack -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if .domains -}}
|
||||
{{- /* https://umami.is/docs/tracker-configuration#data-domains */ -}}
|
||||
{{- $attributes.SetInMap "umami" "data-domains" .domains -}}
|
||||
{{- end -}}
|
||||
|
||||
<script async defer {{ range $k, $v := ($attributes.Get "umami" ) }} {{ (printf `%s=%q` $k $v) | safeHTMLAttr }}{{- end -}}></script>
|
||||
{{- end -}}
|
Reference in New Issue
Block a user