Modules: [MODULE] myReferer: track your referers, search engine, webspiders and keywords

Posted by: solo71on 2005/8/10 8:30:00 19324 reads The wolfactory is proud to announce the release of myReferer 1.0.
Resized Image
This module will allow any Xoops site webmaster to record visits and datas from his referers, web spiders and search engine. It will gather any keywords used to reach his website, and will automatically display an alphabetically ordered list of word link to the most visited pages.

You can have a sample of this module on the wolFactory. You can also see the alphabetical list...

Special thanks to Marco for his inspiration about the keyword section, Marcan who has checked my code and made it compatible with php5, Philou who has checked the security side of the module and every xoopers who helped me with some code tips in the forums.



Resized Image

Extra explications

When coding this module, and after several test on various sites, I had to decisions which may not suits every users. Here are some of them:

1) Keywords selection

In the 'record.php' file, the keyword selection is running through a filter process:

// Keyword analyser //////////////////////////////////////////////////
    
$array explode(' '$query);
    foreach ( 
$array as $query ) {
    
$query strip_tags($query);

// Uncomment the following line if you have problems with special characters.
// Attention: this option may cause your site to crash if not accepted by your server!
// $query = mb_convert_encoding($query, "", "auto");

// Check keyword lenght
    
$query_lenght strlen($query);
if ( 
$query_lenght $min AND $query_lenght $max ) {
// if you want to remove puncutation except the '.'
    
$query str_replace('.''xzy'$query);
    
$query eregi_replace("[[:punct:]]"," "$query);
    
$query str_replace('xzy''.'$query);

// if you want numbers
//     $query = eregi_replace("[[:digit:]]"," ", $query);

// All charaters minuscules and remove blank spaces
    
$query strtolower($query);
    
$query trim($query);

// End Keyword analyser //////////////////////////////////////////////


Minimu and maximum keyword size is set in the head of the file.

2) Targeted page records

I got a long discussion wether we should record each and every page targeted by search engine, referers and linked to keywords with Marco. We finally decided not to record all of them, but only to link the latest page visited to the latest query/referer. The main objective of this was to keep control of the database size. Plus, having too much result would lose the webmaster in a data overweight.

3) Record operation

The 'record.php' file is activated on each and every page of your site. In the hope to limit database queries, the record functions are activated in the following cases :

a. the referers url is different from the current site and not a direct call.
b. if the referer has keywords, it is considered as a search engine, and thus record the used keywords.
c. to check wether the visitor is a bot or not, its useragent must be different from Mozilla and Opera.

Some errors may arise from this control. Please let me know about recurrent errors so I can adapt the code.