Matomo JS Tracker send piwik.php request with empty idsite - how to avoid?

1) Matomo Tag Manager container with enabled bundled JavaScript tracker

2) A html page has the following Matomo components:

<head>
…….
<script type="text/javascript">
    var _mtm = _mtm || [];
    _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src='https://matomo.asi.asia/js/container_d2amnenK.js'; s.parentNode.insertBefore(g,s);
  </script>
…….
</head>
<body>
…….
<script type="text/javascript">
    var _paq = window._paq || [];
    _paq.push(['trackPageView']);
  </script>
…….
<body>

3) Matomo fire:
https://matomo.asi.asia/piwik.php?action_name=ONLINE%20RESERVATION%20SYSTEM&idsite=&rec=1&r=383665&h=10

Unfortunately Matomo fire the trackPageView or other events without a number for idsite.

A little later, Matomo triggers the correct event with the idsite, which comes from the page view event of the Matomo tag itself.

4) Temporary fix: We fire delayed the _paq.push([‘trackPageView’]) then all is good.

Question: What is the simplest way in Webbrowsers JavaScript to verify and confirm that Matomo Tagmanager and all other Matomo components fully initialized & operational?

Hi,

What is wrong with doing the _paq.push(['trackPageView']); also with Tag Manager?
At the moment it is executed before Tag Manager loads and sets an idsite

Hi Lukas and thank you for your reply.

Your answer bring me back to my original question ->

Question: What is the simplest way in Webbrowsers JavaScript to verify and confirm that Matomo Tagmanager and all other Matomo components fully initialized & operational?

Since we are a small JavaScript that is executed in the browser and we do not know whether Matomo nor Tracker are active, these commands below are regularly executed in a scheduled loop, looking that return variables have content, which we then set as an assumption that the tracker (including idSite) set up correctly and ready for use.

_paq.push([ function() { LoopVisitor_id = this.getVisitorId(); console.log(LoopVisitor_id); }]);
_paq.push([ function() { LoopSite_id = this.getSiteId(); console.log(LoopSite_id); }]);

Since I am not a fan of any scheduled loops for this kind of mechanics, I am happy to read other ways or solutions.