Skip to content

Add agent-commerce-analytics-template: merchant dashboard for AI agent traffic#971

Open
mconroy-cf wants to merge 3 commits intocloudflare:mainfrom
mconroy-cf:add-agent-commerce-analytics-template
Open

Add agent-commerce-analytics-template: merchant dashboard for AI agent traffic#971
mconroy-cf wants to merge 3 commits intocloudflare:mainfrom
mconroy-cf:add-agent-commerce-analytics-template

Conversation

@mconroy-cf
Copy link
Copy Markdown

Summary

Adds agent-commerce-analytics-template — a merchant-facing analytics dashboard for AI shopping agents. Tracks the full discover → browse → purchase journey per agent, payment network, and verification status, and surfaces auto-generated insights (top agent, product gaps, blocked checkouts, repeat visitors) in a React SPA at /.

Pairs with commerce-llms-txt-template on the visibility side — where commerce-llms-txt makes a merchant's catalog agent-readable, this template gives the merchant visibility into what the agents are actually doing.

What's in the template

  • Worker at src/analytics-worker/index.ts serving /api/dashboard{,/funnel,/agents,/products}, /api/events{,/batch,/from-headers}, and an /api docs endpoint.
  • React + Vite SPA at src/react-app/ via @cloudflare/vite-plugin — funnel, agent table, per-agent journey timelines, product performance, headline cards, and a before/after comparison with generic zone analytics.
  • Required EVENT_STORE KV binding with a placeholder ID in wrangler.jsonc. Events persist under event:<reversed-timestamp>:<random> so list() returns newest-first without a sort step; per-event TTL is controlled by EVENT_RETENTION_DAYS.
  • DELETE /api/events is gated behind an optional ADMIN_TOKEN secret; disabled (403) when the secret isn't set.
  • Batch ingestion capped at 500 events, with KV writes/deletes chunked to stay well under the Workers subrequest limit.
  • Bundled demo seed (5 agents, ~19 events) seeded once via a long-TTL KV marker so the dashboard is populated the moment you deploy. Disable with SEED_DEMO_DATA=false.
  • 10 vitest tests via @cloudflare/vitest-pool-workers, including coverage for the admin-token gate.
  • Playwright E2E spec at playwright-tests/agent-commerce-analytics-template.spec.ts.

Applying feedback from #968

Both new templates pre-apply the KV-required + SPA-on-top-of-API feedback from #968.

Verification

  • pnpm turbo run check --filter=agent-commerce-analytics-template — passes
  • pnpm turbo run test --filter=agent-commerce-analytics-template — 10/10 passing
  • pnpm run check:templates — passes
  • pnpm run check:prettier — clean

Merchant-facing analytics dashboard for AI shopping agents. Tracks the full
discover -> browse -> purchase journey per agent, payment network, and
verification status, and surfaces auto-generated insights (top agent, product
gaps, blocked checkouts, repeat visitors) in a React SPA at /.

- Required EVENT_STORE KV binding; events keyed with reversed-timestamp
  prefix so list() returns newest-first without a sort step
- @cloudflare/vite-plugin pattern: SPA at /, Worker owns /api/*
- DELETE /api/events is gated behind an optional ADMIN_TOKEN secret
  (403 when the secret isn't set)
- Batch ingestion capped at 500 events, KV writes/deletes chunked to
  stay well under the Workers subrequest limit
- Bundled demo seed (5 agents, 19 events) on first dashboard request via a
  long-TTL KV marker; disabled with SEED_DEMO_DATA=false
- 10 vitest tests via @cloudflare/vitest-pool-workers
- Playwright e2e spec under playwright-tests/

Registered in templates.json.
Copy link
Copy Markdown
Contributor

@deloreyj deloreyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — smoke-tested the worker locally and the analytics pipeline all works (seed data populates, event ingestion writes, admin-token gate behaves correctly). Several things to address before merge:

  • Missing Deploy to Cloudflare button in README.mdvalidate-d2c-buttons will fail CI. Add this at the very top:
    [![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/templates/tree/main/agent-commerce-analytics-template)
  • No <!-- dash-content-start --> / <!-- dash-content-end --> markers — without them, the Cloudflare Dashboard template gallery won't have a blurb to show. Wrap a short overview section (probably a tightened version of "What This Does") in the markers.
  • README.md:66-74 references scripts that don't existnpm run walkthrough, simulate, and dashboard aren't in package.json, so users will hit Unknown script. Either add them or remove from the README.
  • gitlab.cfdata.org links 404 for external viewers — the "Part of the agent-commerce portfolio" note at the top and the table at the bottom. Describe the portfolio inline or link only to public pieces.
  • Live dashboard: points at mattrc07.workers.dev — once the Cloudflare team provisions the live demo, it'll be at https://agent-commerce-analytics-template.templates.workers.dev. Update it then, or drop the line for now.

- Add Deploy to Cloudflare button at the top so validate-d2c-buttons passes
- Wrap overview blurb in dash-content-start/end markers for the dashboard gallery
- Replace Quick Start with the scripts that actually exist in package.json
- Drop gitlab.cfdata.org links (404 for external viewers) and describe the portfolio inline
- Drop the mattrc07.workers.dev live dashboard line; the provisioned URL can replace it later
@mconroy-cf
Copy link
Copy Markdown
Author

Thank you for the feedback, James! Made the desired changes

Captures the four trust signals merchants triage on (Web Bot Auth, signed-agents
managed list, KYA token, UA-only) on every event, derives a verified /
claimed-only / unverified tier, and exposes the rollup at GET /dashboard/trust.

The 'verified: boolean' field is preserved for back-compat with existing
dashboards/clients; new code consumes 'trustSignals.trustTier'. The
POST /events/from-headers endpoint now derives signals automatically from
request headers, so deploying behind a Worker that already runs Web Bot Auth
or a KYA-emitting Managed Ruleset just works.

README updated with a 'Trust signals' section explaining the four signals,
the three-tier rollup, and which header inputs each derives from.

Verification:
  - pnpm run check:templates    pass
  - pnpm run check:prettier     pass
  - pnpm test                   10/10 pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants