Example: Custom Purpose for AdSense

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:

ID5ID is chosen to not collide with any other custom purpose used on your site
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 following code pauses ad requests until the CMP has loaded and had prompted the user. 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