Using AdConsent with AdEngine v3

Overview

AdConsent comes completely integrated with AdEngine v3. Your account manager will configure AdConsent with the page requirements and there are no additional steps required on the page.
To implement AdEngine on a website please check the Setup Overview.

There are some situations where manual control over AdConsent is required. This guide will describe such use cases and how to implement them properly.

Examples

Loading 3rd party libraries that use the CMP

The IAB Europe Transparency and Consent Framework (TCF) Specifications determine that the Consent Management Provider (CMP) is supposed to be loaded synchronously in the page head before any other module, to ensure the API is available. Loading a script synchronously in the head, even if very small, has several risks and will slow down page loading. Therefore, AdConsent is loaded automatically and asynchronously by AdEngine which guarantees that it is accessible to supported libraries, like GPT, AdSense, or Prebid.js.
If the page uses unsupported third-party libraries that use a CMP and process the user consent strings, it is necessary to ensure that these scripts are only loaded or started after AdConsent is loaded and ready.

The following example will show how to load a thirds party script when AdConsent is available, using the adnginLoaderReady event.
This example loads AdConsent asynchronously, waits for the ready signal, and then loads the 3rd party script asynchronously. This ensures sequential loading between the CMP and the libraries using it, but otherwise, it loads everything asynchronously ensuring the best page performance.

The following script should be added to the page <head> before loading the AdEngine script.

<script data-cfasync="false" type="text/javascript"> // Wait for AdConsent to be loaded window.addEventListener('adnginLoaderReady', function() { var s = document.createElement('script'); s.src = '//example.com/script.js'; s.async = true; s.defer = true; document.head.appendChild(s); }); </script>

Using AdConsent API

The page can use the AdConsent API to process consent events or manually configure AdConsent. To work with the API, it requires the API to be loaded and ready, which is guaranteed by the adnginLoaderReady event as described in the previous example.

This example waits for AdConsent to be loaded, and in addition for the user to acknowledge consent, before loading the script.

<script data-cfasync="false" type="text/javascript"> // Wait for AdConsent to be loaded window.addEventListener('adnginLoaderReady', function() { // Wait for user consent to be ready __tcfapi('addEventListener', 2, (tcData, success) => { if(success && (tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete')) { var s = document.createElement('script'); s.src = '//example.com/script.js'; s.async = true; s.defer = true; document.head.appendChild(s); } }); }); </script>

The example can be applied to the following use cases:

  • Loading an Analytics library only after consent is collected

  • Processing user data after the user gave consent