analytics.html 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 src="https://cdn.counter.dev/script.js"
  13. data-id="{{ .id }}"
  14. data-utcoffset="1"
  15. ></script>
  16. {{ end }}
  17. <!-- GoatCounter -->
  18. {{ with .goatCounter }}
  19. <script
  20. data-goatcounter="https://{{ .code }}.goatcounter.com/count"
  21. async
  22. src="/js/goat-counter.js"
  23. ></script>
  24. {{ end }}
  25. <!-- Piwik/Matomo -->
  26. {{ with .matomo }}
  27. <!-- Matomo -->
  28. <script>
  29. var _paq = window._paq = window._paq || [];
  30. /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  31. _paq.push(['trackPageView']);
  32. _paq.push(['enableLinkTracking']);
  33. (function() {
  34. var u="//{{ .instance }}/";
  35. _paq.push(['setTrackerUrl', u+'matomo.php']);
  36. _paq.push(['setSiteId', '{{ .siteId }}']);
  37. var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
  38. g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  39. })();
  40. </script>
  41. {{ end }}
  42. {{ end }}
  43. {{ end }}
  44. <!-- Keep backwards compatibility and consistency with HUGO defaults -->
  45. {{ if site.GoogleAnalytics }}
  46. {{ template "_internal/google_analytics.html" . }}
  47. {{ end }}