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

Documentation

CNStats 4.2 User Manual

© "CN-Software" Ltd. 2002-2012
support@cn-software.com
www.cn-software.com
Previous | Table of Contents  | Next

Counters Work Description

Counters of Site Usage Statistics

Counter for the site written in PHP consists of two parts. The first part is initiated directly from the PHP script by:

<?php
include “/path/to/cnstats/cnt.php”
?>

By default, this code stores most information about the request into the CNStats database and outputs JavaScript code onto the web-site page. This JavaScript code initiates the second part of the counter. The second counter part "for the sites written in PHP" is initiated as an image via HTML tag <img src=”/cnstats/cnt-combined.php”>. The second counter part interacts with Cookies, determining and saving the following information into the database:

It is important that the output of the first part of the counter is not suspended by the site engine, otherwise, the second part of the counter will not be initiated and the request will be countered as one done by a robot.

In case there is no way to insert the counter code to the place where the code can be initiated, then use the option $STATS_CONF["codegeneration"] to place two code parts into different places of the web-site engine.

Counter for the sites with non-PHP contents is a bit simpler. The counter is a JavaScript code, which, using cnt-gif1x1.php image-adapter, initiates the main counter cnt.php. The adapter retrieves additional information from QUERY_STRING and passes it to the main counter. Below is the list of data that is processed and transferred by the adapter:

This code does not count requests from the robots, since it is initiated when the image is loaded via JavaScript code. On the one hand, it is a disadvantage, on the other hand – an advantage, because you can take the load off the statistics server and reduce the size of the database. In fact, robots can generate large number of requests at a time.

Both counter types display invisible image of 1x1 pixel size. In case you want the counter image be visible, you should use one of the codes for displaying counters.

Counters for Displaying Statistics

Counters for displaying statistics are not counters, since they do not accumulate statistics, instead, they display images with the site usage stats values. There are two such counters in CNStats:

If you install only the code for displaying counters, there will be no statistics. If you want to display the counter, you should install both the code for counter displaying and the code for accumulating statistics.

CNStats API

When the counter is initiated, you can transfer additional information with it.

RSS Channel Flag - $GLOBALS["CNSTATSRSS"]

RSS channel flag is used if the counter code is initiated via the RSS channel. If the flag is set to "yes", then this request will be present only in the report belonging to the  "RSS channels" block.

Example:

<?php
ob_start();
 
// Set RSS channel flag
$GLOBALS["CNSTATSRSS"]="yes";
 
// Initiate counter
include_once "/usr/local/www/novgorod.ru/nv/cnt.php";
 
//  Delete JavaScript code generated by the cnt.php counter. This code may affect the RSS file integrity.
ob_end_clean();
?>

Page 404 Flag - $GLOBALS["CNSTATS404"]

Page 404 flag is used if the counter code is initiated from the page 404. If the flag is set to "yes", then this request will be present only in the reports Pages – Popular  Pages 404 and Referrers – Links to Pages 404.

Example:

<?php
// Set page 404 flag
$GLOBALS["CNSTATS404"]="yes";
 
// Initiate counter
include_once "/usr/local/www/novgorod.ru/nv/cnt.php";
?>

When using "counter code for the sites with non-PHP contents", page 404 flag can be transferred via "is404" variable in QUERY_STRING string.

Page Title - $GLOBALS[“CNSTATS_TITLE”]

If the site engine stores the page title in PHP variable, then this title can be transferred directly to CNStats counter. In this case, the page title will be added to main statistics even if the second part of the counter code (JavaScript + image) is incorrectly initiated. If the second part of the counter code is correctly initiated, then the page title will be replaced by the one determined via JavaScript.

Starting with version 4.2, the page title should be transferred in UTF-8.

Example:

<?php
 
// Set the page title
$CNSTATS_TITLE=”Page title”;

// Initiate counter
include_once "/usr/local/www/novgorod.ru/nv/cnt.php";
?>

When using "counter code for the sites with the non-PHP contents", the page title is determined automatically.

Custom Fields

Starting with version 4.2, you can save additional information to the database and use it when generating statistical reports. This is such information as login or identifier of the registered user, user authorization flag and etc.

You can use up to three additional custom fields.

To activate additional fields, you should enable them and define the fields names in the Configuration – Program Settings  – Custom Fields. After that, the fields will be available for creating filters.

To add information into these fields, use $STATS_CONF["userfield1"], $STATS_CONF["userfield2"] and $STATS_CONF["userfield3"] options. You can add any information, that you want to add to the database, into these fields. Text values should be transferred in UTF-8.

Example:

<?php
 
// Define user login and save it into the first custom field
$STATS_CONF["userfield1"]=poral.userGetLogin();
 
// Determine authorization flag
$STATS_CONF["userfield2"]=empty($STATS_CONF["userfield1"])?”no”:”yes”;
 
// Initiate counter
include_once "/usr/local/www/novgorod.ru/nv/cnt.php";
?>

When using "counter code for the sites with the non-PHP contents", the field values can be transferred via QUERY_STRING – uf1, uf2 and uf3 variables.

Example:

<!-- CNStats begin -->
<script type="text/javascript">
cnsd=document;cnst=escape(cnsd.title);
cnst=cnst.replace(/\+/g,'%2B');cnsa=navigator.appName;
cnsn=(cnsa.substring(0,2)=='Mi')?0:1;cnss=screen;cnspx=(cnsn==0)?cnss.colorDepth:cnss.pixelDepth;
document.write('<img src="http://mysite.com/nv/cnt-gif1x1.php?uf1=<?php print urlencode(iconv("windows-1251","utf-8",$NUSER["username"]));?>&amp;uf2=<?php print $NUSER["auth"]?1:0;?>&amp;e='+cnss.width+'.'+cnss.height+'&amp;d='+cnspx+'&amp;r='+escape(cnsd.referrer)+'&amp;p='+escape(cnsd.location)+'&amp;t='+cnst+'" width="1" height="1" border="0">');
</script><noscript><img src="http://novgorod.ru/nv/cnt-gif1x1.php?468&amp;uf1=<?php print urlencode(iconv("windows-1251","utf-8",$NUSER["username"]));?>&amp;uf2=<?php print $NUSER["auth"]?1:0;?>&amp;c=0" width="1" height="1" border="0" alt="" /></noscript>
<!-- CNStats end -->


Previous | Table of Contents  | Next