=== AlwaysPass ===
Contributors: onerhino1
Tags: core web vitals, performance, page speed, monitoring, real user monitoring
Requires at least: 5.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.2.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Measures Core Web Vitals from your real visitors and reports them to your AlwaysPass dashboard.

== Description ==

AlwaysPass measures how your site actually performs for the people visiting it, rather than in a lab. It loads a small monitoring script that records the three Core Web Vitals metrics Google uses for page experience — Largest Contentful Paint (LCP), Cumulative Layout Shift (CLS) and Interaction to Next Paint (INP) — and sends those measurements to your AlwaysPass dashboard, where you can see them per page and over time.

= An AlwaysPass account is required =

This plugin is a client for the AlwaysPass service. It does nothing on its own, and it sends nothing to AlwaysPass until an administrator opens the AlwaysPass screen and clicks **Connect to AlwaysPass**. That screen shows what will be sent. After you connect, the plugin asks the AlwaysPass API once a day whether an account exists for this site's domain. Until an account is confirmed, **no script is loaded and no data is collected**. If you do not have an account, the screen links you to the sign-up page.

= What is not measured =

The plugin deliberately excludes traffic that would distort your numbers:

* Every page load before you connect, or while no AlwaysPass account is confirmed for the domain.
* All of the WordPress admin area.
* Any visitor signed in as an administrator.

Logged-out visitors and signed-in users who are not administrators are measured normally.

= Turning it off =

The settings screen has a single switch. Disabling it stops the script from loading immediately, without deactivating the plugin. **Disconnect** on the same screen also stops the plugin from contacting AlwaysPass.

== External services ==

This plugin relies on the AlwaysPass service, and the script it loads reaches one further host. All three are listed here, with what is sent and when.

**1. The monitoring script — `https://app.alwayspass.io/script.min.js`**

Loaded in the `<head>` of your front-end pages, but only after you have clicked Connect, the plugin is enabled, and an AlwaysPass account has been confirmed for your domain. As with any request for a file, loading it sends your visitor's IP address, browser user agent and referring page to AlwaysPass.

**2. The account check — `https://app.alwayspass.io/api/site-status`**

A server-side request from your site to the AlwaysPass API, asking whether an account exists for this domain. It sends only your site's domain, as a query parameter. The request's User-Agent header identifies the plugin and its version (for example `AlwaysPass-WP/1.2.2`). No visitor data is involved.

This request is made for the first time when an administrator clicks **Connect to AlwaysPass**, never on activation. After that it is made once a day via WP-Cron, when you open the plugin's settings screen if the stored answer is older than 12 hours, and when you press **Check again**. It is **never** made during a front-end page load. It stops when you click **Disconnect** or deactivate the plugin. On a local address (`localhost`, an IP address or a name without a domain extension) the request is never made, because AlwaysPass can only monitor sites on a public domain.

**3. The measurement endpoint — `https://crux-api.vercel.app/api/records`**

Where the collected measurements are sent, by the script in (1), from the visitor's browser. Note that this is a different host from `app.alwayspass.io`. Measurements from a domain without an AlwaysPass account are rejected by the endpoint.

= What is sent to the measurement endpoint =

The script includes Google's open-source `web-vitals` library (Apache-2.0); it is part of the file in (1), so no other host is contacted to load it.

Measurements are grouped and sent as JSON requests, each containing exactly these fields:

* `device` — either `mobile` or `desktop`, derived from the browser's user agent string.
* `metrics` — the metric names and values recorded, for LCP, CLS or INP.
* `url` — the address of the page the visitor landed on, reduced to its origin and path in the visitor's browser: any query string and `#fragment` are removed before sending.
* `origin` — the scheme and host of the page being measured.
* `userAgent` — the visitor's full browser user agent string.
* `batch_id` — a random identifier generated for each page view, used only to discard duplicate deliveries. It is not stored in the browser and is not linked to the visitor.
* `sequence` — the order of the request within that page view.
* `sent_at` — the browser's timestamp when the request was sent.

Requests are sent after 5 seconds without a new metric, when the tab is hidden, and when the page is closed or left.

One of these fields warrants your attention as a site owner: `userAgent` is the visitor's full, unmodified user agent string. The page path in `url` is sent as it is, so avoid putting personal data in your URL paths.

No cookies are set, no identifier is assigned to a visitor, and nothing is stored in the visitor's browser.

= Cookie consent =

If your site runs a consent plugin that supports the WP Consent API (Complianz, CookieYes, Cookiebot and others), the script waits for the visitor to allow the "statistics" category. Nothing is loaded from AlwaysPass before that. The check happens in the visitor's browser, so it also works with page caching. Without the WP Consent API, the script loads on every page view, as described above.

