Editor choice

How to Auto-Refresh Ads in DFP (DoubleClick for Publishers)

Ad Refresh! A lot has been discussed about them. The dos, don’ts and what-nots. But here, we are not talking about refreshing AdSense ads. Note: If case you’re not aware of the policy update, I’d like to remind you that ADX allows its publishers to refresh ad units. However, refreshing an ad unit makes a user irritated and is not recommended unless you’ve seen much higher CPMs with refreshing them. However, our topic of the day is, how we can refresh ads served via DFP. Here we are talking about in-house ads. A lot of marketers use DFP to target ads to their audience. Agreed! Affiliate marketing can make you thousands of dollars, and even more if properly done.

Refreshing In-house ads or Affiliate marketing campaign ads via DFP can be one of the easiest way to increase affiliate sales and earnings.

Use Case: A lot of marketers choose 2-3 banners and show them on their blog. Most of these banners are sidebar ads. Due to space constrain, there can only be 2-3 sidebar ads at max. However, the total number of high performing campaigns are around 10 plus. Under such a circumstance, adding multiple creatives in a line item and then calling the them at specific intervals of 30, 45, 60 seconds can increase the change of users viewing more ads/creatives, and an enhanced CTR.

Looking to increase your website revenue. Simply fill up this form and we shall get back to you.
courtesy: Google

courtesy: Google

Even, if you’re doing direct advertisement deals, and your site is popular, you don’t want to give the entire session of a user for one ad unit, rather make the advertiser agree for a 30 or 60 second ad duration. In this way, you can serve more ad impressions on your blog.

Interestingly, you can also tell DFP to display those ads which are getting high clicks, and give some opportunity to other ad units for potential clicks. This will show weightage to the top performing ad unit (in terms of click) and ensure that your ad space is properly monetized. These are some of the benefits of auto-refresh ad tags on DFP. In this tutorial, I will share with you the necessary ad codes that will help you enable create such custom banners which will be your money-making magnet.

Refresh your Ads in DFP without Refreshing your Webpage

Google DoubleClick for Publishers have provided a functionality using which, you can refresh ads directly without a user triggering it. To do so, you’ll have to add a few line of code on your website.

Let’s start with our standard GPT tag


The above sample code in the <head> section will serve an ad without an ad refresh. Let’s say, I want this ad tag (“defineSlot() function”) to be called every 30 seconds automatically. To achieve this, I’ll first assign it to a variable (specialty of JavaScript). See below:


We are not done yet. Another code has to be placed in the display call i.e., the respective code which we place in the webpage’s <body> section. The new code should be:


You’ll notice that the variable “_Mrec” which we’ve defined before is being used here. As we’re interested in refreshing the ad slot in every 30 seconds, we must include 30,000 milliseconds at the end of this function.

The refresh code has to be placed after the googletag.display() function. See here:


Below is the complete code, just copy it and change the DFP code, ad unit & the ad size (highlighted) and you’re done with your work

<script async=’async’ src=’https://www.googletagservices.com/tag/js/gpt.js’></script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];

googletag.cmd.push(function() {
var _Mrec = googletag.defineSlot(‘/46400095/123_300x250’, [300, 250], ‘div-gpt-ad-1476516294335-0’).addService(googletag.pubads());

<!– /46400095/123_300x250 –>
<div id=’div-gpt-ad-1476516294335-0′>
googletag.cmd.push(function() {
setInterval(function(){googletag.pubads().refresh([_Mrec]);}, 30000);

Can I Refresh AdSense Ads?

Please make sure that you DO NOT serve AdSense ads on such positions. As per Google AdSense policy, refreshing an AdSense ad can terminate your Google AdSense account. You can however, refresh AdX ads but you need to have an approved sub-ADX account for that and declare the existence of such ads in the line item.

Benefits of Auto Refreshing Ads

We have already discussed the benefits of auto-refreshing ads above. They are particularly important for serious marketers and publishers with direct advertisers. Auto-refresh ads will allow publishers to sell more ad impressions on his site and keep the site clean and less clutters.

Things to Keeping in Mind while Auto-Refreshing Ads via DFP

There are a few things that you should keep in mind while auto-refreshing ads on DFP.

  • Adding refreshing to ad units can impact your audience negatively. So, we recommend to refresh not more than 2 ad units.
  • It is always advisable to use auto-refresh on ad units with desktop traffic. Since, on mobile there isn’t much opportunity for your audience to view the refreshed ads.
  • Use a sticky ad code for a sidebar ad which you’re auto refreshing. Keep the refresh rate of this ad at 30 seconds. While, you can keep the refresh rate of other ads at 60 seconds.
  • Use appealing creatives which using ads to increase their CTR.
  • Let DFP allow higher impressions to those creatives which are clicked more.

Drawbacks of Auto-Refreshing Ads

The only drawback of auto-refreshing ad is its annoys the user. However, this can be safeguarded if you don’t refresh all the ads.

Wrapping Up

If you’re new to DFP, you might face setting up auto-refresh since they’re a bit tricky for beginners. Feel free to connect with me, I am here to help! This post is listed under the series “Advanced Guide to DFP” where I will be posting other interesting info as well. Read more about Auto-refreshing ADX ads here.

Recommended List for You:

Works as an ad optimization specialist helping publishers increase their ad revenue in display, video, native, and high impact ad formats. You can contact him on skype (skype id: ronniedey) to increase your ad revenue immediately or hire him for a consultation. If you're an ad network owner, do get in touch for sponsored reviews.

  1. Hi I am currently working on clients web site and they want to auto refresh dfp tags. I am not sure what is entirely legal and what is not. I noticed there are a few differen types of dfp tags and would like to know which auto refresh can apply to and which not.

    I want to use slot rendered event listener and refresh on paticular slots from there. Is there a way to determine if an paticular ad slot runs adsense and which adx.

    Any help will be much appreciated.

    • Hi Stefan,

      Auto refresh of AdSense ads is not allowed. However, you can auto-refresh AdX ad tags. So, if you want to compete AdSense line items with ADX line items for a particular ad unit, then also, you cannot auto refresh those ads since, it would mean you’re auto-refreshing adsense as well. You may auto refresh ads from other networks provided they allow the same, along with in-house ads. Do let me know if this helps. Do get in touch with me on skype if you’d like to discuss more about it. My id is: ronniedey

  2. Hi,

    i dont know auto-refresh ad is legel or illegal but mashable.com is currently using auto refresh google ads.

    if you will be successful in doing that also reply on my mail thank you.

  3. Hello,

    you have actually an error in your code.

    You define _Mrec as a local variable inside the first googletag.cmd.push function, so it’s not available later in the second inside the div.
    Instead the declaration should be
    _Mrec = googletag.defineSlot(‘/46400095/123_300x250’, [300, 250], ‘div-gpt-ad-1476516294335-0′).addService(googletag.pubads());
    At least this is what worked for me, as the former raised an error of an undeclared variable _Mrec


  4. hello, Abhishek
    We Have Made A Deal With The Direct Advertiser, That We Will Be Using 10 seconds Ads Refresh, We Have Only 2 Slots In The Website, Does DFP Allow Us To Do 10 seconds Refresh. If Not Are There Any Adserver Which Can Help Us

Leave a reply

%d bloggers like this: