views:

55

answers:

4

How can I determine where a user came from when they land on my webpage.

  • Did they come from a google link?
  • Did they user a favorites link?
  • Did they type in the url?
+1  A: 

Look at the HTTP Referrer header.

leppie
+6  A: 

If the user browsed to your site via a hyperlink, the following will provide this information:

Request.ServerVariables["HTTP_REFERER"]

Although note on the above it is possible for browsers to block the value (empty value).

You also won't be able to detect if the user specifically used a favorite, typed in the link, etc. These are browser actions that are outside the scope of what client or serverside code can detect once the user lands on your site.

KP
+2  A: 

You can check the Request.UrlReferrer of the current HttpRequest: it will usually contain the page from where the user is coming from (depends on the browser, though).

If the URI contains "google.com/search" you can assume it is a google search and can try to extract the keywords used (you might want to use a regex to detect all various google regional domains). If it is empty, the user probably typed in your URL (or used a favorite link).

Lck
+1  A: 

You can also achieve this with a bit of JavaScript:

document.referrer
P.Brian.Mackey