analytics.html 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <!-- Add Analytics if enabled in configuration -->
  2. {{ with site.Params.features.analytics }}
  3. {{ if .enabled }}
  4. <!-- Google Analytics -->
  5. {{ with .google }}
  6. {{ $privacyConfig:= dict (slice "Site" "Config" "Privacy" "GoogleAnalytics") $.Site.Config.Privacy.GoogleAnalytics }}
  7. {{ $analyticsConfig := dict (slice "Site" "GoogleAnalytics") .id }}
  8. {{ template "_internal/google_analytics.html" (merge $privacyConfig $analyticsConfig) }}
  9. {{ end }}
  10. <!-- Counter.dev -->
  11. {{ with .counterDev }}
  12. <script>
  13. if (
  14. !sessionStorage.getItem("_swa") &&
  15. document.referrer.indexOf(location.protocol + "//" + location.host) !== 0
  16. ) {
  17. fetch(
  18. "https://counter.dev/track?" +
  19. new URLSearchParams({
  20. referrer: document.referrer,
  21. screen: screen.width + "x" + screen.height,
  22. user: "{{ .id }}",
  23. utcoffset: "1",
  24. }),
  25. {{ with .referrerPolicy }}
  26. { referrerPolicy: "{{ . }}" }
  27. {{ end }}
  28. );
  29. }
  30. sessionStorage.setItem("_swa", "1");
  31. </script>
  32. {{ end }}
  33. <!-- GoatCounter -->
  34. {{ with .goatCounter }}
  35. <script
  36. data-goatcounter="https://{{ .code }}.goatcounter.com/count"
  37. async
  38. src="//gc.zgo.at/count.js"
  39. ></script>
  40. {{ end }}
  41. <!-- Piwik/Matomo -->
  42. {{ with .matomo }}
  43. <!-- Matomo -->
  44. <script>
  45. var _paq = window._paq = window._paq || [];
  46. /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  47. _paq.push(['trackPageView']);
  48. _paq.push(['enableLinkTracking']);
  49. (function() {
  50. var u="//{{ .instance }}/";
  51. _paq.push(['setTrackerUrl', u+'matomo.php']);
  52. _paq.push(['setSiteId', '{{ .siteId }}']);
  53. var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
  54. g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  55. })();
  56. </script>
  57. {{ end }}
  58. {{ end }}
  59. {{ end }}
  60. <!-- Keep backwards compatibility and consistency with HUGO defaults -->
  61. {{ if site.GoogleAnalytics }}
  62. {{ template "_internal/google_analytics.html" . }}
  63. {{ end }}