=== Stattery ===
Contributors: johnpoz
Tags: analytics, statistics, live chat, woocommerce, visitors
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 0.9.37
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Real-time visitor analytics, visitor chat and store events for your site, shown in Stattery.

== Description ==

Stattery shows who is on your site right now and what they do: the pages they read, where they came from, what they
buy and when they want to talk. This plugin connects your WordPress site to your Stattery account.

* **Live visitors.** Every visit appears in Stattery as it happens, with its pages, referrer, campaign and device.
* **Signed-in members by name.** Logged-in users show by name instead of as anonymous visitors.
* **Store events.** WooCommerce orders, refunds and status changes are sent from the server, so sales are counted
  even when a browser blocks scripts. Internal orders and claims are not counted as sales, and quote or proposal
  plugin statuses are counted as quotes.
* **Visitor chat.** Turn on chat in Stattery and a chat window appears on your site. Signed-in visitors skip the
  name and email form.
* **Nothing lost.** If Stattery cannot be reached, store and server events wait on your site and are sent once it
  is back. A backup collector takes over automatically if the main one stops answering.
* **Never slows a page down.** The tracking script loads after the page has finished loading, and script
  optimizers such as Perfmatters and WP Rocket are kept from delaying it.
* **Bring your history.** Import past visits from WP Statistics, AnalyticsWP, Koko Analytics, Burst Statistics,
  Independent Analytics or Slimstat, in the background and without double counting.
* **Blocking.** robots.txt lines and a ban list set in Stattery are applied on your site.
* **Search engines told about changes.** With IndexNow on (Settings, Stattery, Search), new, changed and removed
  posts, pages and products are announced to Bing and the other IndexNow search engines a minute later.

