How Can I Determine Where a User Has Come From?

May 15, 2025 5 answers
Asked by ~4 clouds sketched
Hey everyone! I've been trying to figure out how to find out the website a user visited before arriving at mine. I came across a discussion on this topic where someone mentioned using the "Referer" parameter. However, when I tried testing it in the console after clicking a link, it returned an empty string. According to the documentation, it shouldn't be empty, so I'm a bit confused. Does anyone have insights on how this actually works?

Answers

fair play
Boooo! Sounds complicated!
Reply to this answer
inlet.valve
Checking the Referer header is a good start, but keep in mind that it's not very reliable since browsers block it in certain situations for security reasons. This is usually a good measure to protect user privacy.
Reply to this answer
may.contain.plums
You're looking for the referer website or page, and that's standard in analytics tools. Google Analytics and others show this info too. But just remember, you can pull it directly from the request header without using any analytics, but it is optional, so not all sites will provide it.
Reply to this answer
19minPitStop
To track where users are coming from, you want to look at the "Referer" header. Check out the MDN documentation for more details here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Referer

stoneware.mug.: Oh, just a heads up! The misspelling of "referer" is actually part of the web specs from a long time ago. Makes for some confusion for newcomers!

Reply to this answer
pocketful_of_rye
When you say you 'entered this link', did you just change the URL directly in your browser? If so, the referrer will be blank since that action doesn't carry over a referer. The header is only sent when a link on another site is clicked to navigate to yours. Also, external sites can block the referrer via the referrer policy, so it can be hit or miss.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions