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

Recommended Answers

All 6 Replies

Hi,

Where is the part where google_ad_request_done(google_ads); is called?

Hi,

Where is the part where google_ad_request_done(google_ads); is called?

function google_ad_request_done(google_ads) {

Then it starts Logic If Statements.

What I mean is, where is the function, "google_ad_request_done", being called.

The reason I ask is that it will show the parameter "google_ads".

From the function code, you can tell that google_ads will most likely be an Array, containing Objects with properties: url, visible_url, line1 etc.

But unless we see that part of the code, it cannot be debugged...

Is this code from google adsense by the way? or did someone write it to show multiple google adsense ads?

Looks very interesting...

PM me your email address and I will send you the Zip file with all that information.

Hi please let me know where the function "google_ad_request_done" is called.
My email is [removed]

Thanks

thas is my address email i want you to send me the Zip and all information. of that plz [removed]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.