Skip to content
Derek Jones edited this page Jul 5, 2012 · 6 revisions

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 ```php log_site(1);


[CODE]<?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( 1 );        //products
        $specific = $CI->uri->segment( 2 );        //products/shoes
        $item = $CI->uri->segment( 3 );        //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);
    }
} 
?>[/CODE]
Clone this wiki locally