Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pecifying path to root for Cookie tracking

Status
Not open for further replies.

joelBoucher

Programmer
Feb 19, 2007
1
US
I have landing pages on my site located two folders down in the site structure (../../file.html) from the root folder. If vistors click to a page link that is located on my root folder, the tracked cookie is reset to a default value.

I have the new code in my Javascript and have tried to set paths to allow transfer of the cookie to the root however still wont work. thoughts? I used to have this code on a site that was all located on the root, but now with a different folder structure it wont track. I really need to get this fixed or Im dead.

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ronnie T. Moore -->
<!-- Web Site: The JavaScript Source -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! -->

<!-- Begin
function readID() {
var expDays = 1; // 1 day
var expDate = new Date();
expDate.setTime(expDate.getTime() + (24 * 60 * 60 * 1000 * expDays));
var id = GetCookie('id');
if (id == null || id == "Thank You") {
if (location.search.length > 1) id = location.search.substring(1, location.search.length);
else id = "Thank You";
if (id != GetCookie('id')) SetCookie('id', id, expDate);
}

// You can change the FORM location below
// where the referral ID is stored on your page
// You then access this element to get the ID
document.Monthly.Referral.value = id;
document.OneTime.Referral.value = id;



}
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function setCookie(name,value,expires, options) {
if (options==undefined) { options = {}; }
if ( expires ) {
var expires_date = new Date();
expires_date.setDate(expires_date.getDate() + expires)
}
document.cookie = name+'='+escape( value ) +
( ( expires ) ? ';expires='+expires_date.toGMTString() : '../../' ) +
( ( options.path ) ? ';path=' + options.path : '../../' ) +
( ( options.domain ) ? ';domain=' + options.domain : ' ) +
( ( options.secure ) ? ';secure' : 'true' );
}

setCookie('name', 'value', 1, {'path':'../../'});
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top