![]() |
Recording page views - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Recording page views (/showthread.php?tid=19499) Pages:
1
2
|
Recording page views - El Forum - 06-09-2009 [eluser]KeyStroke[/eluser] Hi, I was wondering if anyone here dealt with recording page views in CodeIgniter before. What's the best way to record them accurately? and most importantly, how did you implement it in CodeIgniter? Your help is much appreciated Recording page views - El Forum - 06-09-2009 [eluser]TheFuzzy0ne[/eluser] I've implemented a similar system into my forum. Each view simply increments a counter, but if I wanted some serious statistics, I'd log more data, and probably into a file. What kind of information are you hoping to store and retrieve? Recording page views - El Forum - 06-09-2009 [eluser]KeyStroke[/eluser] Just how many people viewed the page basically. I just don't want refreshing the page (or deleting the cookies) to increase the view count. Recording page views - El Forum - 06-09-2009 [eluser]jedd[/eluser] [quote author="KeyStroke" date="1244595084"]Just how many people viewed the page basically. I just don't want refreshing the page (or deleting the cookies) to increase the view count.[/quote] Well, you're probably going to need a table that contains IP at least. If the same IP hits the page a day apart, is that two page views? An hour apart? A minute apart? If the answer to those three questions is not the same, then you'll need some logic around the logging based on your allowable time deltas, and obviously retain a datetime field. If you get two hits from the same IP address, but with different browser details, does that count as one or two hits? You might find this if a user has two browsers, or if they're behind a NAT or proxy. The latter case might count for several tens of thousands of potential unique users. You'd need to record the browser type too. Recording page views - El Forum - 06-09-2009 [eluser]KeyStroke[/eluser] Thanks jedd. I think a hit a day from the same user would be acceptable. I'm just not sure what kind of code logic I need to use to calculate accurate hits. As far as I know, there are ISP's that assign a different IP's for multiple requests from the same users because of their proxies (correct me if I'm wrong). Recording page views - El Forum - 06-09-2009 [eluser]Dam1an[/eluser] Is there any particular reason you need to implement this yourself instead of using something like Google analytics, which is very compreensive, and takes care of all these little issues Or do you need it to be integrated somehow Recording page views - El Forum - 06-09-2009 [eluser]jedd[/eluser] It's all pretty stateless, so yes, anything is possible. I wouldn't imagine this would skew your stats hugely, but if you want to be as accurate as possible I guess you have to cater for it. You'll have to retain cookies, then. And cope with users that disable cookies on principle (people like me, for instance). You'll have to come up with an algorithm of what makes you think one user is different from another, as far as your web server can tell. Your logic for your one-day-apart assessment will be interesting - if you have a cookie, then it's easy - you can store a hash in there and check against it in your logging table. Absent a cookie it becomes more of a challenge - you'd have to do a time delta, if you've established the same IP & browser pairing already existed for that particular page. So far I see you need something like this: Code: logging ( Recording page views - El Forum - 06-10-2009 [eluser]KeyStroke[/eluser] I'm sorry, but I'm afraid I haven't explained my question clearly. What I meant by recording page views is recording views for an item. You know, like YouTube does - you want to show people how many times this item has been viewed. I hope this clears things up. ![]() Recording page views - El Forum - 06-10-2009 [eluser]jedd[/eluser] That's what I thought we were talking about. If you are happy to surrender accuracy, just have a table with the page identifier, and a count, and every time the page is about to be called by your controller, make a call to a function that updates the count for that particular page. As you want more accuracy, I see the complexity increasing non-linearly. Recording page views - El Forum - 06-10-2009 [eluser]Dam1an[/eluser] I would also recommend doing as much of this as possible in a post system hook (especially if you take the complicated route) as it doesn't increase the render time for the end user, as this will be executed after you've sent the page |