1515use Piwik \Site ;
1616
1717/**
18- * Provides API methods to create, update, fetch, and delete custom alerts.
18+ * Exposes Custom Alerts API endpoints for managing alert definitions and reading triggered alert data.
19+ * These methods let callers create, update, fetch, delete, and evaluate alerts for one or more sites.
20+ *
1921 * @method static \Piwik\Plugins\CustomAlerts\API getInstance()
2022 */
2123class API extends \Piwik \Plugin \API
@@ -33,12 +35,12 @@ public function __construct(Processor $processor, Validator $validator)
3335 }
3436
3537 /**
36- * Calculates the alert value for each site for the given days/weeks/months in past. If the period of the alert is
37- * weeks and subPeriodN is "7" it will return the value for the week 7 weeks ago. Set subPeriodN to "0" to test the
38- * current day/week/month.
38+ * Returns the computed alert value for each site linked to an alert for a past or current period.
39+ * Use 0 to evaluate the current period, 1 for the previous matching period, and so on.
3940 *
4041 * @param int $idAlert Alert ID to evaluate.
41- * @param int $subPeriodN Number of periods in the past to evaluate. Use 0 for the current period.
42+ * @param int|string $subPeriodN Number of periods in the past to evaluate.
43+ * Use 0 for the current day, week, or month.
4244 *
4345 * @return list<array{idSite: int, value: mixed}> Alert values grouped by site.
4446 */
@@ -58,12 +60,11 @@ public function getValuesForAlertInPast($idAlert, $subPeriodN)
5860 }
5961
6062 /**
61- * Returns a single alert.
63+ * Returns a single custom alert definition .
6264 *
6365 * @param int $idAlert Alert ID to fetch.
6466 *
65- * @return array{id_sites: list<int>} & array<string, mixed> Alert definition.
66- * @throws \Exception In case alert does not exist or user has no permission to access alert.
67+ * @return array{id_sites: list<int>} & array<string, mixed> Alert definition including the configured site IDs.
6768 */
6869 public function getAlert ($ idAlert )
6970 {
@@ -84,13 +85,13 @@ private function getModel()
8485 }
8586
8687 /**
87- * Returns the Alerts that are defined on the idSites given .
88+ * Returns the custom alerts configured for the requested sites .
8889 *
8990 * @param string|array $idSites Website ID(s) to query.
9091 * Accepts comma-separated IDs, "all", numeric IDs as strings, or ["all"].
91- * @param bool $ifSuperUserReturnAllAlerts Whether to return all users' alerts when the current user is super user .
92+ * @param bool $ifSuperUserReturnAllAlerts Whether a super user should receive alerts created by all users .
9293 *
93- * @return list<array<string, mixed>> Alerts accessible to the current user.
94+ * @return list<array<string, mixed>> Alert definitions accessible to the current user for the requested sites .
9495 */
9596 public function getAlerts ($ idSites , $ ifSuperUserReturnAllAlerts = false )
9697 {
@@ -114,34 +115,34 @@ public function getAlerts($idSites, $ifSuperUserReturnAllAlerts = false)
114115 }
115116
116117 /**
117- * Creates an Alert for given website(s) .
118+ * Creates a custom alert for one or more sites .
118119 *
119120 * @param string $name Alert name.
120121 * @param string|array $idSites Website ID(s) to query.
121122 * Accepts comma-separated IDs, "all", numeric IDs as strings, or ["all"].
122123 * @param 'day'|'week'|'month' $period Alert period.
123124 * Allowed values: day, week, month.
124- * @param bool $emailMe Whether to send email notifications to the current user .
125- * @param list<string> $additionalEmails Additional email recipients.
126- * @param list<string> $phoneNumbers Mobile Messaging recipients.
127- * @param string $metric Metric unique ID ( for example nb_uniq_visits, sum_visit_length) .
128- * @param string $metricCondition Metric comparison condition .
125+ * @param bool $emailMe Whether to notify the current user by email when the alert triggers .
126+ * @param list<string> $additionalEmails Additional email recipients for email notifications .
127+ * @param list<string> $phoneNumbers Mobile Messaging recipients when the mobile channel is enabled .
128+ * @param string $metric Metric unique ID to evaluate, for example nb_uniq_visits or sum_visit_length.
129+ * @param string $metricCondition Comparison rule to apply to the metric .
129130 * Allowed values: less_than, greater_than, decrease_more_than,
130131 * increase_more_than, percentage_decrease_more_than,
131132 * percentage_increase_more_than.
132- * @param float|int|string $metricValue Metric to check for the selected report .
133+ * @param float|int|string $metricValue Threshold value to compare the selected metric against .
133134 * @param int $comparedTo Number of prior periods to compare against.
134135 * Allowed values by period: day => 1, 7, 365; week => 1; month => 1, 12.
135- * @param string $reportUniqueId Report unique ID in format module_action.
136- * @param false|string $reportCondition Group condition to apply .
136+ * @param string $reportUniqueId Report unique ID in module_action format .
137+ * @param false|string $reportCondition Optional dimension filter condition for report rows .
137138 * Allowed values: matches_any, matches_exactly, does_not_match_exactly,
138139 * matches_regex, does_not_match_regex, contains, does_not_contain,
139140 * starts_with, does_not_start_with, ends_with, does_not_end_with.
140- * @param false|string $reportValue Value used by $reportCondition.
141- * @param list<'email'|'mobile'|'slack'|'teams'> $reportMediums Delivery channels.
141+ * @param false|string $reportValue Value to match when $reportCondition is provided .
142+ * @param list<'email'|'mobile'|'slack'|'teams'> $reportMediums Delivery channels to use for notifications .
142143 * Allowed values: email, mobile, slack, teams.
143- * @param string $slackChannelID Slack channel ID when " slack" medium is enabled.
144- * @param string $msTeamsWebhookUrl Microsoft Teams webhook URL when " teams" medium is enabled.
144+ * @param string $slackChannelID Slack channel ID when the slack channel is enabled.
145+ * @param string $msTeamsWebhookUrl Microsoft Teams webhook URL when the teams channel is enabled.
145146 * @return int ID of the newly created alert.
146147 */
147148 public function addAlert ($ name , $ idSites , $ period , $ emailMe , $ additionalEmails , $ phoneNumbers , $ metric , $ metricCondition , $ metricValue , $ comparedTo , $ reportUniqueId , $ reportCondition = false , $ reportValue = false , array $ reportMediums = [], string $ slackChannelID = '' , string $ msTeamsWebhookUrl = '' )
@@ -222,35 +223,35 @@ private function checkAlert($idSites, $name, $period, &$emailMe, &$additionalEma
222223 }
223224
224225 /**
225- * Edits an Alert for given website(s) .
226+ * Updates an existing custom alert .
226227 *
227228 * @param int $idAlert Alert ID to update.
228- * @param string $name Name of alert .
229+ * @param string $name Alert name .
229230 * @param string|array $idSites Website ID(s) to query.
230231 * Accepts comma-separated IDs, "all", numeric IDs as strings, or ["all"].
231232 * @param 'day'|'week'|'month' $period Alert period.
232233 * Allowed values: day, week, month.
233- * @param bool $emailMe Whether to send email notifications to the current user .
234- * @param list<string> $additionalEmails Additional email recipients.
235- * @param list<string> $phoneNumbers Mobile Messaging recipients.
236- * @param string $metric Metric unique ID ( for example nb_uniq_visits, sum_visit_length) .
237- * @param string $metricCondition Metric comparison condition .
234+ * @param bool $emailMe Whether to notify the current user by email when the alert triggers .
235+ * @param list<string> $additionalEmails Additional email recipients for email notifications .
236+ * @param list<string> $phoneNumbers Mobile Messaging recipients when the mobile channel is enabled .
237+ * @param string $metric Metric unique ID to evaluate, for example nb_uniq_visits or sum_visit_length.
238+ * @param string $metricCondition Comparison rule to apply to the metric .
238239 * Allowed values: less_than, greater_than, decrease_more_than,
239240 * increase_more_than, percentage_decrease_more_than,
240241 * percentage_increase_more_than.
241- * @param float|int|string $metricValue Metric to check for the selected report .
242+ * @param float|int|string $metricValue Threshold value to compare the selected metric against .
242243 * @param int $comparedTo Number of prior periods to compare against.
243244 * Allowed values by period: day => 1, 7, 365; week => 1; month => 1, 12.
244- * @param string $reportUniqueId Report unique ID in format module_action.
245- * @param false|string $reportCondition Group condition to apply .
245+ * @param string $reportUniqueId Report unique ID in module_action format .
246+ * @param false|string $reportCondition Optional dimension filter condition for report rows .
246247 * Allowed values: matches_any, matches_exactly, does_not_match_exactly,
247248 * matches_regex, does_not_match_regex, contains, does_not_contain,
248249 * starts_with, does_not_start_with, ends_with, does_not_end_with.
249- * @param false|string $reportValue Value used by $reportCondition.
250- * @param list<'email'|'mobile'|'slack'|'teams'> $reportMediums Delivery channels.
250+ * @param false|string $reportValue Value to match when $reportCondition is provided .
251+ * @param list<'email'|'mobile'|'slack'|'teams'> $reportMediums Delivery channels to use for notifications .
251252 * Allowed values: email, mobile, slack, teams.
252- * @param string $slackChannelID Slack channel ID when " slack" medium is enabled.
253- * @param string $msTeamsWebhookUrl Microsoft Teams webhook URL when " teams" medium is enabled.
253+ * @param string $slackChannelID Slack channel ID when the slack channel is enabled.
254+ * @param string $msTeamsWebhookUrl Microsoft Teams webhook URL when the teams channel is enabled.
254255 *
255256 * @return int Updated alert ID.
256257 */
@@ -276,10 +277,11 @@ public function editAlert($idAlert, $name, $idSites, $period, $emailMe, $additio
276277 }
277278
278279 /**
279- * Delete alert by id .
280+ * Deletes an existing custom alert .
280281 *
281282 * @param int $idAlert Alert ID to delete.
282- * @throws \Exception In case alert does not exist or user has no permission to access alert.
283+ *
284+ * @return void
283285 */
284286 public function deleteAlert ($ idAlert )
285287 {
@@ -290,12 +292,12 @@ public function deleteAlert($idAlert)
290292 }
291293
292294 /**
293- * Get triggered alerts.
295+ * Returns triggered alerts for the current user and requested sites .
294296 *
295297 * @param string|array $idSites Website ID(s) to query.
296298 * Accepts comma-separated IDs, "all", numeric IDs as strings, or ["all"].
297299 *
298- * @return list<array<string, mixed>> Triggered alerts for the current user and requested sites.
300+ * @return list<array<string, mixed>> Triggered alert entries for the current user and requested sites.
299301 */
300302 public function getTriggeredAlerts ($ idSites )
301303 {
0 commit comments