> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crispstats.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> CrispStats is a hosted, privacy-first analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing and no data import except a site's history from a Plausible export (Settings, Import and export). Websites use the script. iOS, Android, React Native and Flutter use the mobile SDKs in the install guides. Those SDKs are source files, not a published package, and they do not read an advertising id.
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> The script tag is the main install; the npm package @crispstats/tracker does the same from code, never alongside the tag. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# Connect WooCommerce revenue to CrispStats

> Connect a WooCommerce store by typing its address and approving access on the store: CrispStats adds order webhooks, records paid orders and refunds, and the CrispStats WordPress plugin ties each order to a visit.

Connect a WooCommerce store by typing its address and approving access on the store's own screen. Nothing is pasted: WooCommerce hands CrispStats a key directly, and CrispStats adds three order webhooks to the store. From then on, paid orders and refunds arrive within seconds. Install the [CrispStats WordPress plugin](https://docs.crispstats.com/install/wordpress.md) and each order is tied to the visit that led to it.

| | |
| - | - |
| You type | The address of the WordPress site the store runs on, over https |
| New payments | Within seconds, by webhook |
| History | Not imported: orders are recorded from the moment you connect |
| Test mode | Per order, when the gateway marks it: see [test orders](#test-orders) |
| Linked to a visit | When the CrispStats WordPress plugin is installed and **Link orders to visits** is on |

## What is recorded

| WooCommerce order | Recorded as |
| - | - |
| Status **Processing** or **Completed** | `one_time`, for the order total, in the order's own currency |
| A renewal order from WooCommerce Subscriptions | `subscription_renewal` |
| Each refund on an order, partial or full | `refund` of its order, for the amount refunded, tax included |
| Pending payment, On hold, Failed, Cancelled, Draft or Trash | Nothing |

An order that moves from **Processing** to **Completed** is stored once. A refund, partial or full, makes WooCommerce send the order again with every refund it has so far, and each refund is stored once. A refund you delete in WooCommerce stays recorded. The product is the order's line item names. A deleted order keeps the sale that was recorded, because the money was paid. An order in a currency CrispStats does not know is skipped, and the row counts it.

WooCommerce payments are not read back from the store, so they never show as verified revenue. CrispStats checks the signature of every webhook with the secret it gave the store.

### Test orders

WooCommerce has no test keys, so CrispStats leaves out test orders one by one, by the mark the payment gateway saves on the order:

| Gateway | Test orders |
| - | - |
| WooPayments | Left out (test mode) |
| WooCommerce PayPal Payments | Left out (sandbox) |
| Any gateway that records the payment mode, WooCommerce 11.5 and later | Left out |
| WooCommerce Stripe Gateway | Counted: it saves no test mark on the order |
| Other gateways | Counted, unless they record the payment mode |

To try a gateway that saves no test mark, use a staging copy of the store that is not connected to CrispStats.

## Connect WooCommerce

You need an administrator account on the store, and the store must be reachable over https at a public address.

**1. Open the WooCommerce panel**

In CrispStats, open the site's **Settings**, then **Revenue**. Select **Connect a payment provider** and choose **WooCommerce**. During setup, the **WordPress** choice of the install step has the same form under **I use WooCommerce**.

**2. Type the store address**

Under **Store address**, type the address of your WordPress site, such as `https://shop.example.com`. A site in a folder keeps its path, such as `https://example.com/shop`. CrispStats checks that WooCommerce answers there before it sends you on.

**3. Approve on the store**

Select **Connect WooCommerce**. Your store opens its own screen and asks you to sign in as an administrator if you are not, then to approve **CrispStats** with **Read/Write** access. Select **Approve**.

**4. Come back to CrispStats**

The store sends you back to **Revenue**. CrispStats adds its webhooks to the store, and a message confirms that WooCommerce is connected. If something went wrong, the WooCommerce panel opens again with the cause under **Store address**.

**5. Install the plugin**

Without the plugin, orders are counted but not tied to visits. See [link orders to visits](#link-orders-to-visits).

### Why Read/Write

CrispStats only reads orders, but WooCommerce gives a read-only key no way to create webhooks. The key is used to add the three webhooks when you connect and to remove them when you disconnect. CrispStats keeps the key encrypted and never changes orders, products or customers.

### What it adds to the store

Three webhooks named **CrispStats revenue attribution**, for **Order created**, **Order updated** and **Order deleted**. You see them in **WooCommerce**, **Settings**, **Advanced**, **Webhooks**, and the key under **REST API**.

### Connect again

Connecting the same store again, to replace a revoked key for example, adds a new set of webhooks first. The old set keeps delivering until the new connection is saved, then CrispStats removes it, so no order is missed during the switch. If connecting again fails, the old connection and its webhooks stay as they were.

### If the store refuses

| Message | What to do |
| - | - |
| No WooCommerce store answers at that address. | Check the address, and that WooCommerce is active on that site. |
| Use the public https address of your store. | Local, private and `http://` addresses cannot connect. A staging site behind a password cannot either. |
| You declined on the store's screen. | Select **Connect WooCommerce** again and approve. |
| That connection attempt expired. | The store screen was left open for more than 15 minutes. Select **Connect WooCommerce** again. |
| The store did not accept CrispStats's webhooks. | A security plugin or the host may block webhooks or outgoing requests. Check **WooCommerce**, **Settings**, **Advanced**, **Webhooks**, then connect again. |

## Link orders to visits

The [CrispStats WordPress plugin](https://docs.crispstats.com/install/wordpress.md) saves the visitor id of the current visit on each order at checkout, in the classic checkout and the block checkout, as the order field `crispstats_visitor_id`. CrispStats reads it from the webhook and credits the order to that visit's source, campaign and pages.

1. Install the plugin and paste your site key. See [install on WordPress](https://docs.crispstats.com/install/wordpress.md#install-the-plugin).
2. In **Settings**, **CrispStats**, check that **Link orders to visits** is on. It shows when WooCommerce is active and is on by default.

Orders placed before the plugin was installed, or by a visitor whose browser blocked the script, stay unlinked. The plugin also marks renewal orders from WooCommerce Subscriptions, so they count as renewals.

If you add the tag by hand instead of the plugin, save the visitor id on the order yourself under the meta key `crispstats_visitor_id`, with the id that `crispstats.id()` resolves to in the browser.

## Disconnect

Disconnecting removes CrispStats's webhooks from the store. Payments already recorded stay. The store keeps the REST API key it gave CrispStats until you revoke it in **WooCommerce**, **Settings**, **Advanced**, **REST API**. If the store cannot be reached when you disconnect, delete the webhooks named **CrispStats revenue attribution** there yourself.

## How fresh the numbers are

WooCommerce sends each order change within seconds. It does not resend a failed delivery, and it turns a webhook off after five failures in a row. If orders stop arriving, check the status of the **CrispStats revenue attribution** webhooks in **WooCommerce**, **Settings**, **Advanced**, **Webhooks**, or connect the store again. Past orders are not imported, so revenue starts on the day you connect. To bring in older orders, send them with the [payment API](https://docs.crispstats.com/revenue/payment-api.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.