Hey everyone, I'm curious about how to find out which website a user came from before landing on mine. I stumbled upon this Stack Overflow question that mentions using the 'referrer' parameter, and I checked the MDN docs on it. However, when I tried it in the console after clicking the link, it returned an empty string, even though the documentation says it shouldn't. Can anyone shed some light on this? Does it actually work?
5 Answers
When you say you 'entered this link,' do you mean you just typed it in? If so, the referrer will be blank since no site referred you. The referrer header usually only gets passed when clicking a link from another site. Plus, some external sites can block it using referrer policies. Check it out here: https://developer.mozilla.org/en-US/docs/Web/Security/Referer_header:_privacy_and_security_concerns
You should check the 'Referer' header! This is what passes along the info about where users came from. Here’s the link to the MDN docs for more details: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Referer
Booooo! 😂 Just kidding, the referrer can be tricky business!
It's good to know you can pull the Referer header directly, but keep in mind that it's not very reliable. Browsers often block this for security reasons—which is actually a positive thing! Just something to consider when planning your approach.
Yep, it’s called the referrer website or page. Most analytics tools track this info, but it's built into the request headers, so you don't need third-party tools to access it. Just keep in mind that it's optional; not all sites will provide it.
Just a heads up, the misspelling of 'referer' is actually how it was specified in the old standards. It might confuse non-developers.