A Stattery account is needed. Stattery is in an invite-only alpha: creating an account needs an invite, and the
[waitlist](https://stattery.com/join/) is open.

== External services ==

This plugin connects your site to Stattery, an analytics and chat service run by Stattery, Inc. Nothing is sent
anywhere until you press Connect to Stattery under Settings, Stattery. From then on it sends the information below
to Stattery. Stattery shows it only to the account the site is added to.

* **Tracking script (c.stattery.com, backup c.stattery.net).** Each front-end page loads Stattery's script, which
  sends the page address, referrer, screen size and the visitor's browser details to Stattery. For logged-in users
  it also sends their display name, a hash of their email address (for their Gravatar picture) and a signed
  statement of who they are (with their email address), used by the chat.
* **Store and server events (c.stattery.com, backup c.stattery.net).** When WooCommerce records an order, refund or
  status change, the order's number, totals, items and status are sent from your server, with the customer's
  billing name, email, phone and address so the sale can be matched to the visitor who made it. Checkout
  events send the name and email entered.
* **Rules (c.stattery.com).** At most every five minutes, after a page has been sent to the visitor, the site asks
  Stattery for its robots.txt lines and ban list, sending only the site's name and the plugin version.
* **AI activity (c.stattery.com).** If the Easy MCP AI plugin is installed, the actions AI apps take on your site
  through it (what was done, by which app and user) are sent to Stattery.
* **Cloudflare's address list (api.cloudflare.com).** Once connected, at most once a day the site downloads
  Cloudflare's published address ranges (api.cloudflare.com/client/v4/ips), so it can tell a visitor who really came through Cloudflare from
  one pretending to. Nothing about your site or its visitors is sent. Cloudflare's
  [Privacy Policy](https://www.cloudflare.com/privacypolicy/) applies.
* **IndexNow (api.indexnow.org).** Only when you turn IndexNow on (Settings, Stattery, Search; it starts off), the addresses of posts, pages and products that were published,
  changed or removed are sent to api.indexnow.org with the site's IndexNow key, which shares them with the search
  engines that use IndexNow (Bing, Yandex, Seznam, Naver and others). Nothing about visitors is sent. The
  [IndexNow documentation](https://www.indexnow.org/documentation) describes the service.
* **Connection, history import and chat settings (c.stattery.com).** When you connect the site, import history
  from another stats plugin or use the settings screen, the site exchanges that information with Stattery.

Requests from your server are signed with the site's own key. Stattery's
[Terms of Service](https://stattery.com/terms/) and [Privacy Policy](https://stattery.com/privacy-policy/) apply.

== Installation ==

1. Install the plugin through Plugins, Add New, or upload the `stattery` folder to `wp-content/plugins/`.
2. Activate it through the Plugins screen.
3. Go to Settings, Stattery and connect the site to your Stattery account.

== Frequently Asked Questions ==

= Do I need a Stattery account? =

Yes. The plugin sends your site's visits and events to Stattery, where you see them. Sign up at stattery.com.

= Will it slow my site down? =

No. The tracking script is added once the page has finished loading, and events from the server are sent in the
background after the visitor has their page.

= Does it work with page caching? =

Yes. Pages are tracked by the script in the browser, so cached pages are counted too.

= How do I give a page a shorter name in Stattery, or make it a step? =

Open the page, post, product or category in WordPress and fill in the Stattery box: Name in Stattery (up to 80
characters), and for a step, the process's name and the step's number (and how many steps there are, if you like).
Stattery shows the name in place of the title, and each process gets its own funnel under Analytics, Funnels.

A page that changes without loading a new one, such as a configurator, can tell Stattery from its own script:
`stattery('name', 'Table Config - Step 2')` names the screen now showing, and `stattery('step', 'Table Config', 2, 10)`
marks step 2 of 10. Developers can also set both from code with the `stattery_page_name` and `stattery_page_step`
filters.

= My configurator changes steps without loading a new page. Can Stattery follow it? =

Yes, with no code. In the page's or category's Stattery box, tick Steps on this page. Stattery then sends each screen
as a step when it appears, named by the page's main heading, or by an element you name with a CSS selector (the first
one showing on the screen). If the page shows a list of its steps, give the list's items and the current one, and
Stattery reads the step's number and how many there are from it; otherwise steps are numbered in the order each visitor
reaches them, after the page's Process step. Developers can set it from code with the `stattery_page_live_steps` filter.

= Is my imported history counted twice? =

No. Days Stattery already recorded are left alone.

= How does the plugin find the visitor's address? =

It starts from the address that connected to your server. If that is your host's own proxy or load balancer (a
private address), it reads X-Forwarded-For from the right, one trusted step at a time. Cloudflare's CF-Connecting-IP
header is believed only when the request really came from Cloudflare. If your host's proxies have public addresses,
name them in wp-config.php with `define( 'STATTERY_TRUSTED_PROXIES', '198.51.100.7, 198.51.100.0/24' );`, or set it
to `''` to trust no proxy. Developers can have the last word with the `stattery_visitor_ip` filter.

= Does Stattery need my visitors' consent? =

That depends on where your site and its visitors are, and it is your decision. The tag stores one random visitor ID
in the browser (localStorage and a first-party `stt_v` cookie, kept for a year) so a returning visitor is counted once.
If your site must ask first, choose Wait for consent under Settings, Stattery, Privacy. The tag then loads only after
the visitor agrees to statistics cookies in Complianz, CookieYes, Cookiebot or any consent plugin that uses the WP
Consent API. Another banner can call `stattery('consent', true)` when the visitor agrees and
`stattery('consent', false)` if they withdraw. Developers can set the choice in code with the `stattery_consent_mode`
filter (`'always'` or `'wait'`).

= Connect says my host blocks Stattery's checker. What do I do? =

Some hosts and security services refuse requests that don't come from a browser, so Stattery can't read the site's
signing key from the site. Press Connect to Stattery anyway: Stattery shows one TXT record to add where the domain's
DNS is managed (your registrar, Cloudflare or your host), named `_stattery.` followed by your domain. Add it, wait a
few minutes, then press Check Again. You only do this once; the record can be removed after the site is connected.
Any site can choose this way on purpose with Verify with DNS instead, on the Connect page or in Settings, Sites.

= Who does Stattery show by name? =

By default, people signed in to your site are shown in Stattery by their name, and chat knows who they are. Under
Settings, Stattery, Privacy, Who Stattery Shows By Name, choose Staff only (people who can edit posts) or Nobody to
count everyone else as an anonymous visitor. Developers can decide per person with the `stattery_identify_users`
filter: `add_filter( 'stattery_identify_users', function ( $show, $user, $mode ) { return $show; }, 10, 3 );`

= What is the signing key? =

The plugin signs what it sends Stattery (orders, sign-ups, chat sign-ins) with a key kept in your site's database.
If a copy of the database or files may have reached someone else, press Make a New Key under Settings, Stattery,
Privacy. The plugin sends the new key to Stattery signed by the old one, and the old key stops working.

== Changelog ==

= 0.9.37 =
* Security fixes are now made only in WordPress. Fix It For Me in Stattery shows exactly what would change and
  opens the new Stattery Security Fix screen (Settings), where an administrator presses the button. Stattery can
  no longer make or undo a fix on the site by itself.
* Author URI is now https://stattery.com/.

= 0.9.36 =
* Fix: on some sites the plugin could stop picking up Stattery's ban list and settings after a rare database
  hiccup, while Stattery was told all was well. It now recovers by itself within seconds.

= 0.9.35 =
* Connect works on hosts that block Stattery's checker. The plugin hands its signing key to Stattery when you press
  Connect. If Stattery can't read the key from the site to confirm it, it asks for one DNS record that shows the site
  is yours.
* New: Settings, Stattery, Privacy, Who Stattery Shows By Name: Everyone signed in (the default), Staff only, or
  Nobody. Developers can decide per person with the stattery_identify_users filter.
* New: Settings, Stattery, Privacy, Signing Key: make a new key; Stattery gets it signed by the old one.

= 0.9.34 =
* Locking an account now happens only in your own WordPress admin. Stattery's sign-in alert links to the new Lock User
  screen in wp-admin, where an administrator sees the account and presses Lock to sign it out everywhere and
  reset its password. Stattery can no longer lock an account itself.
* The contact form shortcode shows nothing to visitors until the site is connected to Stattery.
* Scripts and styles are added through WordPress's script and style functions, and request values are cleaned before
  use (WordPress.org review).
* The WordPress.org copy no longer changes PHP settings itself: the "hide PHP errors" and "move debug.log" fixes show the
  wp-config.php lines to add instead.

= 0.9.33 =
* Your site's own server is never blocked by its ban list, so WordPress's scheduled tasks, updates and Site Health
  checks keep working.
* On hosts without PHP-FPM, opening wp-admin refreshes Stattery's rules when they are due, so the site keeps up to date
  even when WordPress's scheduled tasks can't run.

= 0.9.32 =
* Privacy: nothing is sent anywhere until you press Connect to Stattery. Before that the plugin adds nothing to your
  pages and makes no outside requests. Sites already connected carry on as before.
* IndexNow now starts off on new installs; turn it on under Settings, Stattery, Search. Sites that turned it on keep it.
* The Connect card explains that Stattery is in an invite-only alpha and links the waitlist.
* Every database query is now prepared, and output on the settings screens is escaped (WordPress.org Plugin Check:
  0 errors). Requires WordPress 6.2 or later.
* Cloudflare's address ranges now come from Cloudflare's IP ranges API in one request.

= 0.9.31 =
* Support: when a member of Stattery's own support staff changes something in your site's admin, Stattery keeps a
  record of what they did in its internal support log. Nothing is recorded for you or your own people.

= 0.9.30 =
* WooCommerce: an order moved to the trash or deleted now tells Stattery, so it stops counting as a sale on the day
  it was placed or paid. Restoring it from the trash counts it again.

= 0.9.29 =
* Fix: 0.9.28 would not load when installed from the zip (a PHP syntax error). Nothing else changes.

= 0.9.28 =
* Security: Stattery's security checks can read what an outside check can't see (the WordPress, plugin and theme
  versions, the role new accounts get, whether the file editor is on and PHP errors are shown, and how many
  administrator accounts there are, never their names or emails).
* Fix It For Me: from Stattery's Security page, close the user list to signed-out visitors, turn XML-RPC off, turn
  the file editors off, hide PHP errors from visitors, move debug.log out of reach, give new accounts the
  Subscriber (or Customer) role, and refuse plugin and theme readme and changelog files to the outside (Apache and
  LiteSpeed). Each shows exactly what it will change first, and each is undone with one click.

= 0.9.27 =
* Stopped for you: a comment Stattery refuses or holds carries its first words, its author's name and the post's title,
  so Settings, Bots, Stopped in Stattery can show what was sent.

= 0.9.26 =
* Sign-in alerts show what the account was before the sign-in: its orders and money spent, its last order, open
  quotes, when it last signed in and from where, its last comment, and the last email the site sent it. The plugin
  now keeps each account's last 10 sign-ins and the last 3 emails sent to it (time and subject only).

= 0.9.25 =
* Stop comment spam: with the switch on in Stattery (Settings, Bots), comments on blog posts from bots are refused,
  and comments Stattery isn't sure about wait in WordPress's Pending queue, marked in a Stattery column. Signed-in
  users, product reviews and questions are never checked.

= 0.9.24 =
* IndexNow: when a post, page or product is published, updated, unpublished or deleted, Bing and the other IndexNow
  search engines are told a minute later (changes go together; each address at most once every 10 minutes). The
  key file is served at https://your-site/<key>.txt. On for new installs; turn it on under Settings, Stattery,
  Search. Each ping and its answer show in Stattery under Search, Crawler Activity.

= 0.9.23 =
* Ban list and robots.txt rules keep updating on sites where another plugin's end-of-page work stalls or
  runs out of time: the update now runs before other plugins' end-of-page work, waits longer for a big answer, and
  catches up on its own when it falls behind.

= 0.9.22 =
* Sign-in alerts name the account: username, email, display name and role, with administrator accounts flagged,
  and what the account did after signing in (orders, comments, posts and pages it changed, open sessions).

= 0.9.21 =
* Sign-in alerts: when Stattery's Edge Observer sees a sign-in that looks like someone else using an account's
  password, "End sessions and reset password" in Stattery signs that account out everywhere, sets a random password and
  sends WordPress's own reset email. Stattery only ever gets a fingerprint of the account, never its name.
* Sessions record the visitor's real address behind Cloudflare, not Cloudflare's.

= 0.9.20 =
* Visitor consent: Settings, Stattery, Privacy can wait for the visitor's consent before the tag loads. Works with
  Complianz, CookieYes, Cookiebot and the WP Consent API, or your own banner through `stattery('consent', true)`.
  Until the visitor agrees, nothing is sent to Stattery and nothing is stored in their browser.
* The contact form can offer a choice of topics: `[stattery_contact topics="General|Bug report|Feature request"
  bugtopic="Bug report"]`. The topic marked as the bug report shows the steps and page fields.

= 0.9.19 =
* The Stattery box's "of" field is wider, so "optional" shows in full.

= 0.9.18 =
* A shorter Stattery box in the editor: each explanation now opens from the (i) beside its label, and the Steps on
  this page fields show only once it is ticked.

= 0.9.17 =
* Live carts: Stattery shows what's in each visitor's WooCommerce cart as it changes, with each item's name, quantity,
  price and picture.
* A store that keeps its cart in the visitor's browser (a custom or headless cart) can name its storage key under
  Stattery, Checkout, and Stattery reads the cart there. Developers can use the `stattery_cart_key` filter, or hand the
  cart over from the page with `stattery('cart', cart)`.

= 0.9.16 =
* Steps on this page: for a product configurator or a builder whose screens change without loading a new page, tick
  it in the Stattery box and Stattery sends each screen as a step of the process, named by its heading or by an
  element you choose, with no code on your site.

= 0.9.15 =
* Give any page, post, product or category a short name for Stattery, such as "Table Config - Step 1", in the new
  Stattery box on its edit screen. Stattery shows that name in place of a long title, and keeps the title too.
* Mark a page as one step of a process, such as a configurator or a quote form. Stattery shows how far people get
  through it, and where they stop, under Analytics, Funnels.
* A Stattery name column in your lists of posts, pages and products.

= 0.9.14 =
* Bans can't be dodged by faking the visitor's address on sites that can be reached around Cloudflare. The plugin
  believes Cloudflare's address header only when the visit really came through Cloudflare, and reads your host's own
  proxy headers only from its own machines.

= 0.9.13 =
* Turning chat on or off in Stattery now reaches your visitors within seconds, whatever page cache or CDN your site
  uses, so there's nothing to clear. The plugin no longer clears your page cache when chat is switched.
* Plugin updates now come from Stattery itself.

= 0.9.12 =
* Turning chat on or off in Stattery reaches your site within seconds. Stattery clears the page cache for you if
  you use SiteGround, WP Rocket, LiteSpeed Cache, W3 Total Cache, WP Super Cache or xCloud. With any other page
  cache or a CDN that caches pages, clear it yourself after switching chat on or off.

= 0.9.11 =
* When someone calls, Stattery looks the caller up in your store by phone number and shows their whole order history,
  including orders from before Stattery was installed.

= 0.9.10 =
* Store revenue counts on the day WooCommerce says an order was paid, so an order marked Completed weeks later
  no longer shows up as today's revenue.
* Contact forms can name a topic, so they reach the right team in Stattery Chat, and can take bug reports.

= 0.9.9 =
* Ready for the WordPress.org plugin directory: GPL license header, this readme, Requires at least and Text Domain.
* A Settings link on Stattery's row in Plugins.

= 0.9.8 =
* Import your history from Koko Analytics, Burst Statistics, Independent Analytics or Slimstat under Settings,
  Stattery, Import History, in the background and without double counting. Imported history is free.

= 0.9.7 =
* Import your history from WP Statistics or AnalyticsWP, a batch at a time, so big sites never time out.

= 0.9.6 =
* If Stattery's main servers stop answering, the site switches to a backup collector automatically.

= 0.9.5 =
* If Stattery stops answering, store and server events wait on your site and are sent once it is back
  (Settings, Stattery shows what's waiting, with a Send Now button).
* The tracking script loads after the page has finished loading.

= 0.9.4 =
* Chat settings moved into Stattery, under Site Settings, Chat.

= 0.9.1 =
* The page's featured image, at WordPress's medium size, for Stattery's hover card.

= 0.9.0 =
* Proposal plugin statuses are quotes, internal orders and claims aren't sales, and the tag can't be delayed by
  Perfmatters or WP Rocket.

== Upgrade Notice ==

= 0.9.20 =
Optional: wait for each visitor's consent before counting them.

= 0.9.17 =
Stattery shows each visitor's cart live.

= 0.9.16 =
Stattery can follow configurators whose steps change without loading a new page.

= 0.9.15 =
Short names for your pages in Stattery, and steps for funnels.

= 0.9.14 =
Bans can't be dodged by faking the visitor's address.

= 0.9.12 =
Turning chat on or off reaches your site within seconds.

= 0.9.11 =
Callers are looked up in your store by phone number.

= 0.9.10 =
Revenue counts on the day an order was paid, and contact form topics.

= 0.9.9 =
Licensing and readme for the WordPress.org directory, and a Settings link on the Plugins screen.
