Sunday, April 17, 2011

Capture who clicked a link from Website A to Website B?

Assume I have a website called Website A and it has some links on it to other websites. One of these links could be a link to Website B. Is there a way, using some existing solution, open source, or something you have to pay for where you can track who, what, where, etc clicked the link to go from Website A to Website B?

Website B could be Stackoverflow and my website is www.websiteA.com, so on my website, I have a link to www.stackoverflow.com. If a user clicks on www.stackoverflow.com from my page, I want to capture information, such as name, phone, etc (not sure if I can do this unless the user is actually logged into my website). In this case, this is a public page which anyone from anywhere can access. If I can't do it from my website, is there a way I can tell stackoverflow that this particular person clicked on my link to get to your website and I need their information.

From stackoverflow
  • Try using HTTP_REFERER

    Chad Birch : Would only work if he also controls Website B, which he didn't specify.
    Xaisoft : I have no control over Website B, for example, imagine Website B is stackoverflow and I have a link to stackoverflow. If someone clicked a link on my site to get to stackoverflow, could I get their information.
    Gero : I see. So you can consider using the methods explained in other answers =)
  • You could always check the referer, but this can be spoofed.

    Request.UrlReferrer.ToString
    

    Other than that, you could append an additional query parameter on the links from Website A so you know where they came from:

    <a href="www.websiteb.com?from=websitea">
    
  • The method most sites use for this is to have a script on your site handle the redirect. So instead of the link being directly to:

    http://websiteB.com

    the link goes to something like:

    http://websiteA.com/link/websiteB.com

    The "link" script logs the request and then forwards them to the address (this should be done instantly, don't give them a "forwarding you to Website B in 3 seconds!" page).

    Note that as a visitor to your site, I much prefer a method where the link's destination is apparent when I hover over the link, as opposed to the method that some sites use where all you see is an id. What I mean is, instead of the link being something like:

    http://websiteA.com/link/websiteB.com

    they instead have a link like:

    http://websiteA.com/link/483

    Showing the destination can be achieved in a few ways. One way is something like I described above, where the destination is part of the query string. Alternatively, you can use some Javascript for this. The status bar's value can be changed with Javascript by setting the window.status variable, but many browsers prevent this by default (Firefox, for example).

    Google has found a sneaky way around this problem by actually using Javascript to change the link instead of the status bar. When the page is loaded, the links in the results list go to their actual destinations, but every link has an onmousedown javascript event that changes the link when you click on it. You can see this in action by right-clicking on a link. After you've done that, hovering over the link will now show the true destination (Google's click-tracking script) in the status bar instead of the result's real URL.

    Of course the information displayed with any method could be a misrepresentation of where I'm actually going to be sent, but I still prefer it over seeing a meaningless id number.

    Andrew Hare : +1 For a very nice explanation.
    Xaisoft : I am not to up-to-date on javascript, do you have an example of how this is done.
    Chad Birch : I will edit some information into my answer about it.
    Frank Crook : That's incredibly neat and something I've never noticed about the links Google provided. I had to play with the links by clicking down and not releasing before I believed you.
    Xaisoft : Is the Click-Tracking script open source to view?
  • If you control website B, then you just use the http_referer portion in logging. Otherwise, you will want to have a redirect page on site A, that records the url, then redirects the browser through to the other site/page.

    http://siteA/redirect?url=siteB/page
    

    the redirect page in site a redirects to..

    "http://" + request['url']
    

0 comments:

Post a Comment