Forum Moderators: DixonJones
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.
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.