I am looking to streamline the process of embedding the Matomo tracking code on my website. Currently, I have a self-hosted version of Matomo set up for multiple websites, and whenever I need to make changes to the tracking options, I have to manually update them on each site individually.
Is there a way for me to create a central file that can be embedded on all my websites? This way, any changes I make will automatically apply to all sites without having to update each one separately.
Currently, I have to insert the tracking code in this format:
<!-- Matomo -->
<script type="text/javascript">
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//example.com/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', 'SITE-ID-OF-INDIVIDUAL-WEBSITE']);
var 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);
})();
</script>
<!-- End Matomo Code -->
Instead, I would like to implement something like this:
<script src="https://example.com/script.js" data-site="INDIVIDUAL-SITE-IDENTIFIER" defer></script>
- or -
<script src="https://example.com/script.js" data-site="INDIVIDUAL-SITE-IDENTIFIER" async></script>