hugo-toha/layouts/partials/analytics.html
JY Hsu 3be5a58a7c
Fix google analytics feature (#989)
* fix: Fix google analytics

* fix: Change respectDoNotTrack in GA html template

---------

Co-authored-by: Emruz Hossain <hossainemruz@gmail.com>
2024-11-27 05:59:35 +06:00

84 lines
3.7 KiB
HTML

<!-- Add Analytics if enabled in configuration -->
{{ with site.Params.features.analytics }}
{{ if or .enable .enabled }}
{{ with .services }}
<!-- Google Analytics -->
{{ with .google }}
{{ partial "google_analytics.html" . }}
{{ end }}
<!-- Counter.dev -->
{{ with .counterDev }}
<script src="https://cdn.counter.dev/script.js"
data-id="{{ .id }}"
data-utcoffset="1"
></script>
{{ end }}
<!-- GoatCounter -->
{{ with .goatCounter }}
{{ with .code }}
<script data-goatcounter="https://{{ . }}.goatcounter.com/count" async src="//gc.zgo.at/count.js"></script>
{{ else }}
<script data-goatcounter="https://{{ .instance }}/count" async src="https://{{ .instance }}/count.js"></script>
{{ end }}
{{ end }}
<!-- Piwik/Matomo -->
{{ with .matomo }}
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//{{ .instance }}/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '{{ .siteId }}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
{{ end }}
{{ with .cloudflare }}
<!-- Cloudflare Web Analytics -->
<script defer src='https://static.cloudflareinsights.com/beacon.min.js'
data-cf-beacon='{"token": "{{ .token }}"}'
></script>
<!-- End Cloudflare Web Analytics -->
{{ end }}
{{ with .umami }}
<!-- Umami analytics -->
<script defer src='{{ or .scheme "https" }}://{{ or .instance "analytics.eu.umami.is" }}/script.js' data-website-id="{{ .id }}"></script>
<!-- End Umami analytics -->
{{end}}
{{ with .statcounter }}
<!-- Statcounter analytics -->
<script type="text/javascript" src="https://www.statcounter.com/counter/counter.js" async></script>
<script type="text/javascript">
var sc_project = {{ .project }};
var sc_invisible = {{ .invisible }};
var sc_security = "{{ .security }}";
var scJsHost = (("https:" == document.location.protocol) ?
"https://www.statcounter.com/js/" : "https://www.statcounter.com/js/");
</script>
<noscript>
<div class="statcounter"><a title="web counter" href="https://statcounter.com/" target="_blank"><img
class="statcounter" src="https://c.statcounter.com/{{ .project }}/0/{{ .security }}/{{ .invisible }}/"
alt="web counter" referrerPolicy="no-referrer-when-downgrade"></a></div>
<!-- End of Statcounter Code -->
</noscript>
<!-- End Statcounter analytics -->
{{ end }}
{{ end }}
{{ end }}
{{ end }}
<!-- Keep backwards compatibility and consistency with HUGO defaults -->
{{ if .Site.Config.Services.GoogleAnalytics.ID }}
{{ template "_internal/google_analytics.html" . }}
{{ end }}