Forum Moderators: DixonJones
I am using a combination of SSI & PHP pages on my site.
Although I know that it would be best to have the entire site in one language, I have just bought a database module for my year and a half old site and dont want to lose the pagerank on my existing pages.
The PHP database implements referral tracking using a cookie with the value of referral_id=xx and stores the value for 90 days. This works fine.
I would like to offer my affiliates the option of being able to refer visitors to any page of my site (particularly the home page or product info page which is a .SHTML extension) and allow them to benefit from the commission.
Does anyone have any clues about how I can do this?
I dont have any javascript or cgi coding experience but I am quick to pick things up and have The O'Reilly JavaScript Definitive Guide. I am over my head though and need a quick solution to this, perhaps there is a commercial product someone could recommend to write these values to this cookie.
TIA
Paul
I worked this out myself, there is probably a neater way of doing this but the code works for me.
Here is the JavaScript
<script Language="JavaScript">
function QueryString(key)
{
var value = null;
for (var i=0;i<QueryString.keys.length;i++)
{
if (QueryString.keys[i]==key)
{
value = QueryString.values[i];
break;
}
}
return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString_Parse()
{
var query = window.location.search.substring(1);
var pairs = query.split("&");
for (var i=0;i<pairs.length;i++)
{
var pos = pairs[i].indexOf('=');
if (pos >= 0)
{
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}
}
QueryString_Parse();
var expDays = 90;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
document.cookie = "referrer_cookie=" + escape(QueryString("referrer_id")) + "; expires=" + exp.toGMTString() + "; path=/" + "; domain=.DOMAIN.COM";
</script>
Thanks for all of your replies! :)
Paul
Here is the code I used to track the referrals.
The PHP code required the value in the cooke to be 'referrer_cookie=xx' and the url used was 'www.mydomain.com/referrer_id=xx'
There are two configurable options, MYDOMAIN.COM & expDays = xx
if (document.cookie && document.cookie.indexOf("referrer_cookie=") > -1)
{
var refer = document.cookie;
}
else
{
function QueryString(key)
{
var value = ("");
for (var i=0;i<QueryString.keys.length;i++)
{
if (QueryString.keys[i]==key)
{
value = QueryString.values[i];
break;
}
}
return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString_Parse()
{
var query = window.location.search.substring(1);
var pairs = query.split("&");
for (var i=0;i<pairs.length;i++)
{
var pos = pairs[i].indexOf('=');
if (pos >= 0)
{
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}
}
QueryString_Parse();
var expDays = 90;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
document.cookie = "referrer_cookie=" + escape(QueryString("referrer_id")) + "; expires=" + exp.toGMTString() + "; path=/" + "; domain=.MYDOMAIN.COM";
}
[edited by: vrtlw at 8:29 pm (utc) on Nov. 27, 2003]