Membership Plugin - Page views counter

By zip222 - November 12, 2014

I am looking for a way to keep track of how many pages each registered member visits. What I am looking to do is that once a user has logged in, every time they visit a page, I want a counter in their record to increase by one. I don't need to know which pages they are looking at, only the number of pages - as a way to gauge activity level. Possible? Easy or difficult? How? Thanks!

By claire - November 12, 2014

Hey there - this is actually relatively simple. All you should need to do is create the field in the member record section - page visits, let's say, and give it a default value of 0 - and then add a piece of code to load on every page that you want to track that detects the $CURRENT_USER['num'] and increments the page visits count if it exists.

It'd look something like this:

if(isset($CURRENT_USER['num'])) {
    mysql_update('members', $CURRENT_USER['num'], null, array('page_visits' => $CURRENT_USER['page_visits']+1));
}

This assumes that your members table is called 'members', of course.

Does that help? You would also probably want to do some data analysis on the page visits info later, but that would require more custom code. This will just record the visits so you can see the count when you look at an individual user.

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/