How can I determine if the document.referrer is from my own site?

David Thielen picture David Thielen · Dec 6, 2010 · Viewed 17.5k times · Source

Each time a page is requested I get the referrer of the page it came from. I need to track just referrer from other sites, I don't want to track going from one page to another within my site. How can I do that?

Answer

Eli Grey picture Eli Grey · Dec 6, 2010
document.referrer.indexOf(location.protocol + "//" + location.host) === 0;