Part of the EllisLab Network
x
 
Create New Page
 View Previous Changes    ( Last updated by George Petsagourakis )

Simple Stats

Category:Plugin -> Community | Category:Plugin -> Statistics

This is a plugin for recording some simple stats about page views. I autoload the simplestats plugin below and call

log_site(1); 

from the controllers class constructor.

<?php
function log_site($zone)
{
    
//stuff that uses CI
    
$CI =& get_instance();
    
$CI->load->library('user_agent');
    if(
$CI->agent->is_robot())
    
{
        
return FALSE;
    
}   
    
else  
    
{
    
        
if ($CI->agent->is_browser())
        
{
            $agent 
$CI->agent->browser().' '.$CI->agent->version();
        
}
        
elseif ($CI->agent->is_mobile())
        
{
            $agent 
$CI->agent->mobile();
        
}
        
else
        
{
            $agent 
'Unidentified User Agent';
        
}

        $browser 
$CI->agent->browser();     
        
$browser_version $CI->agent->version();
        
$os $CI->agent->platform();
        

        
//$zone (frontend / admin / members)
        
$general $CI->uri->segment);        //products
        
$specific $CI->uri->segment);        //products/shoes
        
$item $CI->uri->segment);        //products/view_shoe/34
        
$session $CI->db_session->userdata'session_id' );
        
$ip $CI->db_session->userdata'ip_address' );
        
$user_id getUserProperty'id' );      //if user is logged in
        
$user_agent $CI->db_session->userdata'user_agent' );
        
        
//use a model for inserting data
        
$CI->load->model('Logmodel');
        
$CI->Logmodel->log_site($zone$general$specific$item$session$ip$user_id$user_agent$browser$browser_version$os$agent);
    
}

?>