secureprivacy.ai

Secure Privacy Support Center

Search for any help questions or topics.

Block Cookies in Complex GTM Triggers | Consent-Based Tagging

Learn how to block cookies in complex GTM triggers by checking user consent with a simple conditional trigger setup. Step-by-step guide included.
Avatar
Andrew Sidorkin
Updated 1 hour ago

Introduction

When using Google Tag Manager (GTM), you may need to ensure a user’s consent before firing any tags or triggers to comply with privacy regulations. This guide explains how to block cookies in complex GTM triggers by incorporating user consent conditions, preventing tags from firing unless consent is given.

Who Is This Guide For?

  • GTM administrators
  • Web developers implementing tag management
  • Digital marketers managing analytics and tracking

How to Block Cookies in GTM Triggers Based on User Consent

Step 1: Create a User-Defined Variable for Consent Check

  1. In GTM, go to Variables > New
  2. Name the variable: Check {{Plugin_name}} consent
  3. Select Variable Type: Custom JavaScript
  4. Enter this code snippet:
    function() { 
      return sp.checkConsent("{{Plugin_name}}"); 
    }
  5. Replace {{Plugin_name}} with the exact name of your service/plugin (case-sensitive).
  6. Save the variable.

[screenshot: Google Tag Manager variable configuration showing custom JavaScript]


Step 2: Replace Plugin Name Accurately

  • Use the exact service/plugin name from your scan or consent management platform report.
  • Make sure spelling and case match exactly.

Step 3: Modify Your Trigger to Include Consent Condition

  • Navigate to Triggers
  • Edit your existing trigger (e.g., custom event or click trigger)
  • Add a new condition based on the user-defined variable created, e.g., Check {{Plugin_name}} consent equals true
  • This ensures the trigger only fires if the user has given consent.

[screenshot: GTM trigger configuration with consent condition added]


Step 4: Complete Setup

Save your trigger and publish your GTM container changes. Your tags will now respect user consent and block cookies when consent is not given.

Common Issues & Fixes

My tag still fires without consent. What could be wrong?
  • Check that the plugin name in your variable matches exactly (including case).
  • Confirm the custom JavaScript variable returns boolean values true/false.
  • Verify trigger conditions all evaluate to true simultaneously.
How do I test if the consent condition works?
  • Use GTM preview mode to debug triggers firing based on consent.
  • Change the consent state and observe if the tag fires or blocks accordingly.

See Also

Was this article helpful?
😞 😐 😃