Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using previous days or not including today for the period when sending Email Reports #17720

Open
MrBenGriffin opened this issue Jun 29, 2021 · 6 comments
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.

Comments

@MrBenGriffin
Copy link

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
Copy link
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
Copy link
Author

MrBenGriffin commented Jun 30, 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
Copy link
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
Copy link
Author

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 diosmosis added the Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. label Jun 30, 2021
@diosmosis diosmosis changed the title Personal Email Reports ignore values set by default Allow using previous days or not including today for the period when sending Email Reports Jun 30, 2021
@diosmosis
Copy link
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.

@tomper00
Copy link

This would be very nice indeed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

No branches or pull requests

4 participants