Search code examples
c#asp.netsearchanalytics

How to know the referral source of my website/page


I have a website where I want keep track of the Statistics about the users who came to my page from different sources. I want to identify whether user came from Search engines / other websites / direct typing the URL. I am using asp.net and C#. Please help


Solution

  • As Abdel suggests in his comment, the easiest solution would be to use Google Analytics or a similar tool.

    If you really want to do this yourself you should look at the HttpRequest type. This is available in your code through the Page.Request property. The request has a property for UrlReferrer that tells you the url of the page that linked to this one.

    Edit: You should be aware that the UrlReferrer may not have the information you need. If the user is sent to your page using a Javascript function you may not get a referrer. Also it will be a lot of work to extract really useful information yourself, so the best option is still to use a thrid-party tool like Google Analytics.