How to make the script tag less 'heavy'

This is the <script> tag I am asked to embed:

<!-- Matomo -->
<script type="text/javascript">
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  (function() {
    var u="//";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
    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);
<!-- End Matomo Code -->

Is there a way to do something like:

<script src="" data-id=""></script>

This is how all the other Privacy focused analytic tools handle this, where data-id specifies the domain.

I am not too fussed about the majority of the data collected also, just need basic things like Uniques, Pageviews, Location + Referrer - just in case a workaround means losing out on certain metrics.



I thought about this a bit, as I think e.g. plausible does it this way.

In theory the Matomo tracking code is not that much different, the last two lines starting with var d=document do exactly this: they create a script tag.

If we wanted to do this in Matomo, we would at least need to data-entries (for siteId and the Matomo URL).
But the main reason why the tracking code looks like this, is because it creates the global _paq variable. This means that you can e.g. call _paq.push(['trackEvent', 'Contact', 'Email Link Click', '']); and it doesn’t matter if the matomo.js has already finished loading or not. If it has, it is tracked immediately. If it hasn’t, the task is put into the list and once the matomo.js has finished loading.
Now one could say that we could provide this simpler tracking code as an alternative for people who don’t need any of those features. But I think this introduces a lot of confusion as then the things explained in the guides wouldn’t work and one would need to replace the tracking code. And the people who would tend to use the simpler tracking code are the same people who might not have as much technical knowledge to understand why these limitations are needed.

Just FYI: When you want to do something similar to custom events in Plausible, you also need to modify your tracking code first to work just like the Matomo one: