Results 1 to 8 of 8

Thread: Loading more adslots after scroll

This discussion is about "Loading more adslots after scroll" in the "AdSense Placements" Forum.
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 ...

  1. #1
    Registered User
    Gender
    ?
    Country
    United Kingdom
    Join Date
    05-10-12
    Posts
    7

    Default Loading more adslots after scroll

    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: ((login for URL))

  2. #2
    Registered User
    Gender
    ?
    Country
    United Kingdom
    Join Date
    05-10-12
    Posts
    7

    Default

    Well, I started and have the basic mechanism using some neat jquery addons.

    ((login for URL)) from Lebedev Konstantin is a mod that gives an event on the end of a user scroll. Otherwise jQuery scroll fires constantly.

    ((login for URL)) / ((login for URL)) 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.

  3. #3
    Registered User
    Gender
    ?
    Country
    United Kingdom
    Join Date
    05-10-12
    Posts
    7

    Default

    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:

    ((login for URL))

    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.

  4. #4
    Registered User
    Gender
    ?
    Country
    United States
    Join Date
    09-26-12
    Posts
    18

    Default

    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 - ((login for URL))

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

    Chris

  5. #5
    Registered User
    Gender
    ?
    Country
    United Kingdom
    Join Date
    05-10-12
    Posts
    7

    Default

    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:

    ((login for URL))

    I would hope that Google would use some common sense in this area - if you have a page that's many screen sizes long, then it makes sense to make use of that space. My forum index page has no more than one ad visible at a time on most of it, even with this modification.

    An alternative is to chop the page in to smaller chunks and page between them, with 3 ads per page, which basically is the same thing but in some cases not as user friendly.

    It's at best grey though, so I will ask an account manager once I have a one page demo live. More news when I have it!

  6. #6
    Registered User
    Gender
    ?
    Country
    United States
    Join Date
    09-26-12
    Posts
    18

    Default

    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.

  7. #7
    Registered User
    Gender
    ?
    Country
    United Kingdom
    Join Date
    05-10-12
    Posts
    7

    Default

    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!

  8. #8
    Registered User
    Gender
    ?
    Country
    United States
    Join Date
    09-26-12
    Posts
    18

    Default

    Ah, interesting. I did not know about that guideline. Thanks for letting me know

Search Cloud:

scroll to refresh ads

Like It?
Share It!









Follow AdSenseExperts.com on Twitter