How to Make DFP Tags GDPR Compliant

How to Make DFP Tags GDPR Compliant

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.

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 and GDPR related questions? If so, why not let the experts help? Contact MonetizeMore for a free consultation and make sure your DFP ad tags are 100% GDPR compliant today!

Get my ad optimization tips and tactics delivered to your mailbox.

Kean Graham

CEO and Founder at MonetizeMore

Kean is the resident expert in Ad Optimization covering areas like Adsense Optimization, DFP Management, and third-party ad network partnerships. Kean believes in the supremacy of direct publisher deals and holistic optimization as keys to effective and consistent ad revenue increases.

Submit a Comment

Your email address will not be published. Required fields are marked *