Yes and no.
Some clients send a header called referer
(Yes its a misspelling). You can access the header through document.referer
in javascript or request.referer
in Rails.
However you cannot rely on the presence of the header as many clients do not send it. For a very good reason as it can be used to track users - often without their knowledge or consent.
The referer
header can also be spoofed so using it in any kind of authentication scheme is not a good idea.
Another approach is by attaching a query parameter to links with a tracking code. This requires you to be in control of the incoming links.