Implementing Consent to Cookie and Consent to Tracking using the Tag Manager

I am going through implementing Consent to Cookie and Consent to Tracking using below guide

How can I implement above using Matomo Tag Manager on all the pages?

Have you got an answer?
I have tried this and it seems to be working but can’t be sure:

<script> 
  var _paq = window._paq || []; 
  _paq.push(['requireCookieConsent']); 
  var _mtm = window._mtm = window._mtm || [];
  ...
</script>