Hi, i am in the middle of developing a website, and i would like to add a function to my site whereby a member can see how many times their profile page has been viewed, similar to the way YouTube displays the amount of hits a video has.
I have a few questions which i hope you can help me with:
A - who does the YouTube counter work OR what is the best way to build these counters... are they (1) - IP based, (2) - Cookie based OR (3) - another method
B - does the page make a database update each time a unique user lands on a video page
C - how often is the number updated... for instance, if i view a video on youtube on several different devices all connected to different networks, the number does not update immediately... so how does it work
Thanks in advance to anyone who can offer any help here
Looks like Erik looked into this in-depth. The video counter looks like it updates by a user action of clicking a video and play for at somewhere around 5 seconds. It most likely updates a database so stateless web issues are taking out of the mix. The video counter interacts with the database...maybe?
I know, not much to go on, but it may help a little.
Hi, thanks for your reply... i understand what you are saying, apologies for my poor analogy but i only need to update the hits when a page is viewed, however i don't think it is right to just update $profile_views by +1 every time a users profile page is loaded as the hits will be inaccurate... as i don't want the hits to be +50 if a user simply refreshes a users profile by pressing refresh constantly... what approach would you consider then, thanks again for your reply...
Probably the same reason why YouTube waits a period of time before registering the view, and also after a small number of hits they verify the I.P. and sniff the user agent and who knows what else? But they do this to circumvent the same thing you are worried about. You need to decide what your will allow for a view to be triggered. If for instance you wait until 5 minutes of a video is played then someone trying to get 50 would have to do it over a period of 250 minutes (not likely). You also might want to find the rate at which it happens to determine if a user or an automatic agent is being used. Investigating multi I.P.'s hitting the same file to investigate where they are originating from; if for example they are all registered to one proxy you don't allow any view to count. You will have to use your own judgment of how far you go with criteria for allowed view counts.
I think the final solution, and the amount of work you put into achieving it may well depend upon what you stand to lose by having potentially skewed figures.
"I want to know in my heart that the hit rate is accurate."
-- well, just look at the figures over time and you'll see the odd spike, but it probably wont make much difference to the overall trend. (the figures are going up/down)
"I want to be sure my boss cannot skew the figures when he tests it."
-- I dont want to lose face, but then again I can argue that I can fix this, but leave it to him to decide if its worth the time/effort
"I am paying money for each hit."
-- then yes, spend the time/effort
Thanks for the replies all... i remember Bebo had a profile counter too... and i figured out, if you landed on a profile page, that would constitute as +1 hit... however if you refreshed the profile page, nothing would happen, however if you clicked out into some other page on the site and then went back into the profile page, another +1 would count... i think this would be ideal, but not sure how to go about it... and the figures took a few hours to update also on Bebo...