cookie help required please (javascript newbie)

They have: 3 posts

Joined: May 2002

Goal : To write a cookie which stores the referring website and then writes this referrer into an order form if the visitor orders a service.

Reason : To improve advertising effectivenss.

Ok guys, this is what I have got so far. It's my first attempt at a cookie, let alone javascript. This will write the referrer to the page (next step is to get that into a form)... but now I can't :

1. Get the cookie to check if it already exists and not write anything if it does (so it only ever writes the first time someone visits).

2. Get another page to read the cookie.

<script language="javascript">
cookie_name="mylittlecookie";
var exp = new Date()
var oneYearFromNow = exp.getTime() + (365 * 24 * 60 * 60 * 1000)
exp.setTime(oneYearFromNow)
var qasdf = document.referrer
document.cookie = "referred by " + escape( document.referrer ) + "; expires=" + exp.toGMTString();
document.write (qasdf);
</script>

Could anyone assist me with this please?

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

I'm not that good in cookies, but this link always helps me out:
http://www.htmlgoodies.com/beyond/cookie.html

Hope it helps,

They have: 3 posts

Joined: May 2002

Thanks Jack.

These pages seem to be good at the very beginning parts, but I get stuck once I am beyond those extreme basics.

I even bought the Javascript Bible but the cookie section isn't really very helpful.

gavin681's picture

They have: 184 posts

Joined: May 2001

You want to write an affiliate program script hey? My brother is working on an asp one at his website: http://www.aspbahamas.com

It uses cookies and places the referring id into the contact form message. We will be using this script for our real estate website http://www.knowlesrealty.com

Check it out he might be able to help you.

They have: 3 posts

Joined: May 2002

Hi Gavin,

Although it's much the same idea, it's not really an affiliate script I'm after. I just want to see which keywords are producing paying visitors rather than fly by nights so I can target the best keywords for my site.

gavin681's picture

They have: 184 posts

Joined: May 2001

Interesting. I have always used "Live Stats" from Media House. It comes free with my hosting. The best tracking software out there. As soon my link is posted I can see in real time who at my website where they are from who referred them and much more.

I couldn't promote without it. I would waste money advertising in the wrong places.

It also lets you know which keywords were used to find your site and from which search engine.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.