Complianz Privacy Suite

Enable consent on async javascript without script center

Aert Hulsebos

Aert Hulsebos

Categories

Popular articles

Creating the Legal Hub

Have you seen our new Legal Hub? If not, have a look before reading this instruction article. We created the legal hub to centralize our

Read More

Placeholders for iFrames

From 4.6.11 onwards, you can also use consent shortcode wrappers. An instruction can be found here. You’re able to block iFrames with Complianz with the

Read More
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

If you’re using a code manager outside of Complianz to add javascript, for example, a Remarketing Pixel from Google, you need to add some code to enable consent for javascript that uses asynchronized loading.

NB. With code managers outside of Complianz, we mean either adding code yourself to the header.php or using a plugin to do this for you. This article is not for Google Tag Manager users.

Recognizing async javascript

Async scripts are easily recognized by looking at the beginning line of your javascript, for example:


!-- General sitetag (gtag.js) - Google Ads: 123456789 ->
  script async src="https://www.googletagmanager.com/gtag/js?id=AW-123456789" script
  script
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'AW-123456789'); 

Below the comment you will find script aysnc src=. This signifies a script which loads outside of the normal hierarchy and will load simultaneously with other scripts, without being dependent on the order.

Enabling consent on async javascript

Async scripts do not work in the script center, yet. In this case you will add the code to your header.php, or footer if preferred. You can also use a plugin like Header Footer Code Manager. To enable consent on specific javascript, you can use the following attributes for your scripts:

script class="cmplz-script" type="text/plain" async
script

For the above example this will look like:


!-- General sitetag (gtag.js) - Google Ads: 123456789 ->
  script class="cmplz-script" type="text/plain" async src="https://www.googletagmanager.com/gtag/js?id=AW-123456789" script
  script
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'AW-123456789'); 

NB. In these example we have removed the <> from scripts. Please don’t remove yours.

Recent articles

Subscribe