-
Disabling Google Tag Manager on localhost to prevent tag firing
Hey there! Need some help with Google Tag Manager that you’ve just installed on your website? Exciting, isn’t it? Now, I know you’ve begun firing some events from GTM and you’re able to see them come up when using the tag assistant debugger. And that’s great! You’ve got tags set up which send events to Google Analytics too.
Now, here’s what you’re struggling with – you want to easily configure all your tags of type
GA4 Event
to not fire when the trigger happens in a non-production environment. Essentially, you want to test things out, but don’t want these events to take off to Google Analytics in non-production environments. How do you do this with Google Tag Manager, you wonder?You’ve even noticed that when running the tag assistant debugger there’s a field called
debug_mode
which is set to true. You’ve tried giving it a go in your local environment like this:export function maybeSetDebugMode() { if (typeof window !== 'undefined' && process.env.NODE_ENV !== 'production') { window?.dataLayer?.push({"debug_mode": "true"}) } }
But no luck, huh? Your custom events continue to rush off to GA:
So, you’re wondering, is there a way to tell Tag Manager “Hey, hold up! Don’t pipe events to GA” when a certain condition is met, like matching a URL or the value of some other event field? Or you’d like to know if Google Analytics can say “Thanks, but no thanks!” to events during ingestion which meet some criteria?
Log in to reply.