A single-file PHP CLI script that connects to Matomo, rotates through eligible sites, and posts one site report at a time into Slack.
This script is intended to:
- run from cron every minute
- decide for itself whether the current minute is a valid reporting slot
- pull the list of Matomo sites the configured token can access
- exclude deleted sites
- rotate deterministically through the eligible site list without using SQL or flat-file state
- post a readable Slack report for one site at a time
The script currently:
-
uses a Matomo API auth token sent as a POST parameter
-
uses a Slack webhook for delivery
-
uses
America/Los\_Angelestimezone -
filters out deleted sites using the site name pattern
(DELETED-##) -
adapts reporting frequency based on the number of eligible sites and monthly slot capacity
-
supports a forced test run from CLI
-
reports:
- today so far
- yesterday full day
- week to date
- month to date
- optional top channel
- optional top page
- rotation details
matomo\_slack\_report.php
All editable variables are kept in the config section at the top of the script.
Examples include:
- Matomo base URL
- Matomo token
- Slack webhook URL
- Slack channel
- timezone
- weekday restrictions
- deleted-site filter regex
- reporting display options
- schedule ladder
Normal cron usage:
php /path/to/matomo\_slack\_report.phpForce a send immediately:
php /path/to/matomo\_slack\_report.php --forceForce a send without posting to Slack:
php /path/to/matomo\_slack\_report.php --force --dry-runRun every minute:
\* \* \* \* \* /usr/bin/php /path/to/matomo\_slack\_report.php >> /dev/null 2>\&1The script does not post every minute. It only posts when the current time matches a valid slot or when --force is used.
This script does not store progress in SQL or a file.
Instead it:
- fetches the eligible site list
- sorts it in a stable order
- calculates the valid reporting slots for the current month
- chooses the current slot index
- maps that slot to one site using modulo arithmetic
This allows deterministic rotation without persisted state.
Deleted sites are excluded by name pattern.
Default regex:
'/\\(DELETED-\\d+\\)/i'This is intended to skip names such as:
Tocsin Data Net (DELETED-30)
- PHP with cURL enabled
- access to the Matomo Reporting API
- a valid Matomo auth token
- a Slack incoming webhook
- The Matomo token is sent as a POST field, not in the query string
- The script is designed as a standalone CLI file with no external config file
- Output helpers are included so the script does not depend on
STDOUTorSTDERRbeing defined
--site-id=CLI override for testing a specific site- optional include/exclude lists by site ID or name
- optional quieter Slack mode for zero-traffic sites
- optional rolling 7-day mode instead of Monday-through-now week mode
- optional richer Slack block formatting