|
Motivation The hit counter services I find on the web never seem to be quite what I want. I have for some time been using one provided by easycounter.com. It is pretty good, but still not quite right for me. I am sure that Google Analytics provides lots of features, but when I signed up with that I found it rather intimidating, and I could not find any clear summary of what it provides. So I have now rolled my own, and as an experiment I have made it so that it will provide the same facilities to anyone who wants to use it. It is written in PHP, which is available on the majority of web-hosting systems, so you can quite easily upload a few files to your web server and set it up for yourself. It's also open-source, so you can tweak it do do axactly what you want. This is a small system for those who run small, low-volume web sites, but I'm sure there are plenty of those around. It's not finished yet, but I have posted this page as a sort of preview and specification. If you are interested, please get in touch. Features. So what does it do that's different? Well, for a start, its primary focus is on provinding the web page owner with topical information on who's reading the page, and from where. So the principal features are a few simple reports that will either provide you with a rosy glow - people love your page all over the world - or an informed depression - nobody except some nut-case in Outer Mongolia is reading it. Hit counting, although it is provided in several forms, is a secondary feature. I personally think that hit counters are a bit tacky, and not really something that the reader of the page needs to know about. To get them out of the way, I'll deal with them first. Hit Counting. Most hit counters insist on providing you with an image of the current count in some horrid selection of rather gaudy fonts. The BEV hit counter allows you to choose from three options:
Visitors 1272, Hits 2004 The exact text fragment is determined by the user, who has to provide a text fragment like "Visitors @v, Hits @h, into which the numbers are substituted at the appropriate position." The last method is only for you if you trust BEV as a source, or if you install the system on your own server, since loading script blocks is inherently insecure. This method populates the script block with Javascript text as follows: var visitors = NNNN; var hits = NNNN; Given the existence of these Javascript variables, you can insert the hit information anywhere and anyhow you like in your page using DHTML. The system also allows you to specify fudge factors for the counts so you can adjust the number of hits to take account of the past, or even inflate them - shame on you. To get your site's hit counts, all you need on your page is an image tag like: <img src="http://www.britseyeview.com/php/hits.php?method=2&cid=user_id&pid=your_page_id" width="200" height="22">or an IFRAME like: <iframe src="http://www.britseyeview.com/php/hits2.php?method=1&cid=user_id&pid=your_page_id" width="200" height="22" frameborder="0"></iframe>or a script block like: <script src="http://www.britseyeview.com/php/hits3.php?method=3&cid=user_id&pid=your_page_id"></script>The method parameter in the query string above "method=2" etc tells the server how you want the information presented:
A separate web service is used to record hits on your pages. The two facilities are separated since many users won't be interested in putting hit counts on the page. You can use similar methods to log hits: <img src="http://www.britseyeview.com/php/hits1.php?cid=user_id&pid=your_page_id" width="0" height="0"> <iframe src="http://www.britseyeview.com/php/hits2.php?cid=user_id&pid=your_page_id" width="0" height="0" frameborder="0"></iframe> <script src="http://www.britseyeview.com/php/logvisit.php?cid=user_id&pid=your_page_id"></script>In the IFRAME or script block cases, if you have requested it, the script block method can also return some information about the location of the user that you can use to structure the content of your page appropriately. Of course these calls also writes information about the hit to a database.. The pageid information that you specify in the links above can take two forms. It can be a plain old string, like in my case "BEV", or it can be an indication of some generic type of page within your web site. I have two such generic page types, "archive" - the past month pages of BEV, and "ebook" - the year by year pages of the BEV retropective. These can be qualified by some extra information, like "archive:sep2004" so that custom stats code can provide finer grain information, and so that the recent hits report can be more specific. Filtering Development Hits. The other piece of the jigsaw puzzle is your own hits. If you have a small volume page, or a new page, and you're like me, you will mess with it frequently, and some days half the hits could be you testing things. There are lots of ways to test your page, but the definitive one is to access it. So I want to be able to turn off logging of requests that come from my development machine or machines. To this end, the BEV Hits'n Stats system can set a cookie on your machine that will prevent hits from you being logged. Of course this may defeat the purpose of the testing, so additionally, it is possible to specify that the same information be logged to an alternate database table. That way you can test to your hearts content, but the test results don't get into the permanent statistics record in the database. The Database. Hits'n Stats uses the MySQL database - also available on most web hosting setups. There are four database tables involved:
Reports. The reports provided by the base Hits'n Stats system are:
Subscribing to Hits'n Stats. To subscribe you will need to provide the following information:
If you don't check the box allowing any well formed page ID, you will also have to specify a list of page IDs, like in my case: "BEV, archive, ebook, ap, software, publicity, dcat, hitsnstats, hssignup". You can follow up on this by filling in information on the page preferences page if you want extended names for the pages in reports, fudge factors, some particular colour for hit information images, or some style for IFRAME hit counts (per page). Fudge factors are specified as an integer number 'offset', and a floating point number 'factor'. Hits returned by the system for use on your page will then be calculated as follows: display_hits = offset + factor*actual_hitsIf you do check the flag allowing any well formed page ID, then any such log-visit request will be logged under your client ID, and the default colour, style, and substitution phrase will be used. Fudging of hit counts won't happen in this case. Legal IDs consist of upper or lower case alphabetic characters, digits, and the underscore. Any punctuation character or space signals the end of the ID, and subsequent characters are considered to be supplementary information. For example I can label an archive page "archive+mar2009" (the + is the URL encoding for a space), or "archive.mar2009", or "archive%3Amar2009". In reports, this will be counted under the page category "archive", and in the recent hits list it will be shown as "archive:mar2009". IDs are case sensitive. If you uncheck the box for initial page, then you will get the recent hits page after login. Please feel free to try it out. If you decide you don't want your information in my database anymore, there's a page you can go to to if you are logged in, to expunge your information from the system. The Source. Hits'n Stats is implemented in PHP, and you are welcome to download the source code |