How to set up AdSense using DFPs build in AdSense option – Async Version

It is time for a new Chapter of my DFP Small Business Tutorial. In Oktober 2011 Google introduced the new Google Publisher Tag for DFP Small Business. The new Google Publisher Tags has a number of new benefits and improvements over the existing Google Ad Manager Tags including faster page loads due to an asynchronous JavaScript fetch. This tutorial explains how to set up AdSense using DFPs build in AdSense option by using the asynchronous Google Publisher Tags. Read more about the new Google Publisher Tags here: DFP goes asynchronous with its new Google Publisher Tag. Time to switch

If you are using the old Google Ad Manager Tags read the old version of this tutorial here: How to set up Google AdSense using DFP Small Business build in AdSense option

In the Chapter How to set up Google AdSense as Line Item using DFP Small Business I told you how to set up AdSense as a Third Party Creative. I choose this way because the build in AdSense Feature of DFP didn’t offer all the functionality that AdSense provided. Or at least I did not now how to do it. However things have changed.

The build in AdSense Feature of DFP provides everything we need to set up AdSense without the need for creating a lot of Line Items and Creatives and still have the full functionality of the old set up.

So how to use the build in AdSense Feature to display AdSense on your website?

I assume you already set up DFP Small Business to serve Ads on your website which means you created Ad Units and implemented the tags into your HTML source code.

Now go to your Inventory Tab in DFP and select the Ad Unit you want to display AdSense in. Click on override next to “AdSense inventory settings – Disabled”

override_adsense

and check the checkbox before “Maximize revenue of unsold and remnant inventory with AdSense”. This interface should look familiar to you now. Make your AdSense Settings and Styling Settings and click Save.

override_adsense_expanded

Now your Ad Unit will serve AdSense Ads on this Ad Unit.

 

ATTENTION:

Due to changes in DFP Small Business and AdSense Reportings tracking AdSense served via DFP with Custom Channels is no longer possible!
The part below is no longer needed / does not work anymore.

 

BUT even though AdSense is served now, we still don’t have a Channel attached to the AdSense Ad to track its performance. This was the main reason for me to suggest my first method to serve AdSense Ads as Third Party Creatives. But fortunately there is a way to attach a channel (or other attributes) to AdSense via DFP Tags.

You can override AdSense Settings on a per page and per unit level.

Available keys:

New parameter Example Allowed values
adsense_channel_ids 271828183+314159265 valid AdSense channel IDs, separated by ‘+’
adsense_ad_types text_image text, image, text_image
adsense_ad_format 250x250_as 468x60_as, 234x60_as, 125x125_as, 120x600_as, 160x600_as, 180x150_as, 120x240_as, 200x200_as, 250x250_as, 300x250_as, 336x280_as, 728x90_as
adsense_background_color #000000 hexadecimal colors
adsense_border_color #000000 hexadecimal colors
adsense_link_color #000000 hexadecimal colors
adsense_text_color #000000 hexadecimal colors
adsense_url_color #000000 hexadecimal colors
adsense_ui_features rc:10 rc:10 for very rounded corners, rc:6 for slightly rounded corners, rc:0 for square corners (default)

So how do we attach an AdSense Channel to our Ad Unit? First you need to create your Custom Channel in AdSense for this specific Ad Unit. Login to AdSense, go to “My Ads > Custom Channels”.

If you did not create your custom channels yet this is the time to do so. Read this for more information on AdSense custom channels: Different strategies to use AdSense Channels

Next to the channel name for your AdSense Ad Unit you find the Channel ID which is a 10+ digit number, note it down.

adsense_channel_id

Now we need to edit the DFP Small Business Ad Unit Tag that we implemented in our website header to add the custom AdSense Channel to our Ad Unit.

You now have to options

  1. you can attach one or more AdSense Channels to all Ad Units on the page by using: googletag.pubads().set(“key”, “value”); (see the bottom of this page for an example)
  2. or you can attach a channel to each Ad Unit on a page individually by using: var slot = googletag.defineSlot(“/1234567/skyscraper”, [160, 600]).addService(googletag.pubads());slot.set(“param”, “value”);(recommended)

