The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

WWW::Statistics - Perl extension for genarate and manage web site statistics

SYNOPSIS

use WWW::Statistics;
my $wso = WWW::Statistics->new(
	DB_USER => 'test' ,
	DB_PASSWORD => 'toto',
	DB_HOST => '192.168.0.20',
	DB_DATABASE => 'test_stat'
) or die "[ ERROR ]\n";
$wso->setMSTN('test_script');
$wso->setBACKUP_TABLE_NAME('backup_script');
$wso->initDataBase(
	MAIN_STAT_TABLE_NAME => test_script,
	PAGES_LIST => 'first,seconde,third'
) or die "[ ERROR ]\n";
$wso->addMainPages(PAGES_LIST => 'test') or die "[ ERROR ]\n";
print "[ OK ]\n";
$id = $wso->getIDfromPage('test');
print "[+] id page 'test' (according to getIDfromPage)\t $id\n";
$wso->initBackupDatabase or die "[ ERROR ]\n";
$wso->dropMainPages(ID_LIST=>$id) or die "[ ERROR ]\n";
$wso->updateBackupDBschema or die "[ ERROR ]\n";
my $id = $wso->backupStats(
	BACKUP_DESCRIPTION => 'This is a test of WWW::Statistics'
);
my $html = $wso->generateHTMLMainGraph(
	IMAGES_DIR => '/home/arnaud/images/',
	TABLE_NAME_FONT => "<font color='#3366CC'>",
	TABLE_TAG => "<table cellspacing='1' cellpadding='5' width='250' border='0' bgcolor='#000000'>",
	TR_TAG => "<tr bgcolor='#EEEEEE'>"
);
Write('gen.html',"$html\n"); ## The Write function is from File::Reader
$g = $wso->generateGDGraph(
	GRAPH_WIDTH => 800,
	WITH_HTML => 1
); ## Generate a graph and return the HTML source code wich included him, else this metod return the name of the image.
my $back = $wso->generateHTMLBackupGraph(
	IMAGES_DIR => '/home/1024/INSEP/soutien/images',
	BACKUP_ID => 5,
	IMAGES_CYCLING => 1,
	TABLE_NAME_FONT => "<font color='#3366CC'>",
	TABLE_TAG => "<table cellspacing='1' cellpadding='5' width='250' border='0' bgcolor='#000000'>",
	TR_TAG => "<tr bgcolor='#EEEEEE'>"
);
$wso->reIndexBackupTable;

DESCRIPTION

This module allow you to simply manage statistics for web site. It generate a really simple database, and give you all methods to manage it easily. With WWW::Statistics you can make your own statistics admin interface really simply.

EXPORT

None by default.

