analytics.html 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. );
  26. }
  27. sessionStorage.setItem("_swa", "1");
  28. </script>
  29. {{ end }}
  30. <!-- GoatCounter -->
  31. {{ with .goatCounter }}
  32. <script
  33. data-goatcounter="https://{{ .code }}.goatcounter.com/count"
  34. async
  35. src="//gc.zgo.at/count.js"
  36. ></script>
  37. {{ end }}
  38. {{ end }}
  39. {{ end }}
  40. <!-- Keep backwards compatibility and consistency with HUGO defaults -->
  41. {{ if site.GoogleAnalytics }}
  42. {{ template "_internal/google_analytics.html" . }}
  43. {{ end }}