Stats - Numbers don't compute

I logged into my site today, and was just looking at the Page View Statistics that automatically show up on my dashboard. Check them out:


The numbers just don’t seem to add up. The Month number 1977, and today only being 863, yesterday’s numbers would have to be over 1000, but they are less than 800. This week’s numbers may be more on par, but the month is off! I’m not sure where these stats come from, or how accurate they are. I do like them, but now I’m thinking they are unreliable. It is April 2, so this is not a fools joke, unless Grav joked me yesterday. :smiley: Is this a bug?


There is probably a logical explication to this, because they are consistently off. Clearly I’m missing something.

You’re not the first complaining about it… Errors in dashboard statistics · Issue #2440 · getgrav/grav-plugin-admin · GitHub

The data is collected in files /logs/popularity/daily.json and /logs/popularity/montly.json. For example:

// daily.json
{
    "27-03-2025":1,
    "28-03-2025":2,
    "29-03-2025":3
    "30-03-2025":4,
    "31-03-2025":5,
    "01-04-2025":6,
    "02-04-2025":7
}

// montly.json
{"04-2025":13}

The weekly statistics is calculated by adding the last 7 days from daily.json.
The result should then be:

Let’s have a look at your data. Would you mind sharing from the log files, the month April from montly.json and the last 7 days from daily.json.

Well, that is kind of neat.

//daily.json
{"01-04-2025":552,
"02-04-2025":1096}
//monthly.json
{"03-2025":25208,
"04-2025":2212}

@shane, And where are the remaining 5 days making up “the last 7 days” in daily.json?

They are not in the file. :thinking:

@shane, Smells fishy…

  • There is a value for the previous month, but you have no records for days in March.
    By default, Grav keeps the last 30 days (or more exact: records) in daily.json and purges the rest.
    And Grav keeps the last 12 records for montly.json
  • The value for April, cannot be larger then the sum of hits for 01/04 + 02/04

This is why I was scratching my head when I read the stats. I really don’t know, I had no idea even where to find the data before you told me. :smiley: I just used
cat daily.json
and copy and pasted what was there. Same for monthly.
I did move all the pages from my test site over in March, but only moved the user/pages stuff. Perhaps that messed with the stats? I’m not sure how they are tied in. I think it was early March though…

@shane, I’m pretty sure you have been visiting your site in March, so daily.json and montly.json should have data for that period.

With the info given so far, I cannot draw any conclusion that explains the issue.

Suggestion:

  • Delete the files and see what happens.

So, I wanted to see from my test/staging site it’s stats.

cat daily.json 
{"03-03-2025":119,"04-03-2025":149,"05-03-2025":357,"06-03-2025":763,"07-03-2025":972,"08-03-2025":695,"09-03-2025":9,"10-03-2025":93,"11-03-2025":165,"13-03-2025":3592,"14-03-2025":5317,"15-03-2025":436,"16-03-2025":567,"17-03-2025":488,"18-03-2025":628,"19-03-2025":462,"20-03-2025":315,"21-03-2025":217,"22-03-2025":234,"23-03-2025":210,"24-03-2025":158,"25-03-2025":101,"26-03-2025":84,"27-03-2025":63,"28-03-2025":42,"29-03-2025":36,"30-03-2025":44,"31-03-2025":52,"01-04-2025":63,"02-04-2025":55}
cat monthly.json 
{"03-2025":14135,"04-2025":118

I had to do some serious cleaning of my site, because it had a lot of old outdated plugins. I did a clean install of my site in a subdomain and moved all the pages over. All worked like a charm. I cleaned it all up, and then moved it back, but I don’t remember how I did all that. Even if I did the stats would have been goofy in early March, but not now. It was a couple of weeks ago or more that I did all that. I checked my logs, and I have no errors since March 7th.

So, I came back after a few days, and only two days are kept in the log… so clearly there is a problem besides that of addition. I moved the logs to daily.json.old and monthly.json.old and they immediately repopulated. If that doesn’t work, there is clearly a problem, what should be my next fix? I have no errors in the log. Here are the old stat logs that I moved:

cat monthly.json.old 
{"04-2025":1816}
cat daily.json.old
{"03-04-2025":1347,"04-04-2025":467}

Can I re-install a plugin? Is this a core feature? My staging site doesn’t have this issue. Thank you for your help.

This person had the same issue years ago:

@shane,

I moved the logs to daily.json.old and monthly.json.old and they immediately repopulated.

Are you using fastCGI? When Grav is kept in memory, the arrays created from the popularity files will be kept in memory.

if (!$this->daily_data) {
    $this->daily_data = $this->getData($this->daily_file);
}

On each request, the existing array in memory will be updated with the new hit and written again to disk. Hence they are immediately repopulated when you move the popularity files.

If Grav is not kept in memory, the popularity files will be read from disk on each request and written back to disk.

Disclaimer: I know nothing about the internals of webservers, but this is how I guess it works…

To comment further on the issue:
I’ve gone over the code again and again, but I fail to see how Grav can be the cause of truncated popularity files.

Could there be an interference with a plugin?

When I say, “They immediately repopulated” I should clarify, they didn’t continue with the numbers, the files were auto-created immediately, but the stats were all restarted. I don’t know even how to tell if I have fastCGI. I’m on shared hosting.

On a side note, I did install the Page Stats plugin. I did this just for comparative purposes.

I was letting this work for a while, but according to my records, I reset the daily.json file on April 4th, and only have 7 days of records. So that is odd. Not a super big deal, just odd.

ls -lsh
total 88K
8.0K -rw-r--r-- 1 username username  125 Apr 16 09:25 daily.json
8.0K -rw-r--r-- 1 username username   36 Apr  4 09:29 daily.json.old
8.0K -rw-r--r-- 1 username username   17 Apr 16 09:25 monthly.json
8.0K -rw-r--r-- 1 username username   16 Apr  4 09:29 monthly.json.old
 40K -rw-r--r-- 1 username username  33K Apr 16 09:25 totals.json
8.0K -rw-r--r-- 1 username username 1.1K Apr 16 09:25 visitors.json
cat daily.json
{
"10-04-2025":311,
"11-04-2025":1063,
"12-04-2025":2822,
"13-04-2025":2452,
"14-04-2025":7716,
"15-04-2025":3196,
"16-04-2025":537}

 cat monthly.json
{"04-2025":26347}

@shane,

What’s the value of popularity.history.daily in the following files (if existing):

  • user/config/plugins/admin.yaml
  • user/env/yourdomain/config/plugins/admin.yaml
  • user/env/localhost/config/plugins/admin.yaml
  • user/yourdomain/config/plugins/admin.yaml
  • user/localhost/config/plugins/admin.yaml

So here is what I have in the admin.yaml

popularity:
  enabled: true
  ignore:
    - '/test*'
    - /modular
  history:
    daily: '30'
    monthly: '12'
    visitors: '20'

same document, different section:

dashboard:
  days_of_stats: 7

Also, oddly, I have a admin.yaml file in these directories:

/user/plugins/admin/
/user/config/plugins/

I have a folder: /user/domainname/config/plugins but there isn’t an admin.yaml file there.

Also, oddly, I have a admin.yaml file in these directories:

These are as expected…

/user/plugins/admin/   <=== Comes with the Admin plugin as default values
/user/config/plugins/  <=== Where Admin saves its own config, 
                            unless running in some domain
1 Like