...

View Full Version : replacing part of a string in a variable



hedbanger
07-01-2004, 12:05 AM
i have sites that use webtrendslive remotely-hosted traffic reporting.
a couple of the sites are now using .jsp and the complete url isn't being reported because of the "?" in the url string. i want to make it so that the variable that reports the url replaces the "?" with "-" so that the whole url will be sent and the page title will get reported.
that variable is:

var wtl_URL= document.URL;

i think it should be something like this, but i'm not sure.

var wtl_URL= document.URL;
document.URL.replace(\?,"-");

thanks.

Willy Duitt
07-01-2004, 03:46 AM
The regular expression to replace all instances of ? with - is: replace(/\?/g,'-')

hedbanger
07-01-2004, 04:38 AM
willy,
thanks. there is only one "?" in the url, but i could use what you supplied except i'm unclear on the extra slash in front of the escaped "?".
replace(/\?/g,'-')

other questions:
1. do i have the two lines in the correct order or should they be reversed?
2. do i need to declare a new variable? (i need to preserve the variable "wtl_URL".

hedbanger
07-01-2004, 08:03 PM
how's this? what am i leaving out?
i've been looking here and elsewhere for pointers but am still having trouble.
var wtl_URL= document.URL;
var new= wtl_URL.replace((/\?/g,'-')
var wtl_Title= document.title;

please help me out!
thanks,
joan

Willy Duitt
07-01-2004, 08:30 PM
I do not understand what you are doing.
For instance, how are you using new after you replace (?) with (-)???

You will need to provide more information.
Such as all of the relevant code so someone can make an informed assessment.....

.....Willy

hedbanger
07-01-2004, 09:04 PM
i'm sorry! here is the original script:

var wtl_URL= document.URL;
var wtl_Title= document.title;

i was basing my changes on this model:

var old=window.document.URL
var new=old.replace(\?,'-')

webtrendslive is remotely hosted and the pages that have the script in them report back traffic and browser info. then the info is available on their website.
the .jsp content is dynamically placed inside of one of 6 container pages.
the url before the "?" corresponds to those container pages such as "ProductLine." in

http://www.anolon.com/anolon/ProductLine.jsp?channelid=a808a74c94196f00vcm1000000001f00000a____
link to actual page (http://www.anolon.com/anolon/ProductLine.jsp?channelid=a808a74c94196f00vcm1000000001f00000a____)
when the full url loads, including the string after the "?", the correct page title is displayed, which in this case is "advanced clad".
(the way it's set up, "productline" is a "channel" and the productlines below it are "subchannels".)

when a page is hit, the url is sent to webtrendslive. once a page has been reported, it always reports the same page title. and since it's detecting only the url up to the "?", it's reporting "ProductLine" instead of the dozen different product lines that are subchannels.
so, if i can get the full string to report to webtrendslive, then it should detect and report the correct page title.

so what i need to do is to replace the "?" so the url won't get truncated, but preserve the original variable name "wtl_URL" so remote script will still work.
i hope this makes things clearer.
thanks in advance for your help.
joan

Willy Duitt
07-01-2004, 09:31 PM
when a page is hit, the url is sent to webtrendslive. once a page has been reported, it always reports the same page title. and since it's detecting only the url up to the "?", it's reporting "ProductLine" instead of the dozen different product lines that are subchannels.
so, if i can get the full string to report to webtrendslive, then it should detect and report the correct page title.

so what i need to do is to replace the "?" so the url won't get truncated, but preserve the original variable name "wtl_URL" so remote script will still work.
i hope this makes things clearer.
thanks in advance for your help.
joan

Your link provided us with what we needed to see.
(the webtrends script)


<script language="JavaScript" type="text/JavaScript">
<!--
<!-- START OF WEBTRENDS LIVE TAG -->
<!-- Copyright 2003 NetIQ Corporation -->
<!-- For privacy concerns, check our Privacy Policy at http://www.webtrendslive.com/wtl_system/privacy_policy.htm -->
<!--
// Modification of this code is not allowed and will permanently disable your account!
// SiteName: Anolon
function wtl_Tag5_37748()
{
var SERVER= "";
var CONTENTGROUP= "";
var wtl_Title= document.title;
var wtl_URL= document.URL;
var wtl_URL= wtl_URL.replace(\?,'-');



function D8( d)
{
var fwd=0, seed= new Date('01/01/2000'), key= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var s= key.charAt( d.getFullYear()-2000)+key.charAt( d.getMonth()+1)+key.charAt( d.getDate());
s+= key.charAt( d.getHours())+key.charAt( d.getMinutes())+key.charAt( d.getSeconds());
while( seed.getDay()!=fwd) seed= new Date(seed.getTime() + 86400000);
var w= Math.floor( (d.getTime()-(seed.getTime()+86400000)) / 604800000 );
s+= key.charAt( (w-(w%16))/16 );
s+= key.charAt( w%16);
return s;
}

function A( B, C)
{
W+="&"+B+"="+escape(C);
}

var t = new Date();
var W="http"+(document.URL.indexOf('https:')==0?'s':'')+"://statse.webtrendslive.com/S009-00-11-22-206521-37748/button5.asp?tagver=5&si=37748&fw=0";
A( "server", typeof(SERVER)== "string" ? SERVER : "");
A( "Group", typeof(CONTENTGROUP)== "string" ? CONTENTGROUP : "");
A( "tz", t.getTimezoneOffset());
A( "ch", t.getHours());
A( "cl", D8(t));
A( "ti", typeof(wtl_Title)== "string" ? wtl_Title : document.title);
A( "url", typeof(wtl_URL)== "string" ? wtl_URL : document.URL);
A( "rf", window.document.referrer);
A( "js", "Yes");
A( "ul", navigator.appName=="Netscape" ? navigator.language : navigator.userLanguage);
if(typeof(screen)=="object")
{
A( "sr", screen.width+"x"+screen.height);
A( "cd", screen.colorDepth);
A( "jo", navigator.javaEnabled()?"Yes":"No");
}
if( W.length>2048 && navigator.userAgent.indexOf('MSIE')>=0)
W= W.substring( 0, 2043)+"&tu=1";

document.write('<IMG ID="WTL_37748" BORDER="0" WIDTH="1" HEIGHT="1" SRC="'+W+'">');
}

wtl_Tag5_37748();
//-->
<!-- END OF WEBTRENDS LIVE TAG -->
//-->
</script>

No, wtl_URL has nothing to do with reporting the document title. Webtrends script is sending the document.title from the variable wtl_Title. If you wish to find the subchannel which includes everything after the querry (?) you will need to strip that from webtrends report and I can not offer any solutions to that since I havent seen the report.

All that aside, what you are trying to do is against Webtrends TOS and is clearly stated within the comments of the script that any modifications to the script will terminate your account. Therefore, noone here will help you (for whatever reasons) modify the codes which you agreed not too when you opened your account with Webtrends.

Perhaps if you can post a brief copy of the report indicating how wtl_URL is reported, someone could help you strip out the necassary info in order to figure out which subchannel has been called, how many times.

.....Willy

Willy Duitt
07-01-2004, 09:38 PM
FWIW: Why don't you try this (http://www.whatcounter.com/) free stat counter. I believe it will properly report pages loaded into php or jsp index pages......

hedbanger
07-01-2004, 09:49 PM
willy,
yes, '
i'm aware of the TOS issue. but that's to cover when alterations to the code cause a severe problem, and this won't. (i was told that the only problem in this case would be if the query strings were over 300 characters long -- and they aren't.)

you are correct and i know also, that the variable wtl_URL doesn't convey the title, but it can't get the correct title unless the FULL url with the query for the subchannel is conveyed.

anyway, thanks for your input. i will keep working on this.
joan

hedbanger
07-01-2004, 09:58 PM
FWIW: Why don't you try this free stat counter. I believe it will properly report pages loaded into php or jsp index pages......

thanks. i'll check that one out for other uses.

it's what WTL does with the stats that's important! the WTL reports are very comprehensive -- about 95 pages long. they're the darling of the marketing department.

but there are other log processing apps that i'll be looking into. the sites use websphere and vignette, both of which probably have apps and they may already be part of the license.
j

hedbanger
07-01-2004, 11:28 PM
thanks to you, willy and the netscape 7.1 java console, it looks like it is working.

var wtl_URL= document.URL;
var wtl_URL= wtl_URL.replace(/\?/g,'-');
var wtl_Title= document.title;
:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum