support umamiAnalytics

This commit is contained in:
Weaxs 2024-03-22 23:26:56 +08:00
parent bafc42f587
commit a0d05ce208
4 changed files with 34 additions and 0 deletions

View file

@ -129,6 +129,10 @@ disableTextInHeader = false
# site = "ABC12345"
# domain = "llama.yoursite.com"
[umamiAnalytics]
# websiteid = "ABC12345"
# domain = "llama.yoursite.com"
[buymeacoffee]
# identifier = ""
# globalWidget = true

View file

@ -128,6 +128,10 @@ smartTOCHideUnfocusedChildren = false
# site = "ABC12345"
# domain = "llama.yoursite.com"
[umamiAnalytics]
# websiteid = "ABC12345"
# domain = "llama.yoursite.com"
[buymeacoffee]
identifier = "nunocoracao"
globalWidget = true

View file

@ -3,4 +3,7 @@
{{ end }}
{{ with site.Config.Services.GoogleAnalytics.ID }}
{{ partial "analytics/ga.html" }}
{{ end }}
{{ with site.Params.umamiAnalytics.websiteid }}
{{ partial "analytics/umami.html" }}
{{ end }}

View file

@ -0,0 +1,23 @@
{{ if isset site.Params.umamiAnalytics "domain" }}
<script id="umami-script" async src="https://{{ site.Params.umamiAnalytics.domain }}/script.js" data-website-id="{{ site.Params.umamiAnalytics.websiteid }}">
</script>
<script type="text/javascript">
document.querySelector('#umami-script').addEventListener('load', function () {
const type = document.head.querySelector('meta[property = "og:type"]').getAttribute('content');
let title = document.head.querySelector('meta[property = "og:title"]').getAttribute('content');
let url = document.head.querySelector('meta[property = "og:url"]').getAttribute('content');
umami.track(type + ':' +title, {'url': url});
});
</script>
{{ else }}
<script async src="https://analytics.umami.is/script.js" data-website-id="{{ site.Params.umamiAnalytics.websiteid }}">
</script>
<script type="text/javascript">
document.querySelector('#umami-script').addEventListener('load', function () {
const type = document.head.querySelector('meta[property = "og:type"]').getAttribute('content');
let title = document.head.querySelector('meta[property = "og:title"]').getAttribute('content');
let url = document.head.querySelector('meta[property = "og:url"]').getAttribute('content');
umami.track(type + ':' +title, {'url': url});
});
</script>
{{ end }}