If I have a table with 2000 ids. And for every id I am generating web page ( number of ids will increase dynamically ). I would like to track how many users visits each of those pages has. How would you do this with yii2 ? Is there any extension for this, or a simple way ? What would be necessary steps and best practices to achieve this ?
Can multiple visit from one user increase the hit counter multiple times or only one? If only one - are those visitors anonymous or registered users? With registered users it’s easy - just store each visit somewhere (i.e. db). Guests are more difficult - you can track them by IP or save cookie id - this is general idea.
For simple db counter increase check updateCounters method.
If I use google analytics, how can I know the page visits for each page ? For example if I have two pages: www.example.com/post/1 and www.example.com/post/2, how can I grab, display and maybe store somewhere how many visits each page has ?
In case I would like to count page visits by guests, I guess that I can use the same mechanism ? Maybe I would have separate field that will store counted visits for guests, and some other way to count page readings for each member. I mean, if I want to display count of page red by guests and for each member of web site separetely. What would be the best tactic for this ?
Analytics can give you per-page statistics - that’s the whole point of it. You can even acces this information via Analytics API and display it on your site or admin backend (it’s a Ruby example on the linked page but it can be ported to PHP easily).
EDIT: Just make sure that every page has exactly one valid URL. <link rel=“canonical”> can’t help when working with Analytics.