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.

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:

Increase you programmatic display, video, and native ad revenue by booking a consultation with me. This limited time $150 consultation would include suggestions on how you can increase your website revenue. I have worked with more than 80 ad partners and would only recommend the ones that will bring in good revenue based on your traffic and niche. Additionally, you will be getting two guides-- that can help you setup video ads which pays CPMs of USD 12 and above for tier 1 traffic and USD 5 and above for tier 2 traffic. (I spent almost $1000 testing different players etc, but you don't have to). Also you get a guide to setting up auto-refresh ad units (took me hours getting the code ready but it generates additional 40% in display revenue for me). All these information would worth $2000 and above if you're going to learn by doing it yourself, plus there is a significant time cost involved as well. These steps, if implemented will guarantee least 50-100% revenue uplift on your blog or website. Since the slots are limited and I offer a one to one consultation, please book your preferred slot here. Do connect with me on my skype id:ronniedey. Looking forward to our 1-on-1 discussion to help assist in increasing your ad revenue.

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

  5. is it possible to refresh after an ad has been “in view” for etc 30 secs or someone has scrolled down the page and then back up the page, so as the ad is back in view and then fires a refresh?

  6. any pointers on where to look? i cant seem to find anything on it

Leave a reply

%d bloggers like this: