What Is a Hit?


Let s clarify a few issues about the hit counter before we get into programming it. The first and easiest issue to clarify is that the counter you ll develop in this chapter is page specific that is, it won t track hits to your site as a whole, just to a specific page. If you put the counter on your home page but someone bypasses the home page and goes straight to another page on your site, the counter you create here won t detect that.

A second and more interesting issue is determining what exactly we mean by a hit. The simplest definition is that a hit is a measure of how many times a page has been displayed. This notion of a hit is a bit dull, however someone could simply click Refresh in the browser and turn over the hit counter at will, so you wouldn t be tracking anything particularly useful. Keep in mind too that in ASP.NET, each postback would cause a hit in this scenario.

Another way to define a hit is as a measure of the first time a user displays a page that is, as a record of each unique hit. This means that the first time a person sees a page, he or she is counted, but never again after that. Unique hits are appropriate for a counter that proposes to count visitors along the lines of You are visitor xxxx to this page.

How to count hits is important if you re running a commercial site and your advertisers want to know accurately how many people they re reaching. We re not running a commercial site, however, so our definition of hits doesn t have to be particularly stringent. For our hit counter, we can count hits using one of the following methods:

  • By session.  When users first run the page, they re counted. While they work with pages in the site, they aren t counted again. But if they close their browser, reopen it, and then visit the site again, the repeat visit is considered a new session, so they ll be counted again. In practical terms, you re tracking discrete visits to the site, not unique visitors.

  • By user.  In this scenario, users are counted the first time they run the page, but not thereafter. Your application will know that those users have been to the site and won t count them again. This type of counter is closer to a unique visitors counter than the session-based counter.

I ll show you how to count hits both ways in fact, the difference between the two techniques boils down to a single line of code. When you create the hit-counter page, you can choose which type of hit counter you prefer.




Microsoft ASP. NET Web Matrix Starter Kit
Microsoft ASP.NET Web Matrix Starter Kit (Bpg-Other)
ISBN: 0735618569
EAN: 2147483647
Year: 2003
Pages: 169
Authors: Mike Pope

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net