Loading more adslots after scroll

(written by Olive Net)

I’ve been setting up responsive DFP ads that reload on a screen resize event. This uses the command

googletag.pubads().refresh();

It struck me that this might also be used after a scroll event to effectively have more than the regulation 3 adslots on a long page (assuming all DFP adslots are Adsense enabled and following Adsense rules).

After the top of the page has been scrolled away from, there is no need to reload the hidden ad units, they would be set to

display: none;

Another set of 3 ads further down the page loaded set to display: block, and the refresh called instead.

In fact it ought to be possible to only load any ads within the view window and reload on completion of a scroll action.

Has anyone come across anything like this? I can’t find anything on Google, although this is getting warm: Google Groups

This entry was posted in AdSense Placements and tagged , , , , . Bookmark the permalink.

7 Responses to Loading more adslots after scroll

  1. Olive Net says:
    Well, I started and have the basic mechanism using some neat jquery addons.

    https://gist.github.com/RubaXa/5569075 from Lebedev Konstantin is a mod that gives an event on the end of a user scroll. Otherwise jQuery scroll fires constantly.

    (Resource no longer exists) / (Resource no longer exists) jQuery visible gives a true/false depending on whether an element is in the view window or not.

    Add to header:
    <script src="/your/js/jquery.visible.min.js"></script> 
    <script src="/your/js/jquery.event.scroll.js"></script> 

    <script type='text/javascript'> jQuery(window).bind('scrollend', function (evt){ var visible_ad = jQuery('#div-gpt-######').visible(); if (visible_ad) { alert('ad visible'); // your dfp logic would go here } }); </script>
    the div-ad-######## is from the DFP adslot code.

    That will give an alert when the ad scrolls in to view, but could be used to carry out a calculation of what ads are visible and adjust the dfp code accordingly, before carrying out a refresh.

    I'll crack on with this when I next have time. If anyone else wants to try in the mean time, please do! It seems like a good idea but I'm strapped for time.
  2. Olive Net says:
    I have this working now, so on my forum index page a Skyscraper adunit (on a desktop) is reloaded further down the page as you scroll down. Likewise a single Leaderboard reloads in 5 different pre-defined positions as you scroll down.

    After a lot of trial and error with different jQuery plugins (one example in the post above, since scrapped), I settled on Waypoints, and the solution is pretty much given here. You'll see that as an ad comes in to view an action is taken:

    Scroll Analytics with jQuery Waypoints

    the only significant difference is that the action is to use jQuery append to move the DFP adslot code, then DFP refresh to reload the ad. This is my centre column function, that deals with moving the Leaderboard I described above.
    function showAd_cc(adslotid) { 
      jQuery('#div-gpt-ad-my-adslot').appendTo('#' + adslotid); 
      googletag.pubads().refresh([my-adslot]); 
    }
    Note, that the refresh method takes an adslot object, not the name of the adslot.

    I still have pretty scrappy code, with hardcoded ids and so on, so I can't give a complete solution, but if anyone wants more information just ask.
  3. christopher says:
    If I understand you correctly, the attempt is to put more ads on a page that is allowed?

    The do refer to it as a limit per 'page,' not a limit on a screen - https://support.google.com/adsense/answer/1346295#Google_ad_limit_per_page

    I think you are playing with fire with this one unless the adsense account is not all that important to you,

    Chris
  4. Olive Net says:
    It's more about making more use of the allowed 3 ads, but repositioning on long pages. I can't find any rules against moving ads within a page, in fact in many cases it's necessary to make pages responsive. The ads wouldn't fall foul of this:

  5. christopher says:
    I think that would be a good idea (checking with adsense). I'd love to hear what others here think of the idea. I like this forum, surprised it's not more active.
  6. Olive Net says:
    it's a 'no go' unfortunately. Not necessarily for the reasons you might expect, but actually because programmatic refresh of Adsense is not allowed, even using DFP's own function on backfilled adslots. Oh well, an interesting jQuery exercise for me!
  7. christopher says:
    Ah, interesting. I did not know about that guideline. Thanks for letting me know :)

Leave a Reply

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

*