How to Trigger GTM Tags Immediately After Consent and on Subsequent Page Loads

Edited

This guide explains how to configure Google Tag Manager (GTM) so that tags fire immediately when a user clicks “Allow” and continue to fire on all subsequent page loads once consent has been granted.

This approach ensures consistent and predictable tag execution, especially in environments where consent is required before tags are allowed to run.

This article is not intended to be a full GTM configuration guide. It focuses specifically on this consent-driven firing pattern.

When to Use This Configuration

This setup is most useful for websites using an opt-in consent model, where tags must not fire until a user explicitly allows consent.

In these scenarios, it is often desirable to fire tags immediately when the user opts in, rather than waiting for a page refresh or a subsequent page load.

Because this approach relies on custom events and normalized triggers, it is considered an advanced GTM configuration and is best implemented by teams comfortable using GTM Preview and Debug mode.

DLV Variables:

Captain Compliance supports consent evaluation using either cookie parsing or Google Tag Manager data layer variables (DLVs). The approach described in this article requires consent state to be exposed via DLVs. If your GTM configuration relies exclusively on cookie parsing, this pattern should not be used.

High-Level Approach

Captain Compliance emits different consent-related events depending on the context:

  • One event fires when existing consent is loaded from storage on page load.

    • Event name: captainComplianceConsent

  • A separate event fires when a user actively updates consent, such as clicking “Allow.”

    • Event name: captainComplianceConsentUpdated

Rather than configuring downstream tags to listen for multiple consent events, this approach:

  • Listens for both Captain Compliance consent events

  • Normalizes them into a single internal event

  • Ensures the event fires only once per page load

Step 1: Create the Consent Normalization Tag

Create a new Custom HTML tag in GTM.

Recommended tag name:
Captain Compliance CMP – Consent Normalization

Paste the following code into the tag:

<script>
(function () {
  var dl = window.dataLayer = window.dataLayer || [];
  var ev = "{{Event}}";

  if (ev === "captainComplianceConsentUpdated") {
    window.__ccConsentNormalizedPushed = true;
  } else if (window.__ccConsentNormalizedPushed) {
    return;
  }

  window.__ccConsentNormalizedPushed = true;
  dl.push({ event: "captainComplianceConsentNormalized" });
})();
</script>

This script ensures that the normalized event is pushed immediately on user opt-in and does not fire redundantly on the same page load.

Step 2: Configure the Trigger for the Normalization Tag

Create a Custom Event trigger with the following settings:

  • Enable regex matching: Yes

  • Event name: ^captainComplianceConsent(Updated)?$

This allows the tag to respond to both Captain Compliance consent events.

Step 3: Update Downstream GTM Tags

Update any GTM tags that are required to fire on Captain Compliance consent events:

Event name: captainComplianceConsentNormalized

How this is done depends on how your GTM workspace is structured.

Basic Triggers (From GTM Import File)

If you are using the Captain Compliance triggers provided in the GTM import file, confirm that the following triggers are configured to listen for the normalized event:

  • CCTrigger_Targeting_Functionality

  • CCTrigger_Targeting_Performance

  • CCTrigger_Targeting_Active

Each of these should use:
Custom Event = captainComplianceConsentNormalized

Custom or Advanced Triggers:

For custom triggers, update each relevant trigger so it fires on:

  • Custom Event = captainComplianceConsentNormalized

Your existing consent logic should remain unchanged, including consent-related conditions such as:

  • CaptainFunctionality equals true

  • CaptainPerformance equals true

  • CaptainTargeting equals true

In this model:

  • The event name determines when consent should be evaluated

  • The consent data layer variables determine whether the tag is allowed to run

Special Consideration for Page View–Based Triggers

Some tags rely on GTM built-in lifecycle events, such as Page View triggers that default to gtm.js or gtm.init.

If those tags must run only after consent is available, you may need to replace or supplement Page View triggers with a Custom Event trigger using captainComplianceConsentNormalized.

GTM Page View triggers do not allow you to specify a custom event name, which makes them incompatible with consent-gated execution in opt-in models without additional configuration.