0

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!!

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by dlnicholas1
1

Although I do not have any experience with Rotating ad banners, I do see the cause of your problem:

>> Line 6, 7, 8 - It is a mix of various quotes and they are aligned wrong. Use the following:

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>";

~G

Edited by Graphix: n/a

0

what graphics said, in the code of your OP, you can see the color changes in the text, perchance consider a code highlighting editor, notepad++ notepad2 or similar that offer code hints when some goes wrong

0

Graphix, YOU ROCK!!! The code changes you suggested worked like a charm and I can now see the banner ads rotating on the site. I am still not sure if the tracking code is working as it takes 24 hours to register, but I am a huge step ahead than I was yesterday thanks to you!! Many, many thanks!!

---------------------------------------------------------------------------------

Although I do not have any experience with Rotating ad banners, I do see the cause of your problem:

>> Line 6, 7, 8 - It is a mix of various quotes and they are aligned wrong. Use the following:

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>";

~G

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.