Seomatic - disable tag manager from inside template
This code will let you disable the inclusion of the tag:

{% do seomatic.script.get('googleTagManager').include(false) %}


For more, check out the SEOmatic Twig Templating documentation

If you're changing the inclusion of the tag or not based on some other variable such that the tag may be included or not for the exact same URI, you'll want to bust the cache, too (which is URI-based):

{% do seomatic.script.container().clearCache(true) %}


Also check out the Advanced SEOmatic Tips article for some deeper reading.