Strategies to Manage DFP Tag Firing for Consent

Sourcepoint sets a first party cookie called '_sp_enable_dfp_personalized_ads' to help publishers manage their calls to the DFP adserver for personalized and non-personalized ads. The value is set to true if the user has consented to receive personalized ads and false if the user has rejected the delivery of personalized ads. This cookie is set to false by default the first time the CMP code loads for the user.

On the first pageview the '_sp_enable_dfp_personalized_ads' cookie will likely not be set in time for the first call to the ad server. For this call you can choose to either disable the initial load of the DFP ad calls and wait for the user's consent or rejection action, or you can proceed and have the DFP setNonPersonalizedAds flag set to 1 (true) in your GPT tags and allow non-personalized ads to show.

Not Disabling Initial Load

If you do not want to disable the initial load of ads for the first pageview you see a user, then you can just either the googletag.pubads().setRequestNonPersonalizedAds() flag to 0 or 1 depending on what the Sourcepoint '_sp_enable_dfp_personalized_ads' value is set to. See the code snippet below for an example. The example uses the jquery $.cookie() function to retrieve the cookie value.

<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script><script>
googletag.cmd.push(function() {
googletag.defineSlot('/44586335/example', [[88, 31], [728, 90]], 'div-gpt-ad-1536691535894-0').addService(googletag.pubads());
if($.cookie('_sp_enable_dfp_personalized_ads') === 'true') {
googletag.pubads().setRequestNonPersonalizedAds(0);
} else {
googletag.pubads().setRequestNonPersonalizedAds(1);
}
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>

Using the GPT Disable Load Method

If you choose to disable for the first pageview, you should create a flag to use in our consent actions to be leveraged in the "Consent Actions" for DFP in the user interface. Something like the variable below should work fine.

var dfp_inital_load_disabled = false;

A code example of a GPT tag setup that uses the disableInitialLoad() flag is below. The dfp_inital_load_disabled variable will be used in the CMP user interface and leveraged in the DoubleClick "Consent Action" field.

<script async='async'
src='https://www.googletagservices.com/tag/js/gpt.js'></script><script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
var dfp_inital_load_disabled = false;
</script><script>
googletag.cmd.push(function() {
googletag.defineSlot('/44586335/example', [[88, 31], [728, 90]],
'div-gpt-ad-1536691535894-0').addService(googletag.pubads());
if (typeof $.cookie('_sp_enable_dfp_personalized_ads') === 'undefined')
{
//no cookie
googletag.pubads().disableInitialLoad();
dfp_inital_load_disabled = true;
}
else {
if($.cookie('_sp_enable_dfp_personalized_ads') === 'true') {
googletag.pubads().setRequestNonPersonalizedAds(0);
} else {
googletag.pubads().setRequestNonPersonalizedAds(1);
}
}
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>

The next step in using the disableInitialLoad() method is to setup the consent and reject actions in the UI to fire for the user based on whether they have consented to DFP personalized ads or rejected them.

Consent Action Setup

For the consent action, we are likely to want to only fire this if there was no cookie present when the page load and the initial ad load was disabled. Therefore, we will use the variable we set up as a flag to manage this. If the flag is true then we will set googletag.pubads().setRequestNonPersonalizedAds(0) and then call the googletag.pubads().refresh() command. See code example below to enter into the consent actions window.

if(window.dfp_inital_load_disabled){
window.googletag.pubads().setRequestNonPersonalizedAds(0);
window.googletag.pubads().refresh();
}

Reject Action Setup

For the reject action setup, we will fire the googletag.pubads().setRequestNonPersonalizedAds(1) and then call the googletag.pubads().refresh() command

if(window.dfp_inital_load_disabled){
window.googletag.pubads().setRequestNonPersonalizedAds(1);
window.googletag.pubads().refresh();
}