PDA

View Full Version : Addon: Simple CSV Stats AddOn


tommaso
08-29-2007, 12:20 PM
Hi,
I did the very first version of a stat addon which saves visits into a csv (comma separated values) file with the following fields:

date
visited_url
username (if any)
userwebsite (if any)
useremail (if any)
language
referrer
user_agent
remote_host
remote_addr

you can see it live (http://www.tomsights.net) on my site opening the source of a page you will see right next <head> tag:

<!-- logged: 2007-08-29 12:04:01 / Test www.noname.none noone@noname.none Opera/9.23 (Windows NT 5.1; U; it) 213.140.2.6
-->

which means that the info is logged to the logfile.
This text is replaced where the tag <csv_stats> is found in any file of your tamplate (while the same info is stored in the log file).

You can import the stats in excel and do what you want.
At the moment, the log is cleaned every time reaches 50KB.

I'll probably develop (spare time) the following feature:
- customize log file name (so that only you know where's the log)
- email the log before cleaning

If you want to help me doing this or you have any suggestion you're welcome.

the addon is here (http://www.tomsights.net/csv_stats.zip)

Hope you like it :)

bye
Tommaso

ps oh, well, the file is tab separated because the field HTTP_USER_AGENT is full of ;

tommaso
09-03-2007, 02:25 PM
Hi, my site is going to discontinue. This is the code of the addon at the time I am writing.
bye

<?php

/*
Requires Pixelpost version 1.5 or newer
Simple CSB Stats AddOn - Version 0.9
last update: 05/11/2007

Written by: Tommaso Carullo
tom|at|tomsights|dot|net
www.tomsights.net

License: http://www.gnu.org/copyleft/gpl.html

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

/************************************************** **/
/* configuration variables */
/************************************************** **/
$addon_name = "Simple CSV Stats AddOn";
$addon_version = "1.0";
$addon_description = "Creates a csv file with the stats from your site.<br />Created by <a href='http://www.tomsights.net'>Tommaso Carullo</a><br /><br />";


/***********************/
/* ADDON CODE (action) */
/***********************/

function count_visit() {
//if(!isset($_SESSION["pixelpost_admin"]) || $cfgrow['password'] != $_SESSION["pixelpost_admin"]) {
// $entry = "visit not logged this time"; // do not count site administrator
//} else {
if ((filesize('./stats.csv')>50000)||(filesize('./stats.csv')==0)) {
$flog = fopen("./stats.csv" , "w");
fwrite($flog, "PHOTOBLOG CSV LOG FILE\n");
fwrite($flog, "date\tvisited_url\tusername\tuserwebsite\tuseremai l\tlanguage\treferrer\tuser_agent\tremote_host\tre mote_addr\n");
fclose($flog);
}
if ((! eregi('/admin/',$_SERVER["REQUEST_URI"]))&&
((! eregi('slurp',$_SERVER["HTTP_USER_AGENT"]))&&
(! eregi('twiceler',$_SERVER["HTTP_USER_AGENT"]))&&
(! eregi('gigablast',$_SERVER["HTTP_USER_AGENT"]))&&
(! eregi('spider',$_SERVER["HTTP_USER_AGENT"]))&&
(! eregi('msnbot',$_SERVER["HTTP_USER_AGENT"]))&&
(! eregi('voyager',$_SERVER["HTTP_USER_AGENT"]))&&
(! eregi('emerald',$_SERVER["HTTP_USER_AGENT"]))&&
(! eregi('psbot',$_SERVER["HTTP_USER_AGENT"]))&&
(! eregi('sbider',$_SERVER["HTTP_USER_AGENT"]))
)
){
$now = gmdate("Y-m-d H:i:s",time()+(3600 * $cfgrow['timezone']));
$vinfo_name = "";
$vinfo_url = "";
$vinfo_email = "";
if(isset($_COOKIE['visitorinfo'])) list($vinfo_name,$vinfo_url,$vinfo_email) = split("%",$_COOKIE['visitorinfo']);
$entry = sprintf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", $now, $_SERVER["REQUEST_URI"], $vinfo_name,$vinfo_url,$vinfo_email, $_GET['lang'], $_SERVER['HTTP_REFERER'], $_SERVER["HTTP_USER_AGENT"], $_SERVER["REMOTE_HOST"], $_SERVER["REMOTE_ADDR"]);
$flog = fopen("./stats.csv" , "a");
fwrite($flog, $entry);
fclose($flog);
}
//}
return "<!-- logged: $entry -->";
}

$tpl = str_replace("<CSV_STATS>",count_visit(),$tpl);

$addon_description.="<a href='/stats.csv'>right click to save csv to disk</a>";

?>