# Check storefront visitors

Load the storefront check on your store's pages to class each visitor as a person, an agent or an automated browser, pass the visit to your checkout rules, and add consent-gated field timing.

Load the storefront check on your store's pages and Identify classes every visitor that runs the page's scripts: a person, a signed agent, an unsigned agent, an automated browser. On the cart and checkout pages you get a visit ID to pass with your checkout assessment, so your checkout rules read who was at the till. Field timing, off until you turn it on, adds how the checkout form was filled in.

**Before you begin:** a publishable key for your site (Developers › Publishable keys in the console, or the call in step 1). On Shopify, install the Provenance app instead and follow [Hold Shopify orders](https://provenanceauth.com/docs/authorize/guides/shopify.md#6-see-who-reaches-the-cart). On WooCommerce, the Provenance for WooCommerce plugin checks requests on your server and loads the script for you: follow [Hold WooCommerce orders](https://provenanceauth.com/docs/authorize/guides/woocommerce.md#5-see-who-reaches-the-cart). Every plan; each cart or checkout page view is one hosted check, and other page views are free.

1. **The page loads the script**: one event per page view
2. **Identify classes the visit**: a person, an agent or a bot
3. **Your checkout passes the visit**: your rules read it

## 1. Create a publishable key

A publishable key names your site in the browser. List your site's origins in `allowed_origins`, so a copy of the key on another site is refused.

**curl**

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5

export PUBLISHABLE_KEY=$(curl -s -X POST $PROVENANCE_API/v1/embed/publishable_keys -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" -d '{ "name": "Storefront" }' | jq -r .publishable_key)
echo "{\"publishable_key\": \"$PUBLISHABLE_KEY\"}"
```

**Node**

```ts
const res = await fetch(`${process.env.PROVENANCE_API}/v1/embed/publishable_keys`, {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ name: "Storefront", allowed_origins: ["https://brightbox.example"] }),
});
const { publishable_key } = await res.json();
```

**Python**

```python
import os, httpx

key = httpx.post(f"{os.environ['PROVENANCE_API']}/v1/embed/publishable_keys",
                 headers={"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"},
                 json={"name": "Storefront", "allowed_origins": ["https://brightbox.example"]}).json()["publishable_key"]
```

```json
{ "publishable_key": "prv_pub_9cK2mW7xT4vQ8nB3sYd6fJh1gAe5rLp0" }
```

## 2. Add the script to your pages

Put one tag in your pages' `<head>`. Tell the script which page it is on with `data-provenance-page` on `<html>`, for example `checkout`; without it, the script reads the path.

```html
<html data-provenance-page="checkout">
  <head>
    <script type="module" src="https://sandbox-api.provenanceauth.com/v1/identify/storefront.js?key=prv_pub_9cK2mW7xT4vQ8nB3sYd6fJh1gAe5rLp0" async></script>
  </head>
</html>
```

On each page view the script sends one event to [`POST /v1/identify/storefront_events`](https://provenanceauth.com/docs/api/traffic-checks.md#post-v1-identify-storefront-events): your key, the page type, a random ID for the page view and whether the browser is driven by an automation tool. Identify classes the event's own request (its address, its headers and any Web Bot Auth signature) and records it as the visit. This is what the script sends from a product page:

**curl**

```bash
curl -s -X POST $PROVENANCE_API/v1/identify/storefront_events \
  -H "Content-Type: text/plain" \
  -d "{ \"key\": \"$PUBLISHABLE_KEY\", \"event\": \"page_view\", \"page\": \"product\", \"view_id\": \"Xq3bN8vR2mT6kW9yZc4dF7hJ\", \"webdriver\": false }"
```

**Node**

```ts
await fetch(`${process.env.PROVENANCE_API}/v1/identify/storefront_events`, {
  method: "POST",
  body: JSON.stringify({ key: publishable_key, event: "page_view", page: "product", view_id: "Xq3bN8vR2mT6kW9yZc4dF7hJ", webdriver: false }),
});
```

**Python**

```python
httpx.post(f"{os.environ['PROVENANCE_API']}/v1/identify/storefront_events",
           json={"key": key, "event": "page_view", "page": "product", "view_id": "Xq3bN8vR2mT6kW9yZc4dF7hJ", "webdriver": False})
