> Main > Products and Services > Purchase > Company
English / Russian

Site Statistics Accumulation Using Site Usages. Types of Counters.

The article is dedicated to various counter types and their main operation principles.

The site statistics analysis is performed on the basis of the site visitors information. This data is accumulated by the web-server (then it is registered in log-files) or by site usage counters (afterwards it is stored in databases). Operation principles of different counter types will be considered below.

General Principle

Counter functioning is based on the external application running during web-pages download and gaining the so called environment variables. There is all essential information about a site visitor, including:

Query parameters or QUERY_STRING are indicated by ? symbol after the page address and are divided by &, for example:


The external program invocation can be performed in different ways; the most common is using a picture.

Graphic Counter

As a rule, web-site pages contain text and graphics. The text is formatted by means of specified tags; graphics is a set of pictures which are arranged correctly.

A picture is placed as follows:

... text of html page...
<img src=http://www.myserver.com/img/picture.gif width=468 height=60>
... text of html page...

The browser sends a request to http://www.myserver.com/img/picture.gif and the server transfers the picture file into the response.

Note: Graphic counter functioning is based on the suggestion that while viewing your site, the user's browser downloads all the pictures - and a graphic counter as well. There are two essential problems which can occur in this case:

Thus, it will be impossible to count users with pictures disabled and to control robots activity on the site.

Statistics Accumulation on the Basis of a Graphic Counter

External application call ("pretending" to be a picture) is inserted instead of the link to the picture:

<img src=http://www.myserver.com/counter.php height=1 width=1>

"Counter.php" program generates the picture file and sends it to the browser. Thus, the program invocation looks like simple picture downloading for the browser.

The generated picture can be of various types. For example, transparent GIF of the size 1x1, or 88x31 picture containing site usage data (total pageviews, pageviews for the current day, users for the current day), or any other.

While analyzing environment variables, the application gets visitor's IP-address and browser data, and registers this information in the database for further analysis. However, additional data is required for complete statistics. Query parameters string is used to transfer additional information to the application. For example, screen resolution can be transferred as follows:

<img src=http://www.myserver.com/counter.php?screen=1024 height=1 width=1>

Additional user data is obtained using java-script: a referrer, screen resolution, colour depth, random number, enabled cookie etc. That is why you have to insert a lot of counter codes in java-script while using a graphic counter.

It is possible to record information about most users with the help of graphic counter; however, search bots and users with pictures disabled will not be considered.

Counter as a Program Inclusion

Nowadays most sites are dynamic: their pages are generated on the fly by visitor's request. These pages are written with the help of a program language, mainly PHP, ASP, JSP. I.e. web-site pages are in fact applications and possess their own environment variables. For instance, we can write a PHP-code, which will be accumulating visitor's data and storing it in the database, but it will not be displaying any visual information. For convenient insertion into web pages, it is usually formed as one file and then installed.

For example, CNStats program inclusion counter code (PHP-Include) looks as:

... php-code ...
include "/usr/www/users/www.myserver.com/cnstats/cnt.php";
... php-code ...

Since the counter code is included into the page code, all the visitors will be counted assuredly without even noticing. However, there are certain disadvantages in using a program inclusion:

Combined Counter: a Program Inclusion Plus Picture

The idea implies that the program inclusion code is inserted into dynamic web-pages; it will be displaying graphic counter code. As a result:

  1. The program inclusion code is invoked at the moment of the page generation; the information obtained from the environment variables is stored in the database;
  2. Java-script code of the graphic counter appears on the generated page;
  3. While the browser downloads the page, java-script displays the graphic counter with the additionally accumulated information;
  4. The additional user data collected by java-script is registered in the database.

The statistics accumulation system becomes more complicated (besides, combined counter type does not always fit here), but at the same time, it is the only variant of accumulating the most accurate information about all the visitors. Combined counters are very challenging.


Now you know something about basic counter types. We hope that this information will be useful and will help you to choose the most convenient way of the site statistics accumulation.
Finally, we would like to give you a couple of recommendations:

20 october 2005
Vlad Gerasimov