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?