@MrBenGriffin opened this Issue on June 29th 2021

Report date to load by default: Previous 30 days (not including today)

vs.

(create/schedule a report) Report Period: month.

This is most significant when using an email report which uses post hoc / manual log insertions.

@diosmosis commented on June 29th 2021 Member

Hi @MrBenGriffin, can you provide more details on the issue you're having? What is the expected vs existing behavior? In what context are the default values ignored? How would I reproduce this issue?

@MrBenGriffin commented on June 30th 2021

When using 'Create and Schedule a report' (from Personal:Email Reports) the options available to report editing is given as "Report Period" (day/week/month/year)

The additional text says:
"The period of data covered by this report. By default this is the same as the email schedule, so if the report is sent weekly, it will contain information regarding the last week.

You can change this, however, if you want to see different information and still retain the email schedule. For example, if the email schedule is weekly, and the report period is 'day', you will get information for the last day, every week."

Meanwhile, on Personal:Settings. report dates to load by default are:

  • Yesterday
  • Previous 7 days (not including today)
  • Previous 30 days (not including today)
  • Last 7 days (including today)
  • Last 30 days (including today)
  • Current Week
  • Current Month
  • Current Year

When using import scripts (eg, import_logs.py cf. https://github.com/matomo-org/matomo-log-analytics) as a means of analysing the logs, this is normally done once per day using a cron (docs suggest 1 minute past midnight), needless to say, 'today' is empty of logs until one minute after midnight of the following day.

So, (for the purpose of using import_logs etc) the current email reports always have today as empty, and are always a day forward in time, as logs are imported in lieu.

Fixes
We manually edited / monkey-patch the matomo source code in order to work-around the problem above, such that the email reports the previous calendar week, the previous calendar month, the previous year to month and the previous calendar quarter (replacing the daily).

<?php
        /* About line 351 of plugins/ScheduledReports/API.php */
        /* MONKEYPATCH for getting previous dates in place. ((add use \DateTime as well!)) */
        $offsets=['yesterday', '-2 weeks Monday','first day of yesterday -1 months','first day of yesterday -3 months', 'first day of this month -1 year'];
        $ts=[]; $lookups=[];
        for ($i = 0; $i < 5; $i++) {
                $ts[$i]=new DateTime();
                $ts[$i]->modify($offsets[$i]);
        }
        for ($i = 1; $i < 5; $i++) {
                $days = 1+ $ts[$i]->diff($ts[0])->days;
                $lookups[$i] = 'previous' . $days;
        }
        $lut = ['day'=>$lookups[3],'week'=>$lookups[1],'month'=>$lookups[2],'year'=>$lookups[4]];
        $date = $lut[$report['period_param']];
        /* MONKEYPATCH FINISHED */

        $this->checkUserHasViewPermission($login, $idSite);
@diosmosis commented on June 30th 2021 Member

@MrBenGriffin Thanks for the detailed explanation! To confirm I understand, the problem is just that due to the use of the log importer today never has data, so the email reports end up not being as useful, correct? And you'd like the ability to specify not including today or sending the previousN days in email reports?

@MrBenGriffin commented on June 30th 2021

Hi, pretty much. But also, in fairness, the email reports would be more useful if one thinks about how we would want to use them. Normally we are going to use them as the basis of a larger report which will be driven by calendar weeks, calendar months, quarters, etc.
Likewise, being able to not include today is pretty essential!

@diosmosis commented on June 30th 2021 Member

Thanks for the confirmation, I've marked this as an Enhancement and added a relevant title. It will be prioritized but I can't say when it will be implemented.

Powered by GitHub Issue Mirror