So using javascript, I'd like to know if there's a way to find out where a user is coming from, save it to a variable and use that address later. 

For example: I give an ad banner to various websites, and when a user clicks on the banner, they come to my online store, and if they buy anything, I want to know which website they came from, and how much they spent shopping on my website.

Is there a way to do that with javascript?

Is there a way to use a cookie to store the inbound url, and then after someone buys something, just email that someone coming from "websiteHere.com" bought something on your website? and then the cookie gets deleted, or is that bad practice?