Jump to content

Performance Question - Visitor Counter with dates..


mr-fan
 Share

Recommended Posts

What i wanna achive is a simple counter like that count up on visit (this is no problem) AND save the specific date (year/month/day) of the count...

in the end i will be able to get visits per day/per month/per year in a nice and dirty graph.

Just to have a way better simple counter system.

Should i only go with a complex setup of pages like this:

--stats (home template for pageviews)
----2018 (year)
------08 (month)
---------29 ->page_views   (integers on every day template)
---------30 ->page_views

Or just simple use:

--stats (home template for pageviews)
---->count (template) that holds simple field page_views and a date field

or could a fieldtype like tables (one table field for every month/year or so) be also a solution?

Or a own SQL table special for this and use it in a module? I don't have any experience on this topic...

What i have in mind of performance sideeffects on such a thing?

Or is there a solution that works with PW?

I wanna go the hard way and implement something like this:

http://stats.simplepublisher.com/

only directly within PW and use the API to get the data...maybe create a simple module from it later i don't know if i  could set it up right from the start ?

this is the reason for my questions on more experienced devs

Kind regards mr-fan

 

Link to comment
Share on other sites

Howdy @mr-fan!

This is just my $.02.

While PW can certainly handle such a simple task, to me, it is overkill. And I don't want 100K+ pages in my tree. In one project, I use a simple mysql table to store the unix timestamp as a simple counter. In another project, I use PW's features to track more complex data for affiliates. Regardless of the method you use, google analytics gives you the visitor data you used to get with dedicated visitor tracking scripts.

Even if you store visitor IP with the timestamp, you can use php's dns lookup to gather information on a desired ip address, although I don't recommend using that function on every ip entry.

I haven't noticed any performance degradation with either method. But I'm looking at only a few hundred to a few thousands hit per day on those domains. Your milage may vary. ?

Hope this helps.

  • Like 1
Link to comment
Share on other sites

That is the Point IP saving IP adresses is very bad....since may in europe....very bad...bad bad ? even a whois question is no more possible...so the rise of simple php hit counters (that was a great thing 10 years past) is on the way...

A other more complex workaround could be to setup a crownjob to read the apache logs and get needed data from there?

Link to comment
Share on other sites

You don't need to track an IP unless you are requiring information unique to a user. Just the timestamp in a mysql table is sufficient to give you a hit counter by date. There are quite a few apache log analyzers out there, but I haven't used them since google provides the information for me. I prefer to not make things more complicated than need be.

  • Like 1
Link to comment
Share on other sites

There‘ll certainly be a shift in what tools like google analytics need to be able to do in terms of preserving user privacy (and they already do), but I don‘t see anyone wanting to seriously build page counters in php again. Matomo (piwik) already exists and there are even new alternatives like fathom, which are already enough for simple needs.

  • Like 3
Link to comment
Share on other sites

I would probably do something like this:

Have a "stats" page somewhere (hidden), with one big raw textarea field.

Each visit would add one line to that field:

1234,guest,username,1535646198

= page-id,user-role,username,unix-timestamp

You could get fancy and install a geo-IP-lookup PHP library and add lat/long infos as well.

Instead of using a comma-separated list for each item, you could save it as JSON. But I guess this would mean a slight performance hint on a bigger site (the bigger it gets, the more time it takes to transform JSON into an PHP array, add one item, and use json_encode again).

I've used a similar approach, when I played around with chatbots and certain API calls back and forth.

It would be quite easy to output some sort of stats / infographics from such raw data. And of course easy to export it to Excel or somesuch...

The only thing I would make sure and investigate some time before going that route: Check if there are some size-restrictions, i.e. how much data can actually be stored in a PW textarea field? Even this could be easily solved: Create a new stats-field for each year/month...

  • Like 1
Link to comment
Share on other sites

I had the need to do something similar before. 

We wanted to know how far users got into a multi-step order process, and also what values they were putting in during each step and the referring pages. 

I found inserting a record on every page load worked well and was fast. 

Don't increment anything or it is slow, just insert new records and use a weekly or monthly cron to process the data to keep the table size manageable. 

Add in an optimize command also to clear db overhead after rows are deleted. 

I insert the session_id, timestamp, ip address, etc, but none of the data is public.  Used for troubleshooting.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...