Tuesday, July 20, 2010

Typically you put up a website and hope everything goes well and is used. It is often a good idea to track the pages that users actually go to, and from where. A novice developer would likely add code to every page to record this information. A better developer may add code to a master page to do the same. A better (and simpler) solution is to just drop a IHttpModule on to the website and have it record. If you produce many websites, then just compile it to a DLL and add it to each

You can add a lot more information if you wish. The information is inserted into a SQL with three tables, the page reference table:

PageId Int Identity(1,1)

PageUrl varchar(255)

The Session reference table:

SId Int Identity(1,1)

SessionId varchar(255)

ClientIP varchar(22)

And into the log table:

LogId int Identity (1,1)

PageId

Sid

ReceivedTime Datetime

This allows you to see how long the client spent on each page, what page they go to next, etc. A useful exercise is often to create a chart of all of the pages and the percentage of time they go between each. For example, you can use Visio to generate a site map, now just add the % of times between each page to each link. The results may cause you to restructure the website or identify pages that are not being used as expected.