How to set up MTM with consent manager

I’d like to switch to using the MTM, but I’m struggling to understand how to properly do that in combination with a consent manager (I’m using klaro.js).

First, I need to install the MTM container:

<!-- Matomo Tag Manager -->
<script>
var _mtm = window._mtm = window._mtm || [];
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src='https://matomo.mysite.com/js/container_ID.js'; s.parentNode.insertBefore(g,s);
</script>
<!-- End Matomo Tag Manager -->

I did this, but I’m wondering:

  1. Where does the tracking code come from? When I’m in the dashboard and click: Tags > Create new tag > Matomo Analytics will this add the well known tracking code:
<!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="https://matomo.mysite.com/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '2']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->
  1. If the above adds the tracking code, how do I add _paq.push(['requireCookieConsent']); before the _paq.push(['trackPageView']); line?
  2. How do I make sure that _paq.push(['requireCookieConsent']); will always come before _paq.push(['trackPageView']);?

Thanks for any clarifications.

Regards

Did I ask an absolute basic question that no one want to answer or is it so hard that no one can answer? :face_with_peeking_eye: