Hosted counters are probably the simplest and easiest option for the non-technically inclined. All that is required is that you sign up at a counter service's site, then receive a segment of html code which you must insert into the page you want tracked. There's nothing more to it.
All hosted counters — more commonly known as "
free web counters" — follow this basic idea. The html code they give contains a url to an image hosted on the counter company's site. When a web surfer hits your page, they load the counter's image embedded on the page from the counter company's site. When this happens, the counter registers a "hit", and may record some other information about the request, such as the type of web browser the user uses (Firefox, Internet Explorer or Safari, etc.).
Some take this a step further, and use javascript in the segment of html code given to you to record additional information that browsers would not normally send along with a request for an image. This information may include the HTTP_REFERER header (contains the URL from which a user clicked to your page; see
About tracking referers) or things such as the window size of the user's browser. Javascript appends such information to the counter image url, for instance, if the counter image is normally located at http://counterco.com/count?id=yourid, it changes it to http://counterco.com/count?id=yourid&screenheight=600&screenwidth=800&referer=www.google.com/search . This information would not normally be sent along with the request for the counter image by a web surfer's browser, so javascript sticks it in the url for the counter to record for your betterment.
In addition, though it is rare for free counters to offer this feature, some offer a counter image that is actually a one pixel by one pixel transparent gif file -- so that most users will have no idea of its existence on a web page. Some people prefer this setup. Other than the imperceptible presence of the image, there is nothing technically different about using a tiny transparent image to count users.
Sounds too easy, then huh?
Of course, there are a number of drawbacks to using a hosted counter.
For one, many free counters do not offer it, and it is considerably more difficult for novice users to count more than one page. You can count every page as if it were one page, and you can count only the front page, but counting every page is difficult. If you can find a service that offers it, they may require you to register and get a separate segment of html code for every page you want to count. If you have a large, constantly changing site, this may be an untenable pain.
Second, how should repeat visits be counted? Even if the tracker company encourages counting every request to a page or only every unique visit via the headers it sends along with the counter image, browsers may still foul things up by behaving inconsistently. Some browsers may always re-request the image if the user hits the back button to return to your page no matter if the counter company's servers tell it not to, and some browsers may never reload the image even the user hasn't visited your site in a long time.
Hosted counters cannot record certain special kinds of requests that are used to tell what kind of content a page contains or if the page has been modified since the browser last requested the page, such as HEAD requests or successful HTTP If-not-modified requests. These hits are somewhat unusual, and you can eliminate If-not-modified requests if you know what you are doing.
Another problem is if the user remains behind a caching proxy server. The proxy server may hold onto the image between requests and keep giving its users the same cached copy. Since the image is not being requested from the counter company's servers, it has no way of recording the hits. There are ways of discouraging this behavior, but it is not always possible (see
Counting every single hit).
Finally, a small percentage of users will leave images turned off in their browser. These users will not be counted at all. If you want to record hits from web spider's like Googlebot or MSNbot, you will not be able to since when such spiders browse a web site they only look at the html code and don't bother to download images.
That being said, for its ease-of-use, the free hosted counter is probably the most popular method of hit counting.
To find a hosted counter, see the
free hit counter list or the
paid hit counter list.
For an alternative, see the article
How log analyzers work.