Example: Custom purpose for AdSense

With IAB's recent changes to the consent framework for GDPR, Sortable is transitioning publishers using our hosted CMP to a hosted Quantcast CMP. This and other articles will be updated in coming weeks to reflect these changes.

An example of pausing AdSense ad requests in order to wait for the user to consent of a custom purpose. 

Note: If you are serving AdSense via DFP Dynamic Allocation, then you don't need to follow these instructions. Our CMP will integrate with DFP.

Configuring the custom purpose

This is an example of the configuration you'd provide to your Account Manager:

TitleGoogle AdSense PersonalisationThe title you wish to display to the user

Allow Google AdSense and their technology partners to collect data and use cookies for ad personalisation and measurement.

The following technology providers are enabled on this site:

<li><a href="http://example.com/privacy" target="_blank">Technology Partner 1</a></li>

The verbiage is as recommended from https://www.cookiechoices.org/

The list of technology providers is listed in your AdSense admin UI. This is required to serve personalized ads.

Integrate on the page

The code below pauses ad requests until the CMP has loaded and had prompted the user. Your account manager will provide the ID for the custom purpose, which must be inserted in this line (with "5" as the ID in the example):

if (result.gdprApplies && !result.customPurposes[5]) {

See the Google documentation for more details.

window.deployads = window.deployads || [];
// Pause the adsense tag from sending ad requests.
// You must do this before the first call to adsbygoogle.push(...).
// Check that the custom purpose has been accepted
window.deployads.push(function() {
  if (deployads.__cmp) {
    deployads.__cmp('getPublisherConsents', null, function(result){
      if (result.gdprApplies && !result.customPurposes[5]) {
        // Custom purpose is not approved, disable personalized ads
      if (!result.gdprApplies || (result.standardPurposes[1] && result.standardPurposes[3])) {
        // If GDPR does not apply to this user or
        // GDPR does apply and the user has accepted standard purpose 1 (cookie consent) and purpose 3 (ad selection)
        // continue displaying Google Adsense
  } else {
    // GDPR does not apply to this user