Search code examples
webdetection

Detecting where user has come from a specific website


I'm wanting to know if it's possible to detect which website a user has come from and serve to them different content based on which website they have just come from.

So if they've come from any other website on the internet and landed on my page, they will see my normal html and css page, but if they come from a specific website (this specific website would have also been developed by me so I have control over the code server-side and client-side) then I want them to see something slightly different.

It's a very small difference that I want them to see, and that's why I don't want to consider taking them to a different version of the website or a different page.

I'm also not sure if this solution will be placed on the page they coming from or the page that they arriving on?

Hope that's clear. Thanks!


Solution

  • I would add a URL parameter like http://example.com?source=othersite. This way you can easily adjust the parameter and can use javascript to detect this and slightly alter your landing page.

    Otherwise, you can use the HTTP referrer sent via the browser to detect where they came from, but you would need to tell us your back end technology to get an example of that, as it differs a bit.

    In javascript, you can do something as easy as

    if(window.location.href.indexOf('source=othersite') > 0)
    {
      // alter DOM here
    }
    

    Or you can use a URL Parameter parser as suggested here: How to get the value from the GET parameters?