Installation of the Consent Studio CMP for Google Consent Mode v2 in combination with gtag.js
We recommend that you use a tag management system, specifically Google Tag Manager, to implement Consent Studio and perhaps other tags.
Prerequisites
Make sure that you have basic knowledge of HTML and JavaScript before using this installation method.
Make sure that you understand the difference between Google Tag Manager and gtag.js. This help article from Google can help you understand the difference.
Make sure that you understand Google Consent Mode and the different types of consent signals and the data redaction option.
1. Make sure that you have an account with Consent Studio
Log in at https://consent.studio. If you do not yet have an account, you can create one here:
2. Add this script to your website
We recommend adding the following script as early after opening the <head>
element of your HTML page as possible and before the initialisation of gtag.js.
This script has placeholders. Make sure that you replace them.
The site domain that you have registered with Consent Studio:
[YOUR DOMAIN HERE]
Also...
...if needed, adjust the default consent signals;
...if needed, adjust the default
wait_for_update
parameter;...and remove any other CMP that may have already been installed on your page to prevent conflicts
<script type="text/javascript">
/**
* Manual implementation of the Consent Studio CMP
* - Remember to replace the following placeholders: [YOUR DOMAIN HERE]
* - Remember to adjust the default consent signals if needed
*/
/** Initialize the dataLayer variable */
window.dataLayer = window.dataLayer || [];
/** Define a short-hand function for writing to the dataLayer */
function gtag(){dataLayer.push(arguments);}
if(window.location.hash ? window.location.hash == '#cs-scan' : false)
{
/** Don't touch: set all consent signals to granted for the Consent Studio cookie scanner */
gtag("consent","default",{ad_storage:"granted",ad_user_data:"granted",ad_personalization:"granted",analytics_storage:"granted",functionality_storage:"granted",personalization_storage:"granted",security_storage:"granted",wait_for_update:500});
}
else
{
/**
* Set the default consent signals
* (You may edit these defaults)
*/
gtag("consent", "default", {
ad_storage: "denied",
ad_user_data: "denied",
ad_personalization: "denied",
analytics_storage: "denied",
functionality_storage: "granted",
personalization_storage: "granted",
security_storage: "granted",
wait_for_update: 500,
});
}
/**
* Set a value for ads data redaction
* - More information: https://support.google.com/analytics/answer/13544947?hl=en
*/
gtag("set", "ads_data_redaction", true);
/** Set the Consent Studio developer ID */
gtag("set", "developer_id.dZTlmZj", true);
</script>
<script src="https://consent.studio/[YOUR DOMAIN HERE]/banner.js"></script>
What does this script do?
Firstly, it defines the basics: it initialises the dataLayer
variable and provides us with a shorthand function to easily push information to this variable.
Secondly, we set the default consent signals for Google Consent Mode. In our example, all categories (except security_storage
) are instructed to default to denied
. This is the same behaviour that our Google Tag Manager tag template has.
Thirdly, we set the value for ads_data_redaction
. As referred to from the code snippet above, more information about this flag can be found here in the official documentation by Google. Accepted values are true
and false
.
Then, the Consent Studio developer ID is set. This is our signature use so that Google can recognise our CMP.
Lastly, we will load the actual banner script into the website.
3. Customise your cookie banner
You can do so in your Consent Studio dashboard. More details can be found in this article.
4. Monitor your implementation
Now that you have finalised your implementation, we recommend keeping an eye on what your Consent Studio dashboard (we have a health check page that becomes available to you when issues are detected by our scanner) and the implementation status from within Google services (such as Google Analytics and Google Ads) inform you about.
Please contact consent.studio first, before contacting Google support.
Also, please keep an eye on whether our cookie scanner actually finds cookies on your website. If your website does use cookies, but our scanner does not find any, it may because of any of these causes:
You do not have the correct domain registered with consent.studio;
You have another CMP installed on the domain;
No scan has ran just yet (please wait up to 15 minutes after registration for your initial scan to start)