Hello

I am trying to install some javascript advertising banner tags into my drupal site. I have copied/ pasted the ad calls into blocks, and used the drupal_add_js function in template.php to reference the javascript file.

My site is a fairly straightforward Drupal installation based on Zen theme, using nice menus module for drop down navigation. There are very few other non-core modules being used by the site. The site also runs a google adsense text ad (with the javascript call pasted into a block).

However, the new advertising banner code seems to be doing strange, and unpredictable things to my site. Most of the time (perhaps 90% of the time) everything loads correctly (albeit in a slow and shakey way, sometimes).

However, sometimes there are problems. The most usual problem is that the nice menus drop down navigation bar does not appear (so the nav bar is blank), and the Google adsense ad does not appear. Sometimes the two new banner ads do not appear, while the nav bar/ google ad do. Or sometimes some other combination of these things not working. (Very occasionally other parts of the page do not load or CSS does not load - although this may be an unrelated issue). Problems occur in both IE and firefox (although not neccessarily the same ones), and they seem to occur randomly - not on specific pages or in response to specific actions.

Force refreshing the page often causes all the elements to load properly, but not always. And, the html source code for the page appears to be the same (at least for the times I have checked it), whether or not the ads/ navigation bar appear. So the problem may be that the browsers are rendering the same code inconsistently.

For some reason if I change the order of the ads, so the banner ad code is not placed at the bottom of the page, or the google adsense code is placed below the banner ads, this seems to improve the performance.

I know this advertising code is widely used on many other (non-drupal) sites, including those simultaneously running adsense ads, without problems.

Would be fantastically grateful for any help in understanding this frustrating problem - what's happening, and how I fix it, so this code does not conflict with Drupal.

I'm not a programmer so would appreciate a simple answer if possible.

I can give $150 to anyone who can fully solve this for me and help me get it working without any issues.

I'm pasting below the ad call code for the 2 banner ads.

<script language="JavaScript" type="text/javascript">
<!--
wbds_writeTag('300X250','MIDDLE');
//-->
</script>



<script language="JavaScript" type="text/javascript">
<!--
wbds_target = 'http://adserver.webads.co.uk/jserver/SITE=VCDIRECTORY.NET/AREA=VCDIRECTORY.NET_HOME';

wbds_writeTag('728X90','TOP');
//-->
</script>
<script>
<!--
wbds_firstdone=true;
//-->
</script>

And the javascript code this is referencing.

wbds_waitserver=4000;
wbds_pageid=-1;

function wbds_testserver() {
	if (wbds_waitserver>0 && !wbds_firstdone) {
		wbds_waitserver-=200;
		setTimeout('wbds_testserver()',200);
	} else if (!wbds_firstdone) {
		wbds_serverup=false;
		if (document.all) {
			var ua=navigator.userAgent;
			if (parseFloat(ua.slice(ua.indexOf('MSIE')+5))>=5) document.scripts['wbds_tag0'].src='//'; 
		}
	}
}

function wbds_writeTag(wbds_size, wbds_position) {
	var rnd=Math.round(Math.random()*100000000);
	if (wbds_pageid<0) wbds_pageid=Math.round(Math.random()*100000000);
	if (wbds_serverup) {
		document.write('<scr'+'ipt language="javascript" id="wbds_tag'+wbds_counttags+'" src="');
		document.write(wbds_target+'/ADSIZE='+wbds_size+'/AAMSZ='+wbds_size+'/POSITION='+wbds_position+'/PAGEID='+wbds_pageid+'/ACC_RANDOM='+rnd+'"></scr'+'ipt>');
		if (wbds_counttags++==0) setTimeout('wbds_testserver()',200);
	}
}

Thanks for any help!

Comments

adetoyan’s picture

what modules are you using to embed the ads? Are you using the adsense and ad modules or the code is embedded directly in your template?

danieldd’s picture

Hi, I am not using any modules for this. The calls are copied/ pasted directly into the blocks where they appear. The javascript code itself is stored in my theme directory and referenced in the template.php file.

pecker’s picture

Hi Daniel,

How are you referencing the javascript from the template.php file?

You could try to add a simple code that only gets called when key stages of the process complete, something like an echo or a comment.

i.e after the javascript has been called, and before and after (but from within) the calls in the block.

This way you could check your source code when it goes kooky and see if all your tags are present. If something isn't there, you might get more of an idea where to start looking.

adetoyan’s picture

I'd advise you try the adsense module for the google ads. As for the rest of the javascript, it seems there's either a conflict between scripts or in the order in which they are executed. Try copying the code into the script.js file for your theme somewhere at the bottom; that way the code runs after the rest of your page has been loaded. I'm not too sure but basically if you can get the advertising banners to load after your theme then it shouldn't mess with your layout.
Is there any way I can view the page?

Gary Feldman’s picture

The wbds_target is only being defined for the second of the two script blocks you posted. I also don't see wbds_serverup getting set anywhere. Presumably that's happening in pieces of code you omitted, but that makes it difficult to diagnose the details.

The nondeterministic symptoms you're describing are typical of the problem of executing JavaScript code either before the page is fully built or before all the required JavaScript files have been loaded. This problem has been the bane of JavaScript library users everywhere. If the problem isn't obvious from reviewing the entire file, I'd start by replacing the explicit script in the blocks with empty, identified divs and use Drupal JavaScript behaviors to replace them. This also means changing the document.write calls to use jQuery to find the divs to replace.

danieldd’s picture

Thanks everyone for the advice.

Unfortunately we were never able to solve this problem, although it may have been something to do with the code executing at the wrong time, as Gary Feldman says above.

However, we found that the problems dramatically reduced when the site was moved to a fast, production server. For the remaining issues, as a workaround we put the ads into iframes, to isolate the javascript from the rest of Drupal's code. This seems to be working fine.

If we ever solve this problem completely, I will post the solution here. Thanks again.