1

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

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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