This is a self contained module that enables you to track and display 'view counter' on content types in your Yii based website
'import' => array( //... // Views counter module 'application.modules.PcViewsCounter.*', 'application.modules.PcViewsCounter.models.*', 'application.modules.PcViewsCounter.controllers.*', 'application.modules.PcViewsCounter.components.*', 'application.modules.PcViewsCounter.extensions.ViewsCountWidget.*', //... ), //... 'modules' => array( //... 'contentViewsCounter' => array( 'class' => 'application.modules.PcViewsCounter.PcViewsCounterModule', ), //... ),
$this->_clientIpAddress = Yii::app()->geoip->getRemoteIpAddress();
$this->widget("ViewsCountWidget", array('modelId' => $model->id, 'modelClassName' => get_class($model)));
if impression-cookie exists (this is for guest) do nothing. else if authenticated search PageViewBookeeping record for this user (based on user_id, PageViewsStat->id (which is an FK in the former class/table)) if not found search for PageViewBookeeping record based on ip address. if found in either of the 2 checks above add this information into the impression cookie. return else add impression record for this user. add this information into the impression cookie. else (this is guest user) add cookie for this guest user unique impression search for PageViewBookeeping record based on ip address. if NOT found add impression record for guest (record his ip address) else return existing counter add +1 to unique stats counter for this model name + id.