METHODS

  • new : constructor. Arguments are : DB_HOST : IP adress or hostname of the database (default is 127.0.0.1)

            DB_USER : A username wich is authoryzed to connect to database (default is undef)
    	
            DB_PASSWORD : The password associates with DBUSER (default is undef)
    	
            DB_DATABASE : the database name (default is undef)
            
    	DB_TYPE : the DBI driver name (default is 'mysql')
    	
    	IMAGES_DIR : the directory where we can found images for using in HTML graph generation. (optionnal)
    	

    Moreover, you can pass all arguments wich are definable by followings accessors. It returned a WWW::Statistics object reference

  • setMSTN(VALUE) :

    accessor for setting MAIN_STAT_TABLE_NAME. It returned 1 or undef.
  • getMSTN :

    accessor for getting value of MAIN_STAT_TABLE_NAME.
  • setBACKUP_TABLE_NAME(VALUE) :

    accessor for setting BACKUP_TABLE_NAME. It returned 1 or undef.
  • getBACKUP_TABLE_NAME :

    accessor for getting value of BACKUP_TABLE_NAME
  • setBACKUP_DESCRIPTION(VALUE) :

    accessor for setting BACKUP_DESCRIPTION. It returned 1 or undef.
  • getBACKUP_DESCRIPTION :

    accessor for getting value of BACKUP_DESCRIPTION
  • setIMAGES_DIR(VALUE) :

    accessor for setting IMAGES_DIR. It returned 1 or undef.
  • getIMAGES_DIR :

    accessor for getting value of IMAGES_DIR
  • addMainPages :

    Add a page to the main stats table (MAIN_STAT_TABLE_NAME). Returned undef if faile, else 1.
  • dropMainPages :

    drop a page to the main stats table (MAIN_STAT_TABLE_NAME). Returned undef if faile, else 1.
  • getIDfromPage(PAGE_NAME) :

    return the id of PAGE_NAME. Be carefull with this because if you have 2 pages with same name thereturned result will random...
  • initDataBase :

     create and initialyzed the main database. Arguments are :
     
    	PAGES_LIST : a list of pages you want to manage statistics for. Pass arguments as string (ex: 'index.pl,news.pl,pub.html'). Separator is the coma (',').
    	
    	If you don't have set it before : MAIN_STAT_TABLE_NAME the main statistics table (where are record current stats). Returned undef if faile, else 1.
  • initBackupDatabase :

    create the backup database. Returned undef if faile, else 1.
  • decrMainPage(ID_PAGE) :

    decrement the page identified by ID_PAGE. Returned undef if faile, else 1.
  • incrMainPage(ID_PAGE) :

    increment the page identified by ID_PAGE. Returned undef if faile, else 1.
  • updateBackupDBschema :

    update the backup table's schema from the main table one. Returned undef if faile, else 1.
  • backupStats :

    backup statistics. Returned undef if faile, else 1.
  • generateHTMLBackupGraph :

    generate (and return) an HTML <TABLE> wich contain a graph of the specified backup is (see generateHTMLMainGraph method for explanation of arguments)
  • generateHTMLMainGraph :

     generate (and return) an HTML <TABLE> wich contain the graph of main table. Arguments are :
     
     	IMAGES_DIR : if you don't have set it before, the directory where we can find images wich we use to generate the graph.
    	
    	TABLE_NAME_FONT : opening HTML tag <FONT> wich determine the font of text inside <TD>
    	
    	TABLE_TAG : HTML tag <TABLE> you can specify special tag here
    	
    	TR_TAG : specify your <TR> tag here
    	
    	TD_TAG : specify your <TD> tag here
    	
    	TH_TAG : specify your <TH> tag here
    	
    	IMAGES_CYCLING : 0 or 1. If enable module choose one per one the different images wich are present in IMAGES_DIR. Else the module choose the first image.
    	
    	IMAGES_LIST : specify a list of images you want to use (as a string like 'img1.png,image.gif,logo.xpm' separator is a coma). (OPTIONNAL)
    	
    	IMG_TAG : specify your <IMG> tag here. Default is : <IMG SRC=__IMGSRC__ ALIGN=__IMGALIGN__ WIDTH=__IMGWIDTH__ HEIGHT=__IMGHEIGHT__>. You can use __IMGSRC__, __IMGALIGN__, __IMGWIDTH__ and __IMGHEIGHT__ as variables.
    	
    	Default values are :
    		
    		__IMGSRC__ : IMAGES_DIR/first image in directory. Accessed by IMAGES_DIR and IMAGES_LIST
    		
    		__IMGALIGN__ : CENTER. Accessed by IMG_ALIGN_TAG
    		
    		__IMGWIDTH__ : 4 * number of hits. Accessed by POINT_FOR_PIXEL
    		
    		__IMGHEIGHT__ : 9. Accessed by IMG_HEIGHT_TAG
    		
    		You can access to thoses variables by followings parameters and use them as variables in your own <IMG> tag.
    	
    	PIXELS_FOR_POINT : specify the number of pixels you want for a point in statistics. Default is 4 pixels. For example, if you have 10 hits on a page, the image wich represent this value may have 40 pixels long.

    WARNING : all *_TAG options accept a string as HTML tag but ONLY THE OPENNING ONE !! Tags are closed by the module. Moreover, they all are optionnals.

  • generateGDGraph :

    use the GD module to generate a graph (freshmeat like) of the statistics from the backup table. Returned the name of image generate (wich is stored in IMAGES_DIR)
  • reIndexBackupTable :

    re-index the id_backup column of BACKUP_TABLE_NAME. Returned undef if faile, else 1.
  • getMaxFromBackup :

    get the maximum id of BACKUP_TABLE_NAME all columns included.

Heritage

WWW::Statistics heritate from DB::DBinterface so read this module manpage to having a description of his own methods and functions.

Returned values

Alle methods returned undef if there is a problem.

SEE ALSO

DB::DBinterface

AUTHOR

DUPUIS Arnaud, <a.dupuis@infinityperl.org>

COPYRIGHT AND LICENSE

Copyright (C) 2004 by DUPUIS Arnaud

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 1020:

'=item' outside of any '=over'

Around line 1162:

You forgot a '=back' before '=head2'