I am using Seomatic and i want to conditionally render google tag manager trancking code - or not.

How do I disable it using some Twig template code?

1 Answer 1


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.

  • Using clearCache gave me this error: Calling unknown method: nystudio107\seomatic\services\Script::clearCache()
    – piotrpog
    Apr 5, 2019 at 14:49
  • My bad, I left out the .container() -- I edited the answer Apr 5, 2019 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.