# Show a traffic result

Show one visit Identify's hosted check assessed to your staff inside your own admin tool with <provenance-traffic-result>, keep its session alive with getToken(), and put your own next step beside it.

`<provenance-traffic-result>` shows one visit Identify's hosted check assessed (a [traffic assessment](https://provenanceauth.com/docs/identify/concepts/traffic-assessment.md)) to your staff, inside your own admin tool: the outcome, who visited and whether the agent signed the request, the bot likelihood with the signals behind it, and the rule that decided. Every row is one line, with a dot and a word. Beside it, a slot holds your own next step; Provenance shows the facts and never picks the action.

**Before you begin:** a publishable key (see [embeds](https://provenanceauth.com/docs/embeds.md#1-create-a-publishable-key)) and a secret key with the `identify` scope. The embed needs Pro or the Free trial; the same rows show on the console's **Traffic** page on every plan.

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

## 1. Mint a session on your server

Your server mints a short session for one visit with [`POST /v1/embed/tokens`](https://provenanceauth.com/docs/api/embeds.md#post-v1-embed-tokens), `widget: "traffic_result"` and the assessment's ID. Put it behind a route your admin page calls, after your own sign-in check:

In the SDK tabs, `prov` (Node, Python) and `embed` (Go) are your server-side clients, set up as in [admin results and requests](https://provenanceauth.com/docs/embeds/admin-tools.md#3-mint-a-session-for-an-embed).

**curl**

```bash
curl -s -X POST $PROVENANCE_API/v1/embed/tokens \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "widget": "traffic_result", "object_id": "tas_01M7P2K8D3QJ6V4ZB9XWN5T1RA", "ttl": 900 }'
```

**Node**

```ts
// GET /admin/provenance/session?visit=tas_01M7… (your route, behind your staff sign-in)
const session = await prov.embed.createToken({ widget: "traffic_result", objectId: visitId, ttl: 900 });
res.json({ token: session.embedToken });
```

**Python**

```python
token = prov.embed.create_token(widget="traffic_result", object_id=visit_id, ttl=900)["embed_token"]
```

**Go**

```go
session, err := embed.CreateToken(ctx, pv.EmbedTokenParams{Widget: pv.WidgetTrafficResult, ObjectID: visitID, TTL: 900})
```

| Field | What it does |
| --- | --- |
| `object_id` | One traffic assessment (`tas_…`) from your hosted checks. Another kind of ID is `400` [`embed_object_kind_mismatch`](https://provenanceauth.com/docs/platform/errors.md#embed_object_kind_mismatch); a middleware report or another account's assessment is `404`. |
| `ttl` | Seconds, up to 900 (15 minutes). |

A key without the `identify` scope gets `403` [`insufficient_scope`](https://provenanceauth.com/docs/platform/errors.md#insufficient_scope). A copied session opens only this visit, and only until it expires. For a phone, mint a [hosted page link](https://provenanceauth.com/docs/embeds/hosted-page.md) with the same body instead.

## 2. Drop the element in your page

```bash
npm install @provenance/embed
```

```html
<script type="module" src="https://unpkg.com/@provenance/embed"></script>

<provenance-traffic-result base-url="https://sandbox-api.provenanceauth.com" publishable-key="prv_pub_1D10TzJo8F73Z7ZHhWGKPpn0K7suJ0se" theme="inherit">
  <div slot="actions"><button id="block-agent" hidden>Block this agent</button></div>
</provenance-traffic-result>

<script>
  const el = document.querySelector("provenance-traffic-result");
  el.getToken = async () => (await (await fetch("/admin/provenance/session?visit=tas_01M7P2K8D3QJ6V4ZB9XWN5T1RA")).json()).token;
</script>
```

The element calls `getToken()` on load and one minute before each session ends, and swaps the new session in place. If your server can't answer, it says **Session ended** with **Reload** and fires `pv:token_refresh_failed`. See [capture result in your admin](https://provenanceauth.com/docs/embeds/capture-result.md#3-keep-the-session-alive-with-gettoken) for the details; they're the same here. To show the visit a [traffic list](https://provenanceauth.com/docs/embeds/traffic-list.md) selected, set `for` to the list's `id`.

In React:

```tsx
import { ProvenanceTrafficResult } from "@provenance/embed/react";

<ProvenanceTrafficResult
  baseUrl={process.env.NEXT_PUBLIC_PROVENANCE_API!}
  publishableKey="prv_pub_1D10TzJo8F73Z7ZHhWGKPpn0K7suJ0se"
  getToken={async () => (await (await fetch(`/admin/provenance/session?visit=${visitId}`)).json()).token}
  onResult={(r) => setResult(r)}
>
  <BlockAgent result={result} />
</ProvenanceTrafficResult>;
```

## 3. Put your own next step in the slot

The `actions` slot is yours. Decide what to show from `pv:result`, which carries enums only:

```js
el.addEventListener("pv:result", (e) => {
  const { outcome } = e.detail;
  // Your rule, in your code: offer a block on a visit your rules allowed.
  document.querySelector("#block-agent").hidden = outcome !== "allow";
});
```

| Detail | Values |
| --- | --- |
| `status`, `outcome` | The visit's decision: `allow`, `block`, `challenge`, `log_only`, `rate_limit` or `require_intent` |

The slot can't cover or restyle the status line, the bot likelihood, the signature line, the rule's action or the "Powered by Provenance" foot.

## What it shows

Each row, and where it comes from in [`GET /v1/identify/assessments/{id}`](https://provenanceauth.com/docs/api/traffic-checks.md#get-v1-identify-assessments-id):

| Row | Example | From |
| --- | --- | --- |
| Status line | Rejected · Posts to checkout, POST /checkout | `decision.action`, `policy.rule.name`, `request.method` and `request.path` |
| Visitor | Suspected bot, Acme Shopper, Shopping agent | `class`, `agent.operator`, `agent.category` |
| Signature | Signed and verified, or Not signed | `agent.verified` |
| Person | Backed by a person | `human.backed` |
| Bot likelihood | High, or Unclassified with why | `bot_likelihood` and `bot_likelihood_reason` |
| Bot score | 80 of 100 | `bot_score` |
| Signal | Headless browser, Hosting address, Typed in a field | `signals[].code`, and field timing's typed and pointer flags |
| Deciding rule | Posts to checkout · Reject, each condition with the value it compared | `policy.rule.name`, `policy.rule.action`, `policy.rule.conditions[]` (`actual`) |

The status line says what Identify did to the request in the [visit words](https://provenanceauth.com/docs/embeds/traffic-list.md#visit-words): Allowed, Challenged or Rejected. The deciding rule's action reads in the rule builder's words (Allow, Challenge, Reject). Signals show by name only, never timings. A visit no rule decided shows no rule section.

The element never gets the address, a header, the user agent string, timing values, a pseudonym, an intent or any ID but the visit's. To see what it gets, call `GET /v1/embed/traffic_result` with the session. A visit that can't be read shows that it's unavailable, never a made-up result.

## Events

| Event | When | Detail |
| --- | --- | --- |
| `pv:ready` | The session opened | `widget`, `object_id`, `mode` |
| `pv:result` | First read | `kind: "traffic"`, `status`, `outcome` |
| `pv:token_refresh_failed` | `getToken()` couldn't renew the session | `widget` |
| `pv:error` | The element couldn't start | `code`, `message` |

## Embed, console or your own

|  | This embed | The console | Your own UI on the API |
| --- | --- | --- | --- |
| Where | Your admin tool | **Identify › Traffic**, Hosted checks | Anywhere you like |
| Plan | Pro, or the Free trial | Every plan | Every plan |
| Work | Mint a session, drop the tag | None | Read the assessment, map the words |

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `400` [`embed_object_kind_mismatch`](https://provenanceauth.com/docs/platform/errors.md#embed_object_kind_mismatch) | The ID isn't a traffic assessment | Pass the `tas_…` ID. |
| `403` [`insufficient_scope`](https://provenanceauth.com/docs/platform/errors.md#insufficient_scope) | The key has no `identify` scope | Mint with an Identify key. |
| `401` [`embed_token_invalid`](https://provenanceauth.com/docs/platform/errors.md#embed_token_invalid) | The session expired, or the assessment is past its retention | Mint a new one, or give the element `getToken()`. |
| `503` [`embed_result_unavailable`](https://provenanceauth.com/docs/platform/errors.md#embed_result_unavailable) | The visit couldn't be read | Retry shortly. |

## See also

- [Embeds](https://provenanceauth.com/docs/embeds.md)
- [Traffic list in your admin](https://provenanceauth.com/docs/embeds/traffic-list.md)
- [Traffic assessment](https://provenanceauth.com/docs/identify/concepts/traffic-assessment.md)
- [Admin results and requests](https://provenanceauth.com/docs/embeds/admin-tools.md)
