Reputation: 67
I'm going to do my own Web Analytic App since I can't build any of the existing ones on my server. Note that I'm using NodeJS with Express and a Postgres Database
So I decided to log every "views" on my website. (The table is not created yet, but will store a visitorID based on the headers and of course the datetime of the visit)
And I heard that a new "visit" after 30 minutes of inactivity from the user. I'll therefore assign a new visit ID each time a user arrives on the site and their last “views” were recorded more than 30 minutes ago.
Now I wonder what's the optimized way to know that 30 minutes or more have elapsed since last "views" ? Is there another better way to count visits ?
The most obvious way is to use the database to fetch le last view from this user, but this would but this would mean that each “view” on my website would automatically trigger 2 queries in my database (SELECT for the last view, and INSERT for the current one).
Are there more optimized solutions ? Less costly for the database ? Maybe using cookies or other solutions ?
I've heard of a batch insertion system, like inserting a lot views every minutes instead of each request. I guess this can be interesting
Upvotes: 0
Views: 29