```

```json
{ "object": "storefront_event", "recorded": true, "reason": null, "visit_id": null }
```

A product page view is free and returns no visit ID. A cart or checkout page view is a hosted check and returns one, `"visit_id": "tas_01KAG3W1Q9ZJ8M4V2T6X0YB7RC"`.

## 3. Pass the visit with your checkout

On cart and checkout pages the script gets a visit ID and puts it where your checkout can read it:

| Where | What |
| --- | --- |
| `<input name="provenance_visit">` | Any such input on the page gets the visit ID, so a form posts it with the order |
| `<html data-provenance-visit>` | The visit ID, for your own script |
| `provenance:visit` event | Sent on `document` with `{ visit_id }` |

Send it as `visit_id` with [`POST /v1/authorize/checkout_assessments`](https://provenanceauth.com/docs/api/assessments.md#post-v1-authorize-checkout-assessments). The assessment reads the visit's class and scores, so your [checkout rules](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md) can ask about them. A visit is read for 24 hours.

## 4. Turn on field timing

Field timing watches how the checkout form is filled in, never what is typed, and turns it into an automation score from 0 to 100. Fast, pasted, pointer-free entry with machine-even key timing scores high; ordinary typing scores low. It is off until you turn it on.

**curl**

```bash
curl -s -X PUT $PROVENANCE_API/v1/identify/settings/site \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "storefront": { "field_timing": true } }'
```

**Node**

```ts
await fetch(`${process.env.PROVENANCE_API}/v1/identify/settings/site`, {
  method: "PUT",
  headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ storefront: { field_timing: true } }),
});
```

**Python**

```python
httpx.put(f"{os.environ['PROVENANCE_API']}/v1/identify/settings/site",
          headers={"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"},
          json={"storefront": {"field_timing": True}})
```

```json
{ "object": "identify_config", "storefront": { "field_timing": true } }
```

Field timing runs only for visitors who allow analytics. When your consent banner records that choice, set `window.provenanceConsent = { analytics: true }` or send a `provenance:consent` event with `{ analytics: true }`; until then nothing timing-related runs or is sent.

At the form's submit the script sends one summary for the visit:

| Measured | How |
| --- | --- |
| Time to fill | First focus on a field to submit, and each field's focus-to-blur time |
| How each value arrived | Typed, pasted or autofilled, from the input events |
| Typing rhythm | The count of key events and the mean and spread of the gaps between them |
| Pointer | Counts of pointer moves, clicks and touches |
| Generated events | Events the browser didn't make itself |

Each field is named by its role only: email, name, phone, address, postal code, note or discount code. Card, password and one-time-code fields are never watched.

## 5. Write rules on it

Your checkout rules read these facts from the visit:

| Fact | Type | What it is |
| --- | --- | --- |
| `agent.automation_score` | number | Field timing's score, 0 to 100 |
| `agent.typed` | boolean | A field was typed in |
| `agent.pointer_seen` | boolean | A pointer moved, clicked or touched |
| `agent.fields_all_pasted` | boolean | Every filled field was pasted |
| `agent.checkout_fill_seconds` | number | First focus to submit, in seconds |
| `agent.typing_interval_ms` | number | The mean gap between key events |

With field timing off, without the visitor's consent, or on a page the script doesn't reach, these facts are absent and their conditions don't match.

> **Note: Field timing never blocks on its own**
>
> A rule whose conditions are all field timing may ask the person or notify you, never reject or hold: the policy write refuses it with `behaviour_only_reject` until you add another condition.

## 6. Know what it sees

The script sees visitors that run the page's scripts: browsers, automated browsers and browser agents. A client that fetches pages without running scripts appears only through its orders. It sets no cookie, uses no storage and reads nothing about the device; addresses follow your Identify retention and pseudonym settings.

Field timing is a hint. Browser autofill and password managers fill fields in a fraction of a second; pasting an address from a note looks like an agent; voice input and other assistive tools produce unusual timing; a shopper on an accelerated checkout fills nothing in and sends no summary. An agent can also add pauses and type key by key. Ask the person on a high score rather than reject, and check the backtest before a rule goes live.

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `403` [`embed_origin_not_allowed`](https://provenanceauth.com/docs/platform/errors.md#embed_origin_not_allowed) | The page's origin isn't in the key's `allowed_origins` | Add your site's origin to the key. |
| `401` [`embed_token_invalid`](https://provenanceauth.com/docs/platform/errors.md#embed_token_invalid) | The key is unknown, revoked or from the other environment | Use a live key on your live site. |
| `recorded: false` with `plan_inactive` | Your trial or allowance ended, so no verdict was made | Upgrade in Billing; the next page view records again. |
| `recorded: false` with `field_timing_off` | Field timing is off | Turn it on (step 4). |
| `404` [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing) on a form submit | The visit isn't a storefront visit of this site, or it's over 24 hours old | Send the visit ID the page view returned. |

## See also

- [Hold Shopify orders](https://provenanceauth.com/docs/authorize/guides/shopify.md): the storefront check through the Provenance app
- [Hold WooCommerce orders](https://provenanceauth.com/docs/authorize/guides/woocommerce.md): server-side checks and the script through the plugin
- [Assess an agent checkout](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md): the checkout rules that read the visit
- [Write a traffic policy](https://provenanceauth.com/docs/identify/guides/traffic-policy.md)
- [Signals and categories](https://provenanceauth.com/docs/identify/reference/signals.md)
