Forum Moderators: DixonJones

Message Too Old, No Replies

Tracking refferals

I need to write a value from the query section to a cookie.

         

vrtlw

2:11 am on Nov 21, 2003 (gmt 0)

10+ Year Member



Hi everyone,

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

vrtlw

4:11 am on Nov 21, 2003 (gmt 0)

10+ Year Member



Hi All,

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

vrtlw

5:20 am on Nov 21, 2003 (gmt 0)

10+ Year Member



OK,

This script doesnt quite work.

When returning to the page it actually re-write to the cookie the value Null.

Any help is appreciated.

Paul

vrtlw

11:30 pm on Nov 21, 2003 (gmt 0)

10+ Year Member



No worries now, I worked it out

vrtlw

8:21 pm on Nov 27, 2003 (gmt 0)

10+ Year Member



Wahey, this works!

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]

jatar_k

8:27 pm on Nov 27, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I store the data about users in either sessions or cookies, both with php only. It looks like a good solution.

Glad to see you worked this out. I also thought you might be tired of talking to yourself. ;)

vrtlw

8:32 pm on Nov 27, 2003 (gmt 0)

10+ Year Member




I also thought you might be tired of talking to yourself.

I thought this thread was like a desert island!

Thanks Jatar_K :)