There are different options -
-
You could use the Cookiehub event system to keep track of the current consent settings and “tell” Matomo about these changes - https://support.cookiehub.com/article/87-events
-
You overwrite the datalayer.push function for GTM to also push to the Matomo dataLayer (_mtm).