Is there a plugin that exists that does this? If not, could i theoretically create a mysql database that tracks this kind of information?
For example, say I have a table post_views with the username as the primary key, and everytime a user comes, i check if there exists a value for the column with the post id in that table.
If it does, then do something… if not, then, create the column and assign a value of 1 or something.
Would something like this be feasible? Sorry, I am a mysql noob.
Thanks!
Well, it’s feasable, yes.
You could:
For logged in users: create a relationship table, say users_posts
And at each post view insert into this table the user id and the post id (and if you want you could add other info, such as the date when the post was read). A query to this table will tell you all the pages opened by the user, or conversely you can check if a page was seen or not by that user. From what you said this is a more feasable table schema than what you had in mind;
For non-logged users: without having an user id at your disposal you could use cookies: write in a cookie the user information (IP, UserAgent, whatever) and the post id; as long as the cookie isn’t cleared (or expires) you still would know what a user has seen or not. For added sweetness: as soon as a user logs in you can transform this cookie-based infos into the method in point 2).
Well, on a second thought, cookies are not necessary, you can use a database here too, but the table will not store the user id but the other infos (you could use the same table with added columns, or a new one specifically for non-logged users. I’d go for the latter)
Keep in mind, though, that IP, user Agents and such other infos aren’t reliable, and can lead to problems – the first can be shared by different users, the second can be easily spoofed. The best course of action would be to ignore this point 3) and always track only logged-in users, that way you won’t incur into problems.