Skip to main content

How to Set Default Consent Settings Based on User Consent in GTM ?

When integrating Google Tag Manager (GTM) with CookieYes, it is important to make sure that the tags activate based on the user’s consent preferences. To avoid delays in firing tags when the consent level is set at page load, it is important to ensure the consent state is set timely and tags are configured correctly in GTM.

Step 1: Create a First-Party Cookie Variable.

  1. In the Google Tag manager Container, Navigate to Variables from the left side bar.
  2. Click New to create a User-Defined Variable.

    Create Variable
  3. Choose 1st Party Cookie from the list of variable types.
  4. In the Cookie Name field, enter cookieyes-consent.

    Variable Name

Step 2: Create a Custom JavaScript Variable

  1. Create a variable of type Custom JavaScript.

    Custom JavaScript
  2. Name the Custom JavaScript variable. Here, we’ve named as cy-analytics for the Analytics Category. Paste the following code into the Custom JavaScript field.
function () {
var c = {{cy-cookieyes}} || ""; //cy-cookieyes is the first party variable name created in the first step.
return c.indexOf("analytics:yes") === -1 ? "denied" : "granted";

Make sure to replace "cy-cookieyes" with the name of your first party variable.


For each category that requires prior consent, create a new Custom JavaScript variable. Edit the code , and use “analytics:yes” for the Analytics Category, “functional:yes” for the Functional Category, and “advertisement:yes” for the Advertisement Category.

Step 3: Configure CookieYes Tag for Default Consent Setting

  1. Navigate to the Tags from the left side bar and select CookieYes CMP tag.

  2. In the default consent settings for each category, specify the variable name created earlier. 

    Default Consent
  3. Click Save.
  4. Click Submit and then click Publish to implement the changes.

The CookieYes CMP tag has now been configured for default consent settings. This can be done for all the required categories.

Have more questions?

Reach out to us and we'll answer them.

Contact us