From 084b6542ba63e4e25acb769277709527ed11360a Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Thu, 16 Oct 2025 11:34:14 +0530 Subject: [PATCH 1/3] Update CustomAlerts to include Matomo domain with idSite, #PF-4676 --- Slack.php | 10 +++++++++- tests/Integration/SlackTest.php | 12 ++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Slack.php b/Slack.php index 0965a4c..ae5c40a 100644 --- a/Slack.php +++ b/Slack.php @@ -15,6 +15,7 @@ use Piwik\Piwik; use Piwik\Plugin; use Piwik\Plugins\ScheduledReports\ScheduledReports; +use Piwik\SettingsPiwik; use Piwik\View; use Piwik\Container\StaticContainer; use Piwik\ReportRenderer; @@ -466,7 +467,14 @@ private function groupAlertsByChannelId(array $alerts): array */ public function getAlertMessage(array $alert, string $metric, string $reportName): string { - return Piwik::translate('Slack_SlackAlertContent', [$alert['name'], $alert['siteName'], $metric, $reportName, $this->transformAlertCondition($alert)]); + $settingURL = SettingsPiwik::getPiwikUrl(); + if (stripos($settingURL, 'index.php') === false) { + $settingURL .= 'index.php'; + } + $settingURL .= '?idSite=' . $alert['idsite']; + $siteName = $alert['siteName']; + $siteWithLink = "<$settingURL|$siteName>"; + return Piwik::translate('Slack_SlackAlertContent', [$alert['name'], $siteWithLink, $metric, $reportName, $this->transformAlertCondition($alert)]); } /** diff --git a/tests/Integration/SlackTest.php b/tests/Integration/SlackTest.php index c949d43..78a79c3 100644 --- a/tests/Integration/SlackTest.php +++ b/tests/Integration/SlackTest.php @@ -105,12 +105,12 @@ public function testGetAlertMessage($alert, $expectedMessage) public function getAlertData() { return [ - [['name' => 'Alert1', 'siteName' => 'test.com', 'metric_condition' => 'less_than', 'metric_matched' => '5', 'value_new' => '1', 'value_old' => '2'], 'Alert1 has been triggered for website test.com as the metric Unique Visitors in report Visits Summary is 1 which is less than 5.'], - [['name' => 'Alert2', 'siteName' => 'test.com', 'metric_condition' => 'greater_than', 'metric_matched' => '8', 'value_new' => '10', 'value_old' => '2'], 'Alert2 has been triggered for website test.com as the metric Unique Visitors in report Visits Summary is 10 which is greater than 8.'], - [['name' => 'Alert3', 'siteName' => 'test.com', 'metric_condition' => 'decrease_more_than', 'metric_matched' => '5', 'value_new' => '8', 'value_old' => '15'], 'Alert3 has been triggered for website test.com as the metric Unique Visitors in report Visits Summary decreased more than 5 from 15 to 8.'], - [['name' => 'Alert4', 'siteName' => 'test.com', 'metric_condition' => 'increase_more_than', 'metric_matched' => '5', 'value_new' => '30', 'value_old' => '20'], 'Alert4 has been triggered for website test.com as the metric Unique Visitors in report Visits Summary increased more than 5 from 20 to 30.'], - [['name' => 'Alert5', 'siteName' => 'test.com', 'metric_condition' => 'percentage_decrease_more_than', 'metric_matched' => '5', 'value_new' => '8', 'value_old' => '15'], 'Alert5 has been triggered for website test.com as the metric Unique Visitors in report Visits Summary decreased more than 5% from 15 to 8.'], - [['name' => 'Alert6', 'siteName' => 'test.com', 'metric_condition' => 'percentage_increase_more_than', 'metric_matched' => '5', 'value_new' => '30', 'value_old' => '20'], 'Alert6 has been triggered for website test.com as the metric Unique Visitors in report Visits Summary increased more than 5% from 20 to 30.'], + [['name' => 'Alert1', 'siteName' => 'test.com', 'metric_condition' => 'less_than', 'metric_matched' => '5', 'value_new' => '1', 'value_old' => '2', 'idsite' => 1], 'Alert1 has been triggered for website 'Alert2', 'siteName' => 'test.com', 'metric_condition' => 'greater_than', 'metric_matched' => '8', 'value_new' => '10', 'value_old' => '2', 'idsite' => 1], 'Alert2 has been triggered for website 'Alert3', 'siteName' => 'test.com', 'metric_condition' => 'decrease_more_than', 'metric_matched' => '5', 'value_new' => '8', 'value_old' => '15', 'idsite' => 1], 'Alert3 has been triggered for website 'Alert4', 'siteName' => 'test.com', 'metric_condition' => 'increase_more_than', 'metric_matched' => '5', 'value_new' => '30', 'value_old' => '20', 'idsite' => 1], 'Alert4 has been triggered for website 'Alert5', 'siteName' => 'test.com', 'metric_condition' => 'percentage_decrease_more_than', 'metric_matched' => '5', 'value_new' => '8', 'value_old' => '15', 'idsite' => 1], 'Alert5 has been triggered for website 'Alert6', 'siteName' => 'test.com', 'metric_condition' => 'percentage_increase_more_than', 'metric_matched' => '5', 'value_new' => '30', 'value_old' => '20', 'idsite' => 1], 'Alert6 has been triggered for website Date: Thu, 16 Oct 2025 11:43:25 +0530 Subject: [PATCH 2/3] Bumped version --- CHANGELOG.md | 3 +++ plugin.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fc9bba..0e52c69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +5.0.2 - 2025-10-27 +- Update Slack alert message to mention Matomo instance along with idSite + 5.0.1 - 2025-10-10 - Fix markReportAsSent method was missing diff --git a/plugin.json b/plugin.json index 5a41ce4..87bf7cc 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "name": "Slack", "description": "Send Matomo reports and alerts to Slack channels, keeping your team informed and ready to act in real time.", - "version": "5.0.1", + "version": "5.0.2", "theme": false, "require": { "matomo": ">=5.0.0,<6.0.0-b1" From 3bd428614fa50d409c433e4bf5be8fc928bdda50 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Thu, 16 Oct 2025 12:00:37 +0530 Subject: [PATCH 3/3] Fixes failing test --- tests/Integration/SlackTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Integration/SlackTest.php b/tests/Integration/SlackTest.php index 78a79c3..3be2e56 100644 --- a/tests/Integration/SlackTest.php +++ b/tests/Integration/SlackTest.php @@ -105,12 +105,12 @@ public function testGetAlertMessage($alert, $expectedMessage) public function getAlertData() { return [ - [['name' => 'Alert1', 'siteName' => 'test.com', 'metric_condition' => 'less_than', 'metric_matched' => '5', 'value_new' => '1', 'value_old' => '2', 'idsite' => 1], 'Alert1 has been triggered for website 'Alert2', 'siteName' => 'test.com', 'metric_condition' => 'greater_than', 'metric_matched' => '8', 'value_new' => '10', 'value_old' => '2', 'idsite' => 1], 'Alert2 has been triggered for website 'Alert3', 'siteName' => 'test.com', 'metric_condition' => 'decrease_more_than', 'metric_matched' => '5', 'value_new' => '8', 'value_old' => '15', 'idsite' => 1], 'Alert3 has been triggered for website 'Alert4', 'siteName' => 'test.com', 'metric_condition' => 'increase_more_than', 'metric_matched' => '5', 'value_new' => '30', 'value_old' => '20', 'idsite' => 1], 'Alert4 has been triggered for website 'Alert5', 'siteName' => 'test.com', 'metric_condition' => 'percentage_decrease_more_than', 'metric_matched' => '5', 'value_new' => '8', 'value_old' => '15', 'idsite' => 1], 'Alert5 has been triggered for website 'Alert6', 'siteName' => 'test.com', 'metric_condition' => 'percentage_increase_more_than', 'metric_matched' => '5', 'value_new' => '30', 'value_old' => '20', 'idsite' => 1], 'Alert6 has been triggered for website 'Alert1', 'siteName' => 'test.com', 'metric_condition' => 'less_than', 'metric_matched' => '5', 'value_new' => '1', 'value_old' => '2', 'idsite' => 1], 'Alert1 has been triggered for website as the metric Unique Visitors in report Visits Summary is 1 which is less than 5.'], + [['name' => 'Alert2', 'siteName' => 'test.com', 'metric_condition' => 'greater_than', 'metric_matched' => '8', 'value_new' => '10', 'value_old' => '2', 'idsite' => 1], 'Alert2 has been triggered for website as the metric Unique Visitors in report Visits Summary is 10 which is greater than 8.'], + [['name' => 'Alert3', 'siteName' => 'test.com', 'metric_condition' => 'decrease_more_than', 'metric_matched' => '5', 'value_new' => '8', 'value_old' => '15', 'idsite' => 1], 'Alert3 has been triggered for website as the metric Unique Visitors in report Visits Summary decreased more than 5 from 15 to 8.'], + [['name' => 'Alert4', 'siteName' => 'test.com', 'metric_condition' => 'increase_more_than', 'metric_matched' => '5', 'value_new' => '30', 'value_old' => '20', 'idsite' => 1], 'Alert4 has been triggered for website as the metric Unique Visitors in report Visits Summary increased more than 5 from 20 to 30.'], + [['name' => 'Alert5', 'siteName' => 'test.com', 'metric_condition' => 'percentage_decrease_more_than', 'metric_matched' => '5', 'value_new' => '8', 'value_old' => '15', 'idsite' => 1], 'Alert5 has been triggered for website as the metric Unique Visitors in report Visits Summary decreased more than 5% from 15 to 8.'], + [['name' => 'Alert6', 'siteName' => 'test.com', 'metric_condition' => 'percentage_increase_more_than', 'metric_matched' => '5', 'value_new' => '30', 'value_old' => '20', 'idsite' => 1], 'Alert6 has been triggered for website as the metric Unique Visitors in report Visits Summary increased more than 5% from 20 to 30.'], ]; }