fix umami

This commit is contained in:
Weaxs 2024-03-22 23:54:18 +08:00
parent a0d05ce208
commit 5ad54fd91a

View file

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