Tips: Google adsense
One of the recent improvements to my little blog has been moving Google ads from the sidebar to every third post on the main page. In attempting to detect whether a full-size leaderboard ad would fit, versus a banner ad, I’ve found that loading a responseText object from createXMLHttpRequest doesn’t parse Javascript.
Since there really isn’t any good way to get window resolution from PHP, I hacked around it a bit. See, I have one adsense.php that serves up all the ads. I just do a global $adtheme; ‘checkres’ is a special case that includes some Javascript to detect the window’s internal area.
It basically works like this.
if (window.innerWidth >= 980)
{
google_ad_width = '728';
google_ad_height = '90';
google_ad_format = '728x90_as';
}
else
{
google_ad_width = '468';
google_ad_height = '60';
google_ad_format = '468x60_as';
}
And then the rest of the Google adsense variables.
