Welcome Guest, Not a member yet? Register   Sign In
Recording page views
#11

[eluser]KeyStroke[/eluser]
jedd:
So you mean I log the views in a separate table, then do a MySQL join when the user requests the page? wouldn't this impact performance?

And by the way, I'm doing it per item, not per section. (I have thousands of items)

Dam1an:
How would you achieve that in CI? I would appreciate it if you could point me into the right direction.
#12

[eluser]wiredesignz[/eluser]
[quote author="Dam1an" date="1244648081"]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[/quote]

Nonsense, there is NO output sent to the browser until the entire PHP script (hooks too) finishes. (unless you have an output buffer which is flushed explicitly. Even then it depends on other factors.)

@Damian, trying to be helpful while not knowing the correct information just adds to the confusion around here.
#13

[eluser]jedd[/eluser]
[quote author="KeyStroke" date="1244920223"]jedd:
So you mean I log the views in a separate table[/quote]

Where and how you log the views depends to some extent on the level of complexity (read accuracy) you wish your stats to have. See my discussion above. Until you actually say out loud what you're happy with, it's tricky (read impossible) to give more accurate advice.

In general terms, though, and given what you've said here about wanting to log items not sections (I don't know how that translates to your pages or views - you haven't said yet) then so long as you have some way of uniquely identifying items, then yes, it seems that having a table with an item_id and the other identifying information to constitute a 'unique-enough view' worth logging, is where you are heading.

Quote:, then do a MySQL join when the user requests the page?

You could do a join, but I'd probably just do a separate method in my model that returns the number of views of a given item.

Quote:wouldn't this impact performance?

Yes, absolutely definitely. How could it not?

OTOH it would probably be trivial. Collecting the information will probably be more expensive, as that's a write operation against a table with thousands of items combined with who-knows-how-many page views - whereas a simple count() on an indexed column is probably pretty cheap.

In any case you're in luck - because it's totally free to run up a couple of example database calls and wrap some PHP around it to get an idea of how long things take. Especially if you use the [url="http://ellislab.com/codeigniter/user-guide/general/profiling.html"]CI Profiler Class[/url]

To intercept the question you threw at Dam1an .. on how to do this in CI. As above, I'd have a method that grabbed the number of hits for a given item. I'd have another method that took parameters (item , ip , browser type , datetime) and that would determine whether to update the logging table or not - probably returning true/false to indicate whether an update had occurred but otherwise quite silent. My logic for identifying if the log was updated would be contained wholly within that private method in my model. Where each of those model methods gets called is entirely up to your controller, as usual.




Theme © iAndrew 2016 - Forum software by © MyBB