How to Make DFP Tags GDPR Compliant

DoubleClick For Publishers / Google Ad Manager Ad Optimization
Last updated: September 15, 2021 | by Kean Graham
How to Make DFP Tags GDPR Compliant

This post was most recently updated on September 15th, 2021

GDPR is here, and not a lot of publishers are even ready for it. Despite months or years of preparation, publishers still end up with many unanswered questions.

pgu cta

If you are a publisher using DFP tags on your website, here is a simple step by step guide to making sure you protect your advertising accounts and ultimately, your bank account:

Sample original DFP header tag deployed on site (non-compliant to GDPR):

<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(‘/1234567/adunit_300x250’, [300, 250], ‘div-gpt-ad-55555-0’).addService(googletag.pubads());

googletag.defineSlot(‘/1234567/adunit_728x90’, [728, 90], ‘div-gpt-ad-55555-1’).addService(googletag.pubads());

googletag.pubads().enableSingleRequest();

googletag.enableServices();

});

</script>

What to do?

Step 1: Delete the first line:

<script async=’async’ src=’https://www.googletagservices.com/tag/js/gpt.js’></script>

Step 2: Replace above line with the following code block, putting the principle script inside the publisherCookieWrap function to stop it from loading until after the visitor has given their consent to cookies:

<script type=”text/javascript”>
window.pgjs = window.pgjs || {};
pgjs.publisherCookieWrap = function() {
pgjs.loadJS(‘https://www.googletagservices.com/tag/js/gpt.js’);
}
</script>
<script src=”https://cdn.pubguru.com/pg.js” />

Step 3: The other parts of the original DFP header remain as is.

Step 4: Optional: should you wish to customize the consent popup, deploy the below block of code before the pg.js script.

pgjs.gdpr = pgjs.gdpr || {};
pgjs.gdpr.disclosureTitle = ‘My Custom Title’;
pgjs.gdpr.disclosureBody = ‘My Custom Message’;

Step 5: Sample of a finished code (with customization):

<script type=”text/javascript”>
window.pgjs = window.pgjs || {};    pgjs.gdpr = pgjs.gdpr || {};
pgjs.gdpr.disclosureTitle = ‘My Custom Title’;
pgjs.gdpr.disclosureBody = ‘My Custom Message’;
pgjs.publisherCookieWrap = function() {
pgjs.loadJS(‘https://www.googletagservices.com/tag/js/gpt.js’);
}
</script>
<script src=”https://cdn.pubguru.com/pg.js” /><script> var googletag = googletag || {};googletag.cmd = googletag.cmd || [];</script><script>googletag.cmd.push(function() {googletag.defineSlot(‘/1234567/adunit_300x250’, [300, 250], ‘div-gpt-ad-55555-0’).addService(googletag.pubads());googletag.defineSlot(‘/1234567/adunit_728x90’, [728, 90], ‘div-gpt-ad-55555-1’).addService(googletag.pubads());googletag.pubads().enableSingleRequest();googletag.enableServices();});

</script>

Step 6: To include your Google Analytics tracking code:

<script type=”text/javascript”>
window.pgjs = window.pgjs || {};    pgjs.gdpr = pgjs.gdpr || {};
pgjs.gdpr.disclosureTitle = ‘My Custom Title’;
pgjs.gdpr.disclosureBody = ‘My Custom Message’;
pgjs.publisherCookieWrap = function() {
pgjs.loadJS(‘https://www.googletagservices.com/tag/js/gpt.js’);    pgjs.loadJS(‘https://www.googletagmanager.com/gtag/js?id=UA-1234567-1’);     window.dataLayer=window.dataLayer||[];function gtag(){ dataLayer.push(arguments); }gtag(‘js’,new Date());gtag(‘config’,’UA-1234567-1′);
}
</script>
<script src=”https://cdn.pubguru.com/pg.js” /><script>var googletag = googletag || {};googletag.cmd = googletag.cmd || [];</script><script>googletag.cmd.push(function() {

googletag.defineSlot(‘/1234567/adunit_300x250’, [300, 250], ‘div-gpt-ad-55555-0’).addService(googletag.pubads());

googletag.defineSlot(‘/1234567/adunit_728x90’, [728, 90], ‘div-gpt-ad-55555-1’).addService(googletag.pubads());

googletag.pubads().enableSingleRequest();

googletag.enableServices();

});

</script>

Step 7: Remove previously deployed Google Analytics & DFP header codes and replace with the above code. It is recommended to have it on a test page first.

Step 8: If you want to save it as HTML to test

#1 – Open a notepad

#2 – Copy and paste the finished code

#3 – Save the file

#4 – When naming it, add .html (e.g. offpage.html)

offpage.html

#5 – Save

#6 – Click the saved file and it should open in your browser

Step 9: Testing parameters you can use.

append ?pg_gdpr=popup to the URL to force the popup to show
append ?pg_gdpr=emulate-eu to the URL to force a production test as you’re in the EU
append ?pg_gdpr=reset-cookies to the URL to reset cookies

Step 10: Open the test page/HTML file > right click > inspect.

Step 11: Click on the Network tab.

Step 12: Append the URL with ?pg_gdpr=emulate-eu and reload the page.

Step 13: You should see a popup and pg.js is loaded.

desktop code

Step 14: Click on the consent button, and your DFP + Google analytics are then loaded.

desktop code 2

Step 15: Deploy the entire GDPR compliant code within the <head> </head> portion of your site.

Conclusion

Do you have anymore DFP (now Google Ad Manager) and GDPR related questions? If so, why not let the experts help?  MonetizeMore is a Google Certified Publisher Partner and can help you become GDPR and TCF 2.0 compliant while ensuring your ads are optimized. Sign up for a Professional account at MonetizeMore today!

Ad Ops Tips & Guides, Industry News, Latest Tech and Success Stories - right in your inbox.

We are committed to protecting you Privacy Data

Here’s the course that 300+ pubs used to scale their ad revenue.

Enroll today

Book Banner

Recommended Reading

what-is-google-ad-manager
AdTech Industry Definitions
November 28, 2022

What Is Google Ad Manager – How to 10X Revenue with GAM?

Read More
top-ad-servers-for-publishers-best
Ad Servers
November 27, 2022

Best Ad Server Platforms For 2023

Read More
how-ad-blockers-work
Ad Blocking
November 25, 2022

Simple Strategies For Publishers To Combat Ad Blockers

Read More
Close

Enjoying this post? Let's put things to action

Get started