mirror of
				https://github.com/ZetaKebab/quartz.git
				synced 2025-11-04 06:49:49 +00:00 
			
		
		
		
	feat: add support for matomo analytics (#2051)
* feat: Support Matomo as analytics provider (self-hosted) * SPA support * Don't use var * inline * Revert fixing issues outside of this change
This commit is contained in:
		@@ -201,6 +201,33 @@ function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentReso
 | 
			
		||||
      })(window, document, "clarity", "script", "${cfg.analytics.projectId}");\`
 | 
			
		||||
      document.head.appendChild(clarityScript)
 | 
			
		||||
    `)
 | 
			
		||||
  } else if (cfg.analytics?.provider === "matomo") {
 | 
			
		||||
    componentResources.afterDOMLoaded.push(`
 | 
			
		||||
      const matomoScript = document.createElement("script");
 | 
			
		||||
      matomoScript.innerHTML = \`
 | 
			
		||||
      let _paq = window._paq = window._paq || [];
 | 
			
		||||
 | 
			
		||||
      // Track SPA navigation
 | 
			
		||||
      // https://developer.matomo.org/guides/spa-tracking
 | 
			
		||||
      document.addEventListener("nav", () => {
 | 
			
		||||
        _paq.push(['setCustomUrl', location.pathname]);
 | 
			
		||||
        _paq.push(['setDocumentTitle', document.title]);
 | 
			
		||||
        _paq.push(['trackPageView']);
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      _paq.push(['trackPageView']);
 | 
			
		||||
      _paq.push(['enableLinkTracking']);
 | 
			
		||||
      (function() {
 | 
			
		||||
        const u="//${cfg.analytics.host}/";
 | 
			
		||||
        _paq.push(['setTrackerUrl', u+'matomo.php']);
 | 
			
		||||
        _paq.push(['setSiteId', ${cfg.analytics.siteId}]);
 | 
			
		||||
        const d=document, g=d.createElement('script'), s=d.getElementsByTagName
 | 
			
		||||
('script')[0];
 | 
			
		||||
        g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
 | 
			
		||||
      })();
 | 
			
		||||
      \`
 | 
			
		||||
      document.head.appendChild(matomoScript);
 | 
			
		||||
    `)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (cfg.enableSPA) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user