# WordPress

> The mettr plugin sends a WordPress site's page views, crawler visits, 404s, fatal errors, sign-ins and WooCommerce orders, refunds and subscriptions.

Source: https://status.mettr.app/docs/wordpress

WordPress 6.0 or later, PHP 7.4 or later, no dependencies. The source is on [GitHub](https://github.com/mettrhq/mettr-wordpress), licensed GPL-2.0-or-later as WordPress is.

## Install

In WordPress, **Plugins**, **Add New Plugin**: search for mettr, install and activate it. Then **Settings**, **mettr**: paste the site's secret and public keys (mettr, the site's settings, **Tracking**).

The keys can live in `wp-config.php` instead, out of the database:

```php
define( 'METTR_SECRET_KEY', 'sk_...' );
define( 'METTR_PUBLIC_KEY', 'pk_...' );
```

It sends nothing on a site whose environment type is `local` or `development`. `define( 'METTR_ENABLED', true );` turns it on there, `false` turns it off anywhere.

## What it sends

- **Page views, navigation, scroll depth, time on page, [Web Vitals](/docs/browser-script#web-vitals) and who is online**, from the [browser script](/docs/browser-script), added to every page's `<head>`. The script and its events go through `/_live` on your own domain, so ad blockers mostly let them through and each event carries the visitor's address and their WordPress user id.
- **Crawler visits**: search engines, AI crawlers, SEO tools and link previews never run a script; the plugin sees them on the server, with the page and its status.
- **404s**, and **fatal errors** by their class only, never the message.
- **Response times** of 5% of requests, by what WordPress served (`single:post`, `archive:product`, `front-page`, `rest` and so on).
- **Sign-ins and sign-ups** (`login`, `signup`), as the user's.

Each can be turned off under **Settings**, **mettr**. Administrators are left out by default. Paths listed under **Paths that send nothing** (`/up` already, one a line, `*` matching anything) send nothing.

Events leave in one batch at the end of the request, after the page has gone to the visitor where PHP can say so (PHP-FPM, LiteSpeed).

## WooCommerce

With WooCommerce active, the plugin also sends:

- `add_to_cart`, with the product;
- every **paid order** as revenue before tax, once however many hooks fire;
- **refunds** as revenue below zero;
- **WooCommerce Subscriptions**' subscriptions, for MRR, ARR and churn on the [revenue panels](/docs/revenue).

Orders and subscriptions are the customer's (their user id), never the request's visitor: a payment gateway's webhook often marks an order paid.

## Your MCP server

With the MCP Adapter, or any MCP server on the REST API, the plugin counts each call an AI assistant makes, with nothing to set up: `mcp.connect`, `mcp.tool`, `mcp.resource` and `mcp.prompt`, with the tool's, resource's or prompt's name, the assistant, how the call ended (a 401 from the REST API's auth included) and how long it took. The call is the signed-in WordPress user's. Never the arguments, the answer or an error's message; the session only as a hash. Such a request sends no crawl or response time. More in [MCP analytics](/docs/mcp-analytics).

## Your own events

From a theme or another plugin:

```php
mettr_event( 'newsletter', array( 'list' => 'weekly' ) );
```

Names are up to 100 characters. Props are flat: up to 30, each a string, number, boolean or null.

## Behind a proxy

The visitor's address is read from `CF-Connecting-IP` only when the request came from Cloudflare's own ranges. Behind a proxy of your own, tick **Read the visitor's address from X-Forwarded-For**; never otherwise, as anyone can send that header.

## Page caching

A page served from a page cache (a cache plugin's, or your host's) is answered before plugins load: the script still counts its page views and who is online, but the plugin does not see crawler visits or response times of cached pages.
