I want to change how I embed the Matomo (https://matomo.org/) tracking code to my website.
I am using self-hosted version of Matomo to track a few websites, and every single time I need to change tracking options I have to manually update them on all the websites.
Is it possible for me to have a central file so that I can embed that on all websites. This way when I need to make any changes, I have to change it in just one file and it will get auto reflected on all my websites.
Currently, I have to insert the tracking code like this:
<!-- 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 want to do 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>