analytics.html 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. {{ end }}
  42. {{ end }}
  43. <!-- Keep backwards compatibility and consistency with HUGO defaults -->
  44. {{ if site.GoogleAnalytics }}
  45. {{ template "_internal/google_analytics.html" . }}
  46. {{ end }}