Forum Moderators: DixonJones

Message Too Old, No Replies

url tracking

will javascript track passed variables in a url

         

evvo

11:42 am on Apr 18, 2002 (gmt 0)



Using javascript is it possible to track a piece of info as per this scenario?

The aim is to track a campaign code from a link in an email thru to a submitted form.

An email to customers will contain 4 links (promotions) - each related to a different campaign code - that will take a customer to a page related to that promotion. I need to find a way of storing the campaign code related to each link (perhaps a cookie?) so am wondering if i can include each campaign code within the URL link as a querystring? Can a cookie read data from a URL querystring and store it?

Then when a customer accesses one of our forms this campaign code will pre-populate the form's ref number field so that we can track the success of each promotion.

NovaW

8:01 pm on Apr 19, 2002 (gmt 0)

10+ Year Member



Yes - it is kind of possible to do that, but it would be much easier to do it with server side code & store it in a db. ASP would make that easy. If you read the URL in Javascript & store the value in a cookie - it will be stored on the users machine - which, if I understand you correctly would then be read back later to use as a ID to populate a form

To read a url and store the value in a cookie on the users machine - you could use this code. It assumes the query is something like ?id=5. It will pass id=5 into a cookie for 30 days.

<script language="JavaScript">
var url = '' + this.location;
url = url.substring((url.indexOf('?')) + 1);
var test = url.substring(0,url.indexOf('='));
var vall = url.substring((url.indexOf('=')) + 1);
if (test == 'id') {
var today = new Date();
var expiry = new Date(today.getTime() + 2592000000);
document.cookie="id=" + vall + "; expires=" + expiry.toGMTString();
}
</script>

There is better ways to do what you are trying to do - using server side code & a db.

Hope the above helps.