Express install instructions for phpOpenTracker

I suggested phpOpenTracker as an alternative for visitor statistics based on the webserver logs. This is a summarized installation procedure for a typical php and mysql environment (note: the tracked site can be any platform!), extracted from the documentation:

The phpOpenTracker library

  • Download phpopentracker<versionnumber>.tgz
  • unzip, and upload the /phpopentracker directory and the phpopentracker.php file (at the same level after unzipping) to your webserver (it’s a good habit to put library files outside the web root directory)
  • run the /docs/sql/mysql/myisam.sql sql instructions in a newly created or existing database on your host
  • rename conf/phpOpenTracker.php.dist to conf/phpOpenTracker.php
  • uncomment and change at least the following settings in this conf/phpOpenTracker.php:
    • $PHPOPENTRACKER_CONFIGURATION[‘db_user’] = ‘***********’;
    • $PHPOPENTRACKER_CONFIGURATION[‘db_password’] = ‘***********’;
    • $PHPOPENTRACKER_CONFIGURATION[‘db_database’] = ‘***********’;

    to the values appropriate for the database you have put your tables in

The “web-bug” setup

Most of the times this library code is called by including the phpOpenTracker.php script in your own php code and calling the “phpOpenTracker::log();” function (see Listing 2.1 for a code snippet). But this is exactly what we want to avoid, because then we will still log page requests by search bots, referer spammers, and rss clients.

What you better do in order to track real people using browsers to access your site, is using a web-bug: a fake 1px image that is in fact a php file instead of a static image. Search and spam bots don’t download these images, browsers do. You can set up a web-bug this way:

  • copy the /docs/scripts/image.php and /docs/examples/webbug/webbug.js files to a place within the web root (probably the same directory). Neither the image.php nor the webbug.js have to be on the same host as the pages you’re monitoring, but but it’s better to do so, because some users set their browsers not to display external images or to run external javascripts in pages. Still, if you want to monitor an external static site or you want to set up one logging installation for multiple hosts, you’ll probably still get fairly accurate statistics with an external image.php
  • edit image.php (phpopentracker can be part of the PEAR library which assumes the PEAR files are in your include_path, but that might not be the case in your setup):
    // require 'phpOpenTracker.php';// modif pvh 20050717
    require '/[the/path/to]/phpOpenTracker.php';//
  • modify webbug.js so that it refers to the correct (absolute) path to image.php:
    '<img src="[/path/to/]image.php?' +
  • modify your site’s template so that it includes the webbug: probably you’ll have to make the path to the webbug.js and to image.php absolute (and include the hostname when working over different hosts)
    <script language="JavaScript" src="[/path/to/]webbug.js" type="text/javascript">
    <img alt="" src="[/path/to/]image.php?client_id=1" width="1"
    height="1" />

A simple report

You’re ready and tracking visitors now!

Uh… but you probably will want to have some reporting system to tell you how many people came to which pages, don’t you?

  • the idea behind phpOpentracker is that you build your reporting system yoursel using their API. Probably that’s not what you want, so there’s a default “simple report” included in /docs/examples/simple_report.
  • edit index.php to include the full path (if necessary, see the explanation above on include_path when editing image.php):
    //require_once 'phpOpenTracker.php';//modif pvh 20050717
    require_once '/[path/to]/phpOpenTracker.php';
  • Upload this directory to somewhere in your webspace, point your browser to it and… you’ll see your stats!
  • all of this is textual – if you want to see some charts as well:
    • download JpGraph (a php library, free for non-commercial use), unzip and upload the files you found in the src dir (omit the examples subdir) to some jpgraph library directory (let’s say at the same level as the phpOpenTracker library)
    • edit conf/phpOpenTracker.php: $PHPOPENTRACKER_CONFIGURATION['jpgraph_path'] = '[/path/to/]jpgraph/';
    • edit graph.php in the report directory the same way you edited image.php and index.php (if necessary)://require_once 'phpOpenTracker.php';//modif pvh 20050717
      require_once '/[path/to]/phpOpenTracker.php';
    • if the graph produces an error “font file … does not exist” you might need to upload the necessary ttf file and edit jpgraph/ DEFINE("TTF_DIR","/usr/X11R6/lib/X11/fonts/truetype/");
      DEFINE("TTF_DIR","/[path/to]/jpgraph/ttf/");//modif pvh

That should be it! But, there’s more to tell about phpOpenTracker plugins and the API. To be continued.

