CookieYes automatically blocks third-party cookies on your website prior to obtaining user consent. But if you use Google Tag Manager to add third-party scripts to your website, you will need to ensure that your site blocks all cookies that are set via GTM but have not been consented to use.
If, for instance, you have added a Functional cookie script to your GTM account, and if a user visiting your website gives consent to only Analytics cookies, ideally your site should block all the other types of cookies.
But in this case, the Functional cookies will also possibly get triggered. The reason behind this is that when you enable Analytics cookies, it will trigger the Google Tag Manager, which would, in turn, trigger all the other cookie scripts set via GTM.
To avoid this issue, you are required to create an appropriate custom event trigger in your GTM account. Here’s an example of how this can be done!
Creating a custom event trigger in GTM
The following are the steps to create a custom event trigger in Google Tag Manager that helps CookieYes block third-party cookie scripts on your website (set via GTM) prior to receiving user consent.
Step 1: Create a user-defined variable
- Sign in to your Google Tag Manager account > Click the required Container Name from your Accounts.
- From the left panel, select Variables > In the User-Defined Variables section, click New.
- Name the variable > Click Variable Configuration > Choose variable type as 1st Party Cookie from under Page Variables.
Cookies installed by the site — displayed under the Application tab of the Developer console
- In the Cookie Name text box, enter the name of that cookie for which you need to retrieve the value.
- Click Save to save the variable.
Step 2: Create a custom event trigger
- From the left panel of your GTM account, select Triggers > In the Triggers section, click New.
- Name the Trigger > Click Trigger Configuration > Choose trigger type as Custom Event.
- In the Event Name text box, enter the .* regular expression and check the Use regex matching option.
- Under This trigger fires on, choose Some Custom Events.
- Under Fire this trigger when an Event occurs and all of these conditions are true, set up a trigger condition.
e.g. Tawk.to trigger variable (i.e. the name of the user-defined variable that you have created in Step 1), equals, and yes.
- Click Save to save the custom event trigger.
Step 3: Add the custom event trigger to the required custom HTML tag
- From the left panel of your GTM account, select Tags > Click the Tag name that needs to be fired.
- Click Triggering.
- Choose the custom event trigger that you have created in Step 2.
- Click Save.
Step 4: Submit changes
- Click the Submit button at the top right corner of your GTM account.
- Finally, click Publish to make this tag live on your website.
Once you have done these steps, your site visitors will not have Functional cookies running in the background after enabling Analytics cookies and disabling Functional cookies.
Now, take a look at how a website’s cookie installation differs before and after adding the custom event trigger in GTM.
Before adding the custom event trigger in GTM
After adding the custom event trigger in GTM