The plugin also adds a suggested section to Settings → Privacy → Policy Guide, which you can copy into your privacy policy.

= Service terms =

* Terms of Service: https://app.alwayspass.io/terms-of-service
* Privacy Policy: https://app.alwayspass.io/privacy-policy
* Cookie Policy: https://app.alwayspass.io/cookie-policy

By using this plugin you agree to the AlwaysPass Terms of Service, and your visitors' data is handled as described in the Privacy Policy.

== Installation ==

1. Install the plugin through Plugins > Add New in your WordPress admin, or upload it to `/wp-content/plugins/`.
2. Activate it through the Plugins menu.
3. Open **AlwaysPass** in the admin sidebar.
4. Read what will be sent and click **Connect to AlwaysPass**.

If the screen shows **Account connected**, you are done — measurement starts on your next front-end page view.

If it shows **Account not found**, this domain has no AlwaysPass account yet. Use the sign-up link on that screen to register the same domain at https://app.alwayspass.io/register, then come back and press **Check again**.

== Frequently Asked Questions ==

= Do I need an AlwaysPass account? =

Yes. The plugin is a client for the AlwaysPass service and does nothing without an account for your domain. Nothing is sent to AlwaysPass until you click Connect. Until the account check succeeds, no script is loaded and no data is collected.

= Is my own traffic measured? =

No, not when you are signed in as an administrator, and never inside the WordPress admin area. This keeps your own editing sessions out of your performance data. Visitors who are logged out, and signed-in users who are not administrators, are measured normally.

= What happens if AlwaysPass is unreachable? =

Nothing breaks. The last successful answer is kept, so a service outage does not silently stop your monitoring. The plugin retries on a short back-off rather than on every page load, and the settings screen tells you when the stored answer is stale.

= How often is the account re-checked? =

Once a day via WP-Cron, after you have clicked Connect. Opening the plugin's settings screen also refreshes it if the stored answer is older than 12 hours. You can force a check at any time with **Check again**.

= What if I move the site to a different domain? =

The stored answer belongs to the domain it was checked against. If the site moves, the plugin treats the account as unconfirmed and stops loading the script until a check succeeds for the new domain.

= How do I stop it without deactivating the plugin? =

Use the switch on the plugin's settings screen. The script stops loading immediately.

= How do I stop the plugin from contacting AlwaysPass? =

Click **Disconnect** on the plugin's settings screen. The stored answer and the daily check are removed and the script stops loading. Deactivating the plugin has the same effect.

= What does the plugin store in my database? =

Three options and two short-lived transients: whether the script is switched on, when you clicked Connect, the cached result of the account check, and the two timers that control caching and retries. After you connect it also schedules one daily WP-Cron event. Disconnect removes the connection, the cached result and the event. Deactivating the plugin removes all of it.

== Changelog ==

= 1.2.2 =
* The External services section now describes exactly what the monitoring script sends and stores.
* The admin screen's variables now carry the plugin prefix. No change in behaviour.

= 1.2.1 =
* The monitoring script now loads with `async` instead of `defer`, so your site's own page-ready code never waits for it.
* The measurement library is now bundled in the script, so unpkg.com is no longer contacted.
* Page addresses are sent without query string or `#fragment`, and the landing page is recorded once per page view.

= 1.2.0 =
* Activation no longer contacts any server. The account check starts only after an administrator clicks Connect on the plugin's screen, which shows what is sent.
* Added Disconnect, which stops all contact with AlwaysPass.
* The account check no longer sends the site's home URL in the User-Agent.
* With a consent plugin that supports the WP Consent API, the script waits for the visitor to allow statistics.
* Added a suggested privacy policy section (Settings → Privacy → Policy Guide).
* On a local address such as localhost, the plugin explains that only public domains can be connected and sends nothing.
* Clearer account screen: one message per state.

= 1.1.0 =
* An AlwaysPass account is now required before any script is loaded. Sites with no confirmed account collect nothing.
* The WordPress admin area and administrator sessions are excluded from measurement.
* The settings screen now shows the connection state, when it was last checked, and a button to re-check on demand.

= 1.0.1 =
* Added a sign-up link to the settings screen.

= 1.0.0 =
* First release.

== Upgrade Notice ==

= 1.2.2 =
Documentation and code-style update. No change in behaviour.

= 1.2.1 =
The script no longer delays your site's page-ready code and no longer contacts unpkg.com.

= 1.2.0 =
The plugin now asks before contacting AlwaysPass. After updating, open the AlwaysPass screen and click Connect to resume monitoring.

= 1.1.0 =
Measurement now requires a confirmed AlwaysPass account for your domain, and administrator traffic is no longer measured.
