Updating Ad Counter Via Piwik After Render

Hi there,

Scenario: I counting visit for each ad using Piwik Analytics. Know i want after each ad view update the hint field in ad table. I have the following code:

in Controller:

 public function actionView($catId,$id)


        $this->layout = 'index';


            '(id=:id and category_id=:catId) and (status=:verified or status=:active)',array(

            ':id'=>(int)$id, ':catId'=>(int)$catId, ':verified'=>Advert::Verified, ':active'=>Advert::Active,





            throw new CHttpException(404,Yii::t('application','The requested page does not exist.'));



    protected function afterAction($action)


        if(Yii::app()->controller->action->id == 'view')






In afterAction the updateHint() is a static method in Advert model as follow:

	public static function updateHint($ad_id)


        $url ="http://localhost/piwik/index.php?";

        $url .= "module=API&method=Actions.getPageTitle";

        $url .= "&pageName=$ad_id";

        $url .= "&idSite=1&period=day&date=today&format=php";

        $url .= "&token_auth=c0e024d9200b5705bc4804722636378a";

        $ch = curl_init($url);

        curl_setopt($ch, CURLOPT_HEADER, 0);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $ad = unserialize(curl_exec($ch));


        $hints = 0;

        $visits = 0;

        $uniq_visitors = 0;

        if(!empty($ad)) {

            $hints = $ad[0]['nb_hits'];

            $visits = $ad[0]['nb_visits'];



        $model = Advert::model()->findByPk($ad_id);




adView also is as fllow:

<script type="text/javascript">


	_paq.push(['setDocumentTitle', "<?php echo $model->id ?>"]);




<div class="ad_view">

	<?php if((int)$model->type===Advert::Photo_Ad){ ?>

	<div class="row image">

    	<?php echo CHtml::image(



        	'id'=>'currentImage', 'height'=>150,'width'=>180,



	<?php } ?>

	<div class="row">

    	<?php echo CHtml::activeLabel($model,'title'); ?>

    	<?php echo CHtml::tag('p',array(),$model->title); ?>


	<div class="row">

		<?php if(!empty($model->description)){ ?>

        	<?php echo CHtml::activeLabel($model,'description'); ?>

			<div class='description'>

				<?php echo $model->description;?>


    	<?php } ?>


	<div class="row">

    	<?php if(!is_null($model->user->name)){

    	echo CHtml::Label(Yii::t('form','Name'),'');

    	echo CHtml::tag('p',array(),$model->user->name);



	<div class="row">

    	<?php if(!is_null($model->user->surname)){

    	echo CHtml::Label(Yii::t('form','Surname'),'');

    	echo CHtml::tag('p',array(),$model->user->surname);



	<div class="row">

    	<?php if(!is_null($model->user->telephone)){

    	echo CHtml::Label(Yii::t('form','Telephone'),'');

    	echo CHtml::tag('p',array(),$model->user->telephone);



	<div class="row">

    	<?php if(!is_null($model->user->mobile)){

    	echo CHtml::Label(Yii::t('form','Mobile'),'');

    	echo CHtml::tag('p',array(),$model->user->mobile);



	<div class="row">

    	<?php if(!is_null($model->user->email)){

        	echo CHtml::Label(Yii::t('form','Email'),'');

        	echo CHtml::tag('p',array(),$model->user->email);



	<div class="row">

    	<?php if(!is_null($model->user->www)){

        	echo CHtml::Label(Yii::t('form','www'),'');

        	echo CHtml::tag('p',array(),$model->user->www);






	<?php echo CHtml::link(Yii::t('form','Back'),array('/')) ?>


Problem is updateHint method always is rear one. for example if in Piwik cpanel pageview was 25, updateHint return 24.

Note that if updateHint be run once again after ending ad view in other place, updateHint returns right report(returns 25).

In my opinion problem is updateHint be run before ad view be completed. In your opinion afterRender is a right place for putting updateHint method?

excuse me if description is not much clean.

Thanks friends

In fact i want execute the updateHint($ad_id) after the CController->processOutput.

How can i execute a function after CController->processOutput?