Web Referral Tracking User Control

In my efforts to continue building my personal web sites, I wanted to see where my visitors are coming from and how they are getting to my web site. Unfortunately, my ISP doesn’t provide me with any kind of stats or access to the logs, so I’m kind of screwed there. So, I decided to take things into my own hands, and wrote a user control that has relatively little UI (and even then it’s easy to disable).

My solution uses an XML file in the app_data directory. I chose this as it was pretty easy to test and write, but I found out when I went to deploy it, my ISP won’t let me write to files in my app_data directory either. The solution I ended up using was a SQL one, but for now, I’m going to post the XML file version. There are some issues with this, it does lock the file while the data is updated, so you run the risk of slowing your website down. I took this as an acceptable side effect on my website as I don’t get a lot of hits, and if it takes an extra second or two to load, people can deal.

The solution I ended up using gets the data from an SQL database instead of an XML file, but it still does the same thing where it reads from the table to find out if the hit has happened before, so it can then increase the count, or if it’s a fresh hit, it’ll just add a new entry to the table.