We want to add a block to our website with user information. for example how many users are currently online? how many guests are checking the website? how many pages are visited during the last day, month, year?
I know that there are some 3rd party websites that can track this information and I`ve used them before. But, I prefer not to add their scripts to our website.
Does OJS keep this data so that I can extract and use it without the need to another service provider?
I am using OJS 2.4.6
You can get an approximate count of “current” users from the
sessions table in the database. You would probably want to count
session_id, filtering on
user_id for anonymous vs. logged in users, and
last_used for whether or not to consider the session “current”, and
user_agent to filter out bots.
OJS does not keep tracking information by “page”, but you can find article based usage information in the
metrics table. This table is documented in the OJS Statistics Concept page on the wiki.
Thank you @ctgraham,
Is there a tutorial about the definition of table columns and how they are created/updated?
for example, I couldn’t figure out how the
last_used columns in the
sessions table work.
A session is created on the first encounter of a user with the website. The time of creation is stored in the
sessions.created field as a unix datestamp.
A session is updated throughout the user’s interaction with the website. As session activity happens, the
sessions.last_used value will be updated with the unix datestamp.
Session are abandoned when the user’s activity lapses for more than the session_lifetime in config.inc.php or the garbage collection cycle in Session.inc.php.
You’ll probably want to choose an arbitrary duration to consider “active” and look at
sessions.last_used in your filter.
Thanks for the reply.
I created the plugin and shared it here.
I set current_time - 60 seconds as the active or current user.
I was amazed on how much coding is done to develop the Statistics API! but why isn’t all this coding used to create user friendly and nice reports (instead of csv and xml files)?
I am working on a creating a pivot table/chart report generator from the csv file and will share the template here. may be I could even connect it directly to OJS.