I am desperately trying to figure out HOW to add tracking code to my rotating banner.
I have random "onload", rotating banner ads on my website. The script works like a charm and will randomly load a banner ad when you go to the site and will continue rotating the bannners while you are surfing the site. The code below is in a separate .js file and there is a <div> tag within the html code of each page that tells the banners where to display.
My problem is, when I add Google tracking code to my banner script, the banners disappear completely.
This is the Google tracking code:
onClick="javascript: _gaq.push(['_trackPageview', '/bannerad/leighfibers']);"
(I have tried rearranging the code in various ways, with no success).
Here is the banner ad script (as you can see the google tracking code is already in place, but does not work. The only time I can get the banners to work with the tracking code in place is if I change the single quotes to double quotes in this part of the code: '_trackPageview', '/bannerad/leighfibers', but when I do that then the onclick event does not work which means the tracking code does not work).
// JavaScript Document
var adtimer;
var adcounter;
var textads = new Array();
textads[0]='<a href="http://www.leighfibers.com" target="_blank" onClick="javascript: _gaq.push(['_trackPageview', '/bannerad/leighfibers']);" ><img src="http://www.sleepproducts.org/ISPANEW/images/bannerads/August_LeighFibers.jpg" border="0"></a>';
textads[1]='<a href="http://www.henkelna.com/foambonding2" target="_blank" onClick="javascript: _gaq.push(['_trackPageview', '/bannerad/henkel']);" ><img src="http://www.sleepproducts.org/ISPANEW/images/bannerads/July_Henkel.jpg" border="0"></a>';
textads[2]='<a href="http://www.storksmt.com/Stork/6212/Bedding_Evaluation.html" target="_blank" onClick="javascript: _gaq.push(['_trackPageview', '/bannerad/stork']);" ><img src=\"http://www.sleepproducts.org/ISPANEW/images/bannerads/August_Stork.gif" border="0"></a>';
var adcounter=Math.floor(Math.random()*(textads.length));
function changeRandomTextAd(){
var oldAD = document.getElementById('randomtextadsdiv').innerHTML;
var newAD = textads[adcounter];
document.getElementById('randomtextadsdiv').innerHTML = newAD;
if (adcounter < ((textads.length)-1))
{
adcounter++;
}
else
{
adcounter=0;
}
adtimer=setTimeout("changeRandomTextAd()",6000);
}
PLEASE, PLEASE HELP!!!
BTW: I am also open to using a different banner ad script as long as it does the same thing as the one I have now.
Many thanks to anyone who is willing to help me!!