Load banner asynchronous + Consent Mode defaults

Have more questions? Submit a request

If you run in to issues with load speed of the banner and you want to load the banner asynchronous you need to still make sure that Google can have access to the consent mode defaults and update commands in time. The async loading of the banner might result in that it loads after Google tags and consent mode might not get propagated. 

Make sure that you still run the consent.js file before any Google tags. and just add the 'async' attribute to the file.

In this case you cannot load the Consent Mode defaults over the banner but you need to make sure to add it hard coded to your website. 

In the example below we added region specific defaults for the EEA + Uk and the rest of the world. You can tailor it specifically to your needs following Googles’ documentation which can be found here.

In short:

1. Copy the banner embed code an put in the head.

2. Add the consent mode defaults 

3. load your google tags (advanced Consent Mode)


   <!-- Banner script here! -->
<script async src="https://consent.cookiefirst.com/sites/your-unique-domain+key/consent.js"></script>
<!-- Set Google Consent Mode defaults -->
// Define dataLayer and the gtag function.
window.dataLayer = window.dataLayer || [];

function gtag() {
// Set default consent to 'denied' as a placeholder
// Determine actual values based on your own requirements
// Below are the defaults for EU + UK
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
  'personalization_storage': 'denied',
'analytics_storage': 'denied',
'functionality_storage': 'denied',
'security_storage': 'granted',
'wait_for_update': 2000, // This is to make sure the banner is loaded before sending data to Google
  'region': ['AT', 'BE', 'BG', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IS', 'IE', 'IT', 'LV', 'LI', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'CH', 'GB']
// Default settings for all users out of EU + UK
gtag('consent', 'default', {
'ad_storage': 'granted',
'ad_user_data': 'granted',
'ad_personalization': 'granted',
  'personalization_storage': 'denied',
'analytics_storage': 'granted',
'functionality_storage': 'granted',
'security_storage': 'granted'
<!-- Put below your Google tags -->

Articles in this section

Was this article helpful?
0 out of 0 found this helpful