Skip to content

Commit

Permalink
Add docs for the od_url_metric_stored action
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Nov 14, 2024
1 parent 28a6491 commit b76d1d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 12 additions & 0 deletions plugins/optimization-detective/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ add_filter(

See also [example usage](https://github.com/WordPress/performance/blob/6bb8405c5c446e3b66c2bfa3ae03ba61b188bca2/plugins/embed-optimizer/hooks.php#L128-L144) in Embed Optimizer. Note in particular the structure of the plugin’s [detect.js](https://github.com/WordPress/performance/blob/trunk/plugins/embed-optimizer/detect.js) script module, how it exports `initialize` and `finalize` functions which Optimization Detective then calls when the page loads and when the page unloads, at which time the URL Metric is constructed and sent to the server for storage. Refer also to the [TypeScript type definitions](https://github.com/WordPress/performance/blob/trunk/plugins/optimization-detective/types.ts).

**Action:** `od_url_metric_stored` (argument: `OD_URL_Metric_Store_Request_Context`)

Fires whenever a URL Metric was successfully stored.

The supplied context object includes these properties:

* `$request`: The `WP_REST_Request` for storing the URL Metric.
* `$post_id`: The post ID for the `od_url_metric` post.
* `$url_metric`: The newly-stored URL Metric.
* `$url_metric_group`: The viewport group that the URL Metric was added to.
* `$url_metric_group_collection`: The `OD_URL_Metric_Group_Collection` instance to which the URL Metric was added.

== Installation ==

= Installation from within WordPress =
Expand Down
1 change: 0 additions & 1 deletion plugins/optimization-detective/storage/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ function od_handle_rest_request( WP_REST_Request $request ) {
* Fires whenever a URL Metric was successfully stored.
*
* @since 0.7.0
* @todo Add this to the README as documentation.
*
* @param OD_URL_Metric_Store_Request_Context $context Context about the successful URL Metric collection.
*/
Expand Down

0 comments on commit b76d1d3

Please sign in to comment.