Tracking user cakephp 2.x

Someone , i need help to tracking user activity in cakephp 2.x
I want to tracking ip , page view , download counter etc ,
Please help me

Best regards,

Muhammad Robin

In the past, I’ve just created a dedicated model for this. For example, in the login method of Controller/UsersController.php, I have a line to handle the logging…

    $this->_loginLog('login_form');

Which just calls a protected method.

protected function _loginLog($type) {
  // Update the User's lastlogin
  $this->User->id = $this->Auth->user('id');
  $this->User->saveField('lastlogin',date("Y-m-d H:i:s"));
  // Add an entry to the log
  $this->SystemLog->log($type,'Login from ' . $this->SystemLog->findHost(), $this->Auth->user('id'));
}

And here’s a snippet form my Model/SystemLog.php which was a generic model to handle multiple kinds of logging throughout the system (including user logins).

function log($code,$message,$uid=0){
  $this->set(array(
  'code' => $code,
  'message' => $message,
  'user_id' => $uid,
  'ip' => $this->findIp() ));
   $this->save();
  }

Not saying this is the best approach, but it worked for me. I vaguely remember seeing a plugin at one point that might have handled this, but it would probably be hard to find one now that’s still supports 2.x.

Thanks , I will try it

do you implement it? how you do it?