Forum Moderators: martinibuster

Message Too Old, No Replies

Showing unlimited number of banners (coding practices)

         

csdude55

2:43 am on Jan 28, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I couldn't decide whether this is an Adsense question or a Javascript question :-/

I'm setting up my pages for infinite scroll (jScroll). My current site has:

300x250 Adsense

300x400 local stuff

300x250 Adsense

300x400 local stuff

... then at the bottom of longer pages
300x250 Adsense


But since now Adsense allows for unlimited banners, I guess I would want:

while (something) {
300x250 Adsense

300x400 local stuff
}


just repeated over and over for as long as I have room. So if a page is 20000px long, I could potentially have 30 sets of those two elements.

So the question is:

1. Do I need to set up 30+ tags and pull up a different tag for each block? Or should I just use the same tag over and over? If I should use the same tag, then is there a concern that a lower CTR on tags further down the page would negatively impact the overall value of the tag?

2. Is there a standard method to do this, or am I going to have to roll my own? Something like this (just written for this post):

<script>
var i = 0;
var column_height = document.getElementById('container').clientHeight;

while (column_height > 700) {
document.write('<div id="container_' + i + '">');
document.write(' <div style="margin: 10px 0; padding: 10px; width: 300px; height: 250px">');

document.write(' <ins class="adsbygoogle"');
document.write(' data-ad-client="ca-pub-xxxx"');
document.write(' data-ad-slot="xxxx"></ins>');

// Somehow plug this in to the loop
//<script>(adsbygoogle = window.adsbygoogle || []).push();</script>

document.write(' </div>');

// Ajax link to local stuff
document.write(' <div id="block_"' + i + '" style="margin: 10px 0; padding: 10px; width: 300px; height: 400px"></div>');
$('#block_' + i).ajax('$link_to_local_stuff');

document.write('</div>');

column_height -= document.getElementById('container_' + i).clientHeight;
i++;
}
</script>


FWIW, I've reviewed the sample on lazy loading, here:

[support.google.com...]

But (1) it's hard to follow, and (2) it doesn't really specify how to do this in a loop, and whether to use the same tag for each.

TIA!

keyplyr

3:06 am on Jan 28, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



But since now Adsense allows for unlimited banners, I guess I would want:
Do you think your visitors want to see "unlimited banners?"

csdude55

3:33 am on Jan 28, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you think your visitors want to see "unlimited banners?"


Unknown, so this is more or less an experiment. What I know, though, is that when I implement infinite scroll, the user will end up with a long, long right column of white that has no visual interest.

All I know to do is try it and see what happens. If it doesn't work out then it's not that big of a deal to go backwards, but I won't know until I try.

csdude55

3:43 am on Jan 28, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Update to the pseudo-code I posted, it looks like the better option is using DFP:

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

<script>
var i = 0;

googletag.cmd.push(function() {

// I guess pick a maximum number of banners? I'm not sure if I can get the height
// of "container" here before it's created, so I picked 50 at random
while (i < 50) {
googletag.defineSlot('/xxxx/300x250', [300, 250], 'div-gpt-ad-xxxx-' + i).addService(googletag.pubads());
i++;
}

googletag.enableServices();
});
</script>
</head>

<body>
...
<script>
var i = 0;
var column_height = document.getElementById('container').clientHeight;

while (column_height > 700) {
document.write('<div id="container_' + i + '">');
document.write(' <div id="div-gpt-ad-xxxx-' + i + '" style="margin: 10px 0; padding: 10px; width: 300px; height: 250px">');
googletag.cmd.push(function() { googletag.display('div-gpt-ad-xxxx-' + i); });
document.write(' </div>');

// Ajax link to local stuff
document.write(' <div id="block_"' + i + '" style="margin: 10px 0; padding: 10px; width: 300px; height: 400px"></div>');
$('#block_' + i).ajax('$link_to_local_stuff');

document.write('</div>');

column_height -= document.getElementById('container_' + i).clientHeight;
i++;
}

tangor

3:52 am on Jan 28, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Aside comment: js disabled browsers won't display anything. (There are more than a few out there)

csdude55

8:37 am on Jan 28, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That wouldn't be a tragedy in this case, tangor. They would have enough problems with my site with JS disabled that I doubt they'd stick around for long, anyway. And honestly, if they're not able to view ads then they have limited value to me, so it's an acceptable loss.

Dimitri

10:27 am on Jan 28, 2017 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



In all events,JS disabled browsers will not load adsense at all, so it's not changing anything.

That being said, I don't think you can use document.write to "append" content to a page after it has been loaded by the browser.

LuckyD

3:44 pm on Jan 28, 2017 (gmt 0)

10+ Year Member Top Contributors Of The Month



csdude55, I don't have the exact numbers in mind, but, as far as I remember, my rep told me that after 3 ads you can only display one additional one every 800 pixels.
So I'd be careful on the policy part. Just give yours a quick call to be sure.

NickMNS

4:08 pm on Jan 28, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@tangor

Further to Csdude55's point. I understand and prescribe to the concept of progressive enhancements but there has to be line drawn in the sand at some point. I am working on a new site using Bootstrap 4, which has no support for IE9 and below. So that is my line, you need to have JS and a minimum IE10 and 11. And regarding IE/ME products, I will do my best to show you something, the format may be a bit messed up but you will get the gist of it. If you want to see the site in all of it's glory you will need to install a real browser.

I am a one man show I cannot afford the time and effort required to produce a perfect product, where 80% of the effort goes to writing workarounds for something like 5% of my audience. I rather spend that effort building something awesome for the 95% of my audience. Not to mention the fact that the more awesome you add the more effort is required to build workarounds.

I can accept that people do not want to upgrade their browsers, for whatever reason. But not upgrading has cost.

tangor

1:24 am on Jan 29, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not suggesting folks don't code as they like, just suggesting that up to 25% of visitors might not see enough of a site to decide if they will white list or turn on their js. That's a significant number.

csdude55

2:19 am on Jan 29, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In my particular case, the audience is predominately repeat traffic for many years so it's not really a concern. Besides, my navigation is in Javascript, and I've changed all of my dropdown menus to Ajax, so people not using Javascript would have already been turned off 5 or 6 years ago.

There's no real way for me to know what percentage of my traffic they represent, since Analytics wouldn't count them, either. But since they see no ads, they bring little (if any) value to the site, anyway. So if they leave, it won't show up in Analytics or Adsense, so I'll never know (or care).


csdude55, I don't have the exact numbers in mind, but, as far as I remember, my rep told me that after 3 ads you can only display one additional one every 800 pixels.


Hmm, now this is interesting. I haven't seen that 800px limit anywhere, but that doesn't mean they're not arbitrary. Here is the actual policy:

[support.google.com...]

Can anyone else confirm this 800px guideline? I can easily change mine from 700 to 800 if necessary, I just need to know for sure. I don't have a rep to ask :-(

Otherwise, am I right that there's no "standard" code for this, and what I wrote would be OK?