matomo_controller.js 925 B

123456789101112131415161718192021222324252627
  1. import { Controller } from '@hotwired/stimulus'
  2. export default class extends Controller
  3. {
  4. static values = {
  5. url: String,
  6. active: Boolean
  7. }
  8. connect() {
  9. if (this.activeValue) {
  10. const url = this.urlValue
  11. console.log("TEST")
  12. var _paq = window._paq = window._paq || [];
  13. /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  14. _paq.push(['trackPageView']);
  15. _paq.push(['enableLinkTracking']);
  16. (function() {
  17. var u="https://"+ url +"/";
  18. _paq.push(['setTrackerUrl', u+'matomo.php']);
  19. _paq.push(['setSiteId', '2']);
  20. var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
  21. g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  22. })();
  23. }
  24. }
  25. }