17 Responses to “Express install instructions for phpOpenTracker”

  1. Ellery Leung Says:

    Hi, just read this article and I found that it’s great for me to actually implement phpOpenTracker for my website. Thank you.

    One point to note: when I followed this step: modify your site’s template so… I just copy & paste your javascript code in my HTML file. However, after doing that no record is added to phpopentracker database. Both failed in MSIE6 and Firefox 1.5…

    However, when I use the content inside …, i.e. only include

    in my code. It works fine.

    Hope it helps.

  2. Ellery Leung Says:

    Seems your blog strip out all tags. What I mean is only input the content inside noscript tags…

  3. Pascal Says:

    You might need to check whether the webbug.js writes the same client ID. The javascript ends with:

    ‘<img src="/_extra/image.php?’ +
    ‘client_id=’ + client_id + ‘&’ +
    ‘document_url=’ + base64_encode(document.URL) + ‘&’ +
    ‘referer=’ + base64_encode(document.referrer) + ‘&’ +
    ‘add_data[]=resolution::’ + resolution +
    ‘" alt="" width="1" height="1" />’

    and the client_id is set at the start:

    var client_id = 1;

    You can see the source when you open /path/to/webbug.js in your browser.

  4. Ellery Leung Says:

    Thx for reply.

    One interesting thing is: when I look at the source HTML file, I CANNOT see the

  5. Russell Says:

    I got this working, but not tried the pixel thing yet, and yes, google comes up loads :S

    But the problem I have is that there is no graph shown at the top of the page on the simple_report. I just have a white box with a cross, probably meaning the script isnt working or something. Thing is, its the example code, not edited by me, so how come this happens.

    Would be nice to get the graph working, if anyone has any ideas, please let me know on here. Thanks.


  6. Cam Says:

    russel i think you have to have JPgraph installed

  7. Russell Says:

    Ive downloaded jpgraph, set the path in the config to the right path for the jpgraph src, but no luck.

    Maybe i need to setup jpgraph somehow, cos all I did it download it and put it on the site, and linked phpopentracker to it.

    Would reall appreciate someones help. Email me at (ukredfox at gmail dot com)

  8. WP-ShortStat plugin broken after upgrading to Wordpress 2.0.2 Says:

    […] It’s a very quick solution if you want to diagnose a blog problem and need to monitor all behaviour on your website (searchbots, feedtraffic and browsers).  I would not recommend it for other than private and short-term use however…  If you want really meaningful information on human visitors, you’ll have to switch to a webbug-based system (see these postings on refer spam and phpopentracker).  And because all site requests are logged in Mysql, you get huge tables and performance problems in no time (PhpOpentracker has the same problem, BTW).  But again, it does serve its purpose as a short-term solution! […]

  9. stats med phpOpentracker at mö Says:

    […] et par links af interesse: sebastian bergmann Quick n dirty guide – for dem der ikke gider læse api manualen mailing liste arkivet […]

  10. vijay Says:

    Hi All,

    I don’t know php. Can I use this in my website written in pure HTML?

    Please help.


  11. Bart Says:

    Does somebody know a script where a bunch of stats are being generated using the phpopenstats package? Been searching for this, but i can’ t find it or there is none released yet. Would be very usefull to a whole lot of persons i think!

  12. Pascal Says:

    Did you check the default “simple report” included in /docs/examples/simple_report?

    There was no other report included when I installed it, and if you googled for it in vain, then there probably isn’t any other (I remember having read about a commercial reporting tool written on top of phpOpentracker though).

    It’s been a long time I have been testing phpOpentracker: so many free visitor tracking services have come out in the meantime, along with the beautiful self-hosted Mint, that I haven’t installed phpOpentracker since.

  13. Vijay Says:

    I am a newbie in php.

    I went thru the same process explaind here….but I get a strange error when I was trying to view the page.

    Can you help me pls.? I am trying to find detailed installation manual.

    Warning: require_once(phpOpenTracker.php) [function.require-once]: failed to open stream: No such file or directory in /is/htdocs/wp1050921_WHQ0AL2PBK/www/uebersicht/index.php on line 3

    Fatal error: require_once() [function.require]: Failed opening required ‘phpOpenTracker.php’ (include_path=’.:/home/mann/PEAR:/home/mann/class’) in /is/htdocs/wp1050921_WHQ0AL2PBK/www/uebersicht/index.php on line 3

  14. Pascal Says:

    Hello Vijay,

    as I wrote in the post:

    “phpopentracker can be part of the PEAR library which assumes the PEAR files are in your include_path, but that might not be the case in your setup):
    // require ‘phpOpenTracker.php’;// modif pvh 20050717
    require ‘/[the/path/to]/phpOpenTracker.php’;//”

    if php cannot find the file, you’ll need to mention the full path to the file in the require statement

  15. Vijay Says:

    Hi Pascal,

    Thank you so much. I am able to solve the error. But now I am getting a different error.
    I have been doing research on web on this but couldn’t find it anywhere. Infact, there is no better installation instructions found except this.

    I really appreciate your help.

    Can you help me fix this error? I was installing in my computer.

    Fatal error: Class ‘phpOpenTracker_Config’ not found in C:\Program Files\xampp\htdocs\stats\phpOpenTracker\docs\examples\simple_report\index.php on line 65

    Thanks again.


  16. Pascal Says:

    Haven’t had the error yet, but it probably means something is still wrong with the inclusion of the file.
    Try to google for “Class * not found in *.php” error

  17. Vijay Says:

    Thanks, Pascal for all the help…

    I will update the thread as soon as I found a fix.