What is a best way to track page visits ?

If I have pages:


www.example.com/article/view?id=1


www.example.com/article/view?id=2

and so on…

I want to track when logged in user visit some page and record user_id and article_id in some db table called "visits".

Somewhere in my application I need to have code that is going to do this job.

But where ? What is the best approach ?

Should I do it in controllers, master controller ?

Should I somehow use afterAction event ? If yes, where should I do it ?

Thanks is advance

Create custom component in common folder and call this function on beforeAction or afterAction from your controllers.