Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 9 additions & 1 deletion Slack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
}
Comment on lines +471 to +473
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent way too long thinking about this bit. I think the upstream code could be improved!

I'm not 100% sure getPiwikUrl will always include the trailing / either, but I couldn't figure it out for sure!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@james-hill-matomo We have this code for GA and SEKP plugin and its running fine without any errors so I didn't bother adding / check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need a central location for this stuff!

$settingURL .= '?idSite=' . $alert['idsite'];
$siteName = $alert['siteName'];
$siteWithLink = "<$settingURL|$siteName>";
return Piwik::translate('Slack_SlackAlertContent', [$alert['name'], $siteWithLink, $metric, $reportName, $this->transformAlertCondition($alert)]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
12 changes: 6 additions & 6 deletions tests/Integration/SlackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://localhost/tests/PHPUnit/proxy/index.php?idSite=1|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', 'idsite' => 1], 'Alert2 has been triggered for website <http://localhost/tests/PHPUnit/proxy/index.php?idSite=1|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', 'idsite' => 1], 'Alert3 has been triggered for website <http://localhost/tests/PHPUnit/proxy/index.php?idSite=1|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', 'idsite' => 1], 'Alert4 has been triggered for website <http://localhost/tests/PHPUnit/proxy/index.php?idSite=1|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', 'idsite' => 1], 'Alert5 has been triggered for website <http://localhost/tests/PHPUnit/proxy/index.php?idSite=1|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', 'idsite' => 1], 'Alert6 has been triggered for website <http://localhost/tests/PHPUnit/proxy/index.php?idSite=1|test.com> as the metric Unique Visitors in report Visits Summary increased more than 5% from 20 to 30.'],
];
}

Expand Down