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

< DFP Small Business Tutorial

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>

< DFP Small Business Tutorial

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

  1. Tony Page says:
    This is all excellent stuff, admin, and your tutorials have been a real help to me as I move fromsite wideAdSense to DFP usin AdSense as the remnant (although currently only) advertising. One question, why do you disable AdSense and then override it, rather than simply enable it as the remnant choice? Thanks again, Tschuess!
  2. Carlotta Daldoss says:
    Hi admin, first of all THANK YOU for your great job with this tutorial... I think I could solve so many things in only one day that we'll take me months without this!

    I have a question if you (or someone reading) experience this. I place 2 orders of clients of us in some ad units of my page and for the most of the time it works fine, and then without any change it start to show adsense or a white space.

    I understood that adsense only enter if you didn't sell the space so I cannot understand why they appears in that ad unit sold and also why only sometimes. when this happen the image of our customer ad disappear and is not shown even if I refresh the page, only empty space or adsense.

    Any idea?

    thanks again, Carlotta
  3. Antonio Romero says:
    Hello,

    can we combine both? Defining var slot1, slot2 etc

    And at the same attaching the same channel to every adunit with googletag.pubads().set('adsense_channel_ids' '38234470929');

    or do we have to add that "382344...." to each var slot1, slo2 with "+"??

    Thanks
  4. Antonio Romero says:
    Another question,

    do we need to create ad in google adsense and then assing the channels, or it is enough with creating the channels, assign them to ad units, and let DFP publish adsense ads?

    BR
  5. albo82 says:
    Hi, thanks for this wonderful guide

    I'm trying to use var slot1 but doesn't show me any advertising!

    is there any mistake?

    googletag.cmd.push(function() var slot1=googletag.defineSlot("/17676156/atbf_728_prova", [728, 90], "div-gpt-ad-1349270454725-0").addService(googletag.pubads());slot1.set("adsense_channel_ids", "0211110617"); googletag.pubads().enableSingleRequest(); googletag.enableServices(); );

    THANKS
  6. Jason says:
    Hi admin,

    Just wondering if you have any updates as to how this is working? Has anyone been able to implement multiple channels to ad units using the '+'?

    I note that on Google's known issues page that the new Adsense UI will not display reporting data for ad units and custom channels in DFP. Is this statement correct for users?

    Lastly, I've read that there are issues of double-counting of impressions in Adsense with people using custom channels. Is this the case?

    Would be great to get some clarity around these points before spending many hours creating channels and editing tags!

    Thanks!

    • admin says:
      I checked my stats and they are still reporting the custom channels defined in DFP SB. I can't tell if it works with multiple channels but why shouldn't it? I don't have the double counting problem either. The reason for this was the asynchronous loading with the single request method as far as I remember. If you encounter the problem first try to disable single request and if that does not fix it use synchronous loading of ad units.
  7. José F. says:
    Hi admin,

    First of all, thank you for this great tutorial.

    I have followed all the steps you pointed out above but I am not getting any data on my adsense channel report:

    1.- I created the dfp ad units.

    2.- I tagged one page

    3.- I created new adSense channels (I see the picture above where targetable option is "no" and I have "yes", might it be that the problem?).

    4.- I rewrote the tags code so I added the ad units to the new created adSense channels

    5.- I can't see any data on the adSense channel report

    6.- I waited 24 hours until I wrote this post :-)

    Is there something I am missing? Bassically I am ussing DFP to serve adSense plus some "house adds" on my pages. I want adSense advertisers being able to target this channels as it's been being until now.

    Just one more questions... Are the adSense channels and DFP placements same from the advertisers point of view?

    Any help would be greatly appreciated.

    Again, thank you very much!
    • admin says:
      I forgott to add a comment I added in the other article to this article:

      Due to changes in DFP Small Business and AdSense Reportings tracking AdSense served via DFP with Custom Channels is no longer possible!
      • José F. says:
        admin, thank you for your time. It is strange... I started to see new data in adSense reports after 3 days. But there they are. I followed the steps above. Anyway... after all these ongoing changes, what do you think is the best way to go if I want adWords advertisers beeing able to reach my site?

        With adSense I created a custom channel and I clicked on "Show this custom channel to advertisers as a target". What is the best way to go when adSense is integrated into DFP?

        P.S. As far as I know, allowing advertisers to reach my site through adSense custom channels increase my revenue so that's the reason why I am quite interested in doing so in DFP.
        • admin says:
          I don't think this is possible in DFP. AdSense in DFP is a fallback option if you have unsold inventory left. If you use DFP just to serve AdSense you might want to rethink your approach if you have a lot of advertisers booking your custom channels.

          Anyway, try the AdSenseExperts-area for these kind of discussions. It's a better place then comments on a blog ;)
          • José F. says:
            Thanks admin
  8. TempestMaker says:
    So now that we can't attach channels with this method, might it make sense to go back to the line item adsense method? My understanding is the disadvantages to that are 1) load speed, since it requires a call to DFP then a call to adsense, and 2) convenience, since you have to set up all the line items. On the other hand, it will allow advertisers to target your channels directly (and preserve any direct targeting already in place if one is using adsense without DFP now). Sound about right?
    • admin says:
      If you are using DFP to mainly serve AdSense then yes, switching back to the line item method is the best approach. If you use it as fallback then keep the DFP AdSense option to compete AdSense with your third party inventory
      • TempestMaker says:
        Thanks admin. I just noticed, in the DFP SB settings to create a placement (a group of Ad Units), there is a "Google Adwords" checkbox, followed by this option:

        "Copy AdSense targeting

        If you maintain targetable channels in your AdSense account, copy site targeting settings from an AdSense channel to continue to generate revenue from AdWords campaigns that are targeting your site."

        Would that work? Or does it just generate the code mentioned above, which no longer works?
  9. pitter says:
    hi,

    I came here first through google.

    I wanna link more than 2 adesnse account with a my DFP. what is process to adding more than 2 different adsense on single DFP. Is it possible I can manage my two adsense through single dfp SB.
    • admin says:
      Use creatives for your AdSense codes. It does not matter from which account the AdSense code comes. However don't put more then 3 Ad Units on your page
  10. Travelsignposts says:
    (This is Tony Page, don't know why I couldn't post as earlier!) Sorry for the delay in responding, admin, I thought I'd get an email alert. Yes, I was referring to enabling it via the network setting.

    In relation this, I have a question re a possible double counting issue using the custom channel linking. I came across this comment on the DFP forum:

    "DFP Backfill numbers will show up in the aggregate performance reports, but not when filtering by ad unit or ad size."

    Does this mean that if I link up my DFP ad unit that uses AdSense as the remnant option to an AdSense Custom Channel that the pageviews are counted twice in AdSense aggregate performance reports?

    The reason I ask is because I am currently experiencing a sudden rise in the number of Adsense pageviews being reported, 30% or more above the Analytics pageview count. Obviously this is different technology and not ad impression based, but the difference does appear to bear some relationship to the DFP remnant numbers.

    Have you had any experience of this?
  11. Travelsignposts says:
    Thanks for the response, admin. It looks like I'll have to find another explanation, as the increase is unfortunately lowering my CTR and presumably quality score. Such is life!
  12. albo82 says:
    I followed this page in which we are writing since i'm using async version. so i m using adsense as "override" the problem is that when i write the original code it works:

    googletag.cmd.push(function() googletag.defineSlot('/17676156/atbf_728_prova', [728, 90], 'div-gpt-ad-1350394427092-0') .addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.enableServices(););

    .............but when i use the "var slot" it doesn't work

    googletag.cmd.push(function() var slot1=googletag.defineSlot('/17676156/atbf_728_prova', [728, 90],'div-gpt-ad-1349270454725-0') .addService(googletag.pubads()); slot1.set("adsense_channel_ids", "0211110617"); googletag.pubads().enableSingleRequest(); googletag.enableServices(););
  13. Chris says:
    I have the same problem with my page. I inserted the "var slot" code for every single channel but none of my adsense ads where shown. I removed it and was all ok again. Is the problem focused on the ' character? What's the correct one to be used? Thanks for your time.
  14. admin says:
    Custom channels wont work anymore with the DFP AdSense option

Leave a Reply

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

*