Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing/Tracking user activity on a website [closed]

I was wondering what would be the best way to go about storing/tracking user activity on a website. I am thinking of user activity along the lines of which webpage a user visited,how many times has she visited,when(i.e timestamp) of his/her vists.

I am currently thinking of creating multiple tables in my database for each webpage on my website, each of which would track an aspect of user activity on my site. E.g 1 table containing timestamp and userid of each user who visited that webpage, another table storing their actions done on the webpage(e.g liked something)

Would this be a good way of tracking user activity or are there other, better methods of doing so?

PS: Im using PHP and MYSQL for the website, and am doing this as a means of improving my coding so i won't be using google analytics or anything like it.

like image 703
Kenneth .J Avatar asked Oct 15 '13 15:10

Kenneth .J


1 Answers

Yep, store everything in a database. Have a table for user visits, one for user interactions etc.

To start with have a table page_visits that contains an ID for the user (This is your first problem to solve - how to uniquely identify a visitor. Identify them using their IP and or User agent? Create a cookie that refers to a unique ID? There are different methods depending on your goal - none are 100% fool-proof) and the page ID or URL they visited along with a timestamp.

Add a table to track interactions. How you capture the event is up to you, do you fire an AJAX call using Javascript or jQuery to log an event like a click? This table could contain fields such as user_id, timestamp, action_performed, source_page_id.

The way you decide to implement is entirely up to you but a database would probably be the way to go.

like image 141
Jonathon Avatar answered Oct 18 '22 18:10

Jonathon