One of my affiliates is having a problem with his Google Adsense and JavaScript.
It works about 2/3's of the time. But on other occasions it gives an undefined error or only one ad shown.
The original code is as follows:
function google_ad_request_done(google_ads) {
if (google_ads.length > 0) {
var first_ad_unit = '', second_ad_unit = '';
for(var i = 0; i < google_ads.length; ++i) {
if (i < 4) {
if (i == 0) first_ad_unit += 'First Ad Unit:<br><table width="100%"><tr>';
first_ad_unit += '<td valign="top" nowrap><b>AD #: ' + (i+1) + '</b><br><a href="' + google_ads[i].url + '"><b>' + google_ads[i].line1 + '</b></a><br>' + google_ads[i].line2 + '<br>' + google_ads[i].line3 + '<br><font color="#008000">' + google_ads[i].visible_url + '</font></td>';
if (i == 3) first_ad_unit += '</tr></table>';
} else {
if (i == 4) second_ad_unit += 'Second Ad Unit:<br>';
second_ad_unit += '<p><b>AD #: ' + (i+1) + '</b><br><a href="' + google_ads[i].url + '"><b>' + google_ads[i].line1 + '</b></a><br>' + google_ads[i].line2 + '<br>' + google_ads[i].line3 + '<br><font color="#008000">' + google_ads[i].visible_url + '</font></p>';
}
}
}
document.getElementById("first_ad_unit").innerHTML += first_ad_unit;
document.getElementById("second_ad_unit").innerHTML += second_ad_unit;
}
google_ad_client = 'YOUR_CLIENT_ID';
google_ad_output = 'js';
google_max_num_ads = '8';
google_adtest = 'on';
google_safe = 'high';
google_feedback = "on";
google_ad_type = "text_image";
Newly Configured Code:
function google_ad_request_done(google_ads) {
if (google_ads.length > 0) {
var first_ad_unit = '', second_ad_unit = '', third_ad_unit = '';
for(var i = 0; i < google_ads.length; ++i) {
if (i < 3) {
if (i == 0) first_ad_unit += '<table width="710"><tr>';
first_ad_unit += '<td width="33%" valign="top" nowrap><a class="adsense" href="' + google_ads[i].url + '" onMouseover="window.status=\'http://' + google_ads[i].visible_url + '\'; return true"><b>' + google_ads[i].line1 + '</b></a><br><a class="adsensedesc" href="' + google_ads[i].url + '" onMouseover="window.status=\'http://' + google_ads[i].visible_url + '\'; return true">' + google_ads[i].line2 + '</a><br><a class="adsensedesc" href="' + google_ads[i].url + '" onMouseover="window.status=\'http://' + google_ads[i].visible_url + '\'; return true">' + google_ads[i].line3 + '</a><br></td>';
if (i == 2) first_ad_unit += '</tr></table><table width="710"><div align="right"><a class="adsensedesc" href="' + google_info.feedback_url + '">Ads by Google</a></div></table>';
} else {
second_ad_unit += '<a class="adsense" href="' + google_ads[i].url + '" onMouseover="window.status=\'http://' + google_ads[i].visible_url + '\'; return true"><b>' + google_ads[i].line1 + '</b></a><br><a class="adsensedesc" href="' + google_ads[i].url + '" onMouseover="window.status=\'http://' + google_ads[i].visible_url + '\'; return true">' + google_ads[i].line2 + ' ' + google_ads[i].line3 + '</a><br><br>';
if (i == 3) third_ad_unit += '<div align="right"><a class="adsensedesc" href="' + google_info.feedback_url + '">Ads by Google</a></div>';
}
}
}
document.getElementById("first_ad_unit").innerHTML += first_ad_unit;
document.getElementById("second_ad_unit").innerHTML += second_ad_unit;
document.getElementById("third_ad_unit").innerHTML += third_ad_unit;
}
google_ad_client = 'removed for privacy';
google_ad_output = 'js';
google_max_num_ads = '24';
google_safe = 'high';
google_feedback = "on";
google_ad_type = "text_image";
google_ad_channel ="removed for privacy";
Any Help at all is welcome. Like I said before it works about 2/3's of the time. But there must be some reason it comes up with errors the other times.
Thanks,
Lightninghawk