For this tutorial I assume that you have more then one Ad Unit on a single page so we choose the second option to attach our AdSense Channel IDs to our Ad Units.
If you want to overwrite other AdSense settings, check the above table for keys and values you can override.

key: adsense_channel_ids
and value is the AdSense Channel ID you noted down earlier.

So this is what your DFP Small Business header Tag (the new Google Publisher Tag asynchronous version) looks like before we attach channels:

<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();</script>
 
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/1025030/PatFra-LR-1P-First_Aid', [336, 280],
'div-gpt-ad-1319984924533-0').addService(googletag.pubads());
googletag.defineSlot('/1025030/PatFra-LR-1P-Threads-Urology', 
[336, 280], 
'div-gpt-ad-1319984924533-1').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>

And this is the way you attach AdSense Channels to your DFP Ad Units:

<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();</script>
 
<script type='text/javascript'>
googletag.cmd.push(function() {
var slot1 = googletag.defineSlot('/1025030/PatFra-LR-1P-First_Aid', 
[336, 280],'div-gpt-ad-1319984924533-0').addService(googletag.pubads());
slot1.set("adsense_channel_ids", "38234470929");
var slot2 = googletag.defineSlot('/1025030/PatFra-LR-1P-Threads-Urology',
[336, 280],'div-gpt-ad-1319984924533-1').addService(googletag.pubads());
slot2.set("adsense_channel_ids", "3867876929");
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>

If you want to attach multiple channels to one Ad Unit use + to add more then one channel ID:

slot.set("adsense_channel_ids", "4132147310+4132127310+4132147319");

Take note of the Counter in var slotX and slotX.set
where X is 1,2,3…. depending on the number of Ad Units you have on the page.

Now your DFP Small Business Ad Unit serves AdSense whenever there is no other creative to be served and AdSense is tracked by custom channels.

This way you don’t need to create line items and orders for each of your websites and AdSense Ad Units which should save you a lot of time.

 

Example for attaching the same AdSense Channel to all Ad Units on a single page:

<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();</script>
 
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/1025030/PatFra-LR-1P-First_Aid',
[336, 280],'div-gpt-ad-1319984924533-0').addService(googletag.pubads());
googletag.defineSlot('/1025030/PatFra-LR-1P-Threads-Urology',
[336, 280],'div-gpt-ad-1319984924533-1').addService(googletag.pubads());
googletag.pubads().set("adsense_channel_ids", "38234470929");
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>

Next Step: How to run Split Tests with DFP Small Business
Previous Step: How to set up Google AdSense using DFP Small Business build in AdSense option

42 Responses to How to set up AdSense using DFPs build in AdSense option – Async Version

  1. Many Thanks for your Tutorial! It helped me a lot. Note that currently all custom channels are added to the generated code . There is no need to edit the Ad unit tag in your page.
  2. Michael Scheel says:
    What do you mean by that? I am talking about custom AdSense Channels and not DFP Placements. Or do you know a method to attach custom AdSense Channels to DFP Ad Units that I did not wrote about here? If you mean the option "Copy AdSense targeting" for placements, this will double your channels in your AdSense report which makes the report a little cluttered. You don't have that if you use my approach. But I will write a tutorial for how to use placements in the near future too.
  3. What do you mean by that? I am talking about custom AdSense Channels and not DFP Placements. Or do you know a method to attach custom AdSense Channels to DFP Ad Units that I did not wrote about here? If you mean the option "Copy AdSense targeting" for placements, this will double your channels in your AdSense report which makes the report a little cluttered. You don't have that if you use my approach. But I will write a tutorial for how to use placements in the near future too.
  4. Chris Prescher says:
    Thanks very much for your excellent tutorial! I have one question about the example you show above. In this line: var slot
  5. googletag.defineSlot("/1234567/skyscraper", [160, 600]).addService(googletag.pubads()); What does the "1234567" value represent? Or is the total value between the "" just the name of the DFP Ad Unit? Thank you.