---
name: prismuv-analytics
description: Complete integration, diagnostics, and telemetry query guide for PrismUV (Self-Hosted Optical Analytics, Fail-Open AdGuard, AI Crawler GEO Radar, Funnels & Release JS Error Sentry). Use whenever adding analytics to a website, setting up Cloudflare Workers first-party /_t proxy, verifying events, querying traffic/funnels/bots/errors via API or MCP, or auditing GEO visibility.
---

# PrismUV Analytics & GEO Skill

Use this skill whenever an AI coding agent or operator wants to:
1. Integrate **PrismUV** tracking into any web project (HTML, Next.js App Router, Vite/SPA, Astro, WordPress, or Cloudflare Workers first-party proxy `/_t/*`).
2. Emit custom conversion funnel events (`tool_run_success`, `tool_download_clicked`, `checkout_start`, etc.) and Fail-Open AdSense protection (`__prismVerdict`).
3. Verify live telemetry end-to-end (`verify-handshake`, `verify-install`, `self-test`).
4. Query real human traffic, bot filtering, AI crawlers, funnels, and JS crashes via **MCP (`prismuv-mcp`)** or **REST API (`/v1/...`)**.

---

## 1. Fastest 1-Line Integration (`<head>`)

Every site registered in PrismUV automatically exposes a canonical pre-configured single-file bundle at `/s/SITE_ID/prismuv.js` (legacy `/p/SITE_ID.js` and `/prismuv.js?site=SITE_ID` also work; no extra inline stub or `data-*` attributes needed for standard installs):

```html
<script defer src="https://PRISMUV_HOST/s/SITE_ID/prismuv.js"></script>
```

That single line automatically sets `site_id`, the beacon API endpoint, live Fail-Open AdGuard mode, optional AdSense auto-loader, SPA route listeners, Core Web Vitals (LCP/INP/CLS), and runtime JS error capture.

### Optional Override `data-*` Attributes (or Generic `/prismuv.js` / `/f.js` Usage)
When overriding defaults or routing via a custom domain:
- `data-release`: Git SHA or version string (e.g. `v2.4.1`) used to pinpoint JS regressions and chart release markers.
- `data-adguard`: `off` | `shadow` (observe without blocking) | `loose` | `balanced` | `strict`. Fail-Open at 300ms timeout.
- `data-adclient`: Optional AdSense client ID (`ca-pub-...`) auto-injected only when traffic passes AdGuard.
- `data-spa`: Default `"true"`. Automatically hooks `history.pushState`, `replaceState`, and `popstate`. Set `"false"` to disable.
- `data-cookieless`: `auto` (default) | `always` | `off`.
- `data-exclude`: Comma-separated path globs to skip (e.g. `/admin/*,/preview/*`).

*(Optional pre-hydration error queue for capturing synchronous `<head>` crashes before deferred JS executes: add `<script>(function(q){window.__eq=q;addEventListener('error',function(e){if(!e.target||e.target===window)q.push(['e',e.message,e.filename,e.lineno,e.colno,e.error&&e.error.stack])})})([])</script>` above `<script defer>`.)*

---

## 2. Recommended AdBlock-Proof Cloudflare Worker Proxy (`/_t/*`)

Routing SDK & beacons through same-origin `/_t/*` bypasses ~99% of script blockers AND forwards edge GEO/ASN headers (`X-Prism-Country`, `X-Prism-Region`, `X-Prism-City`, `X-Prism-ASN`, `X-Prism-ASN-Org`, `X-Prism-Client-IP`) + non-blocking AI/Search crawler hits (`GPTBot`, `OAI-SearchBot`, `ClaudeBot`, `PerplexityBot`, `Googlebot`) to `/t/edge`:

- `wrangler.jsonc`: `"vars": { "PRISMUV_UPSTREAM": "https://PRISMUV_HOST" }`
- Worker Secret: `npx wrangler secret put PRISMUV_EDGE_SECRET` (must match `EDGE_INGEST_SECRET` on PrismUV API)
- `/_t/f.js` -> `${PRISMUV_UPSTREAM}/f.js` (NOT `/s/SITE_ID/prismuv.js`, so explicit `data-api="/_t"` stays first-party)
- `/_t/in` -> `${PRISMUV_UPSTREAM}/t/in`
- `/_t/v` -> `${PRISMUV_UPSTREAM}/t/v` (350ms timeout, returns fail-open `{ allow_ads: true }` on error)
- `/_t/err` -> `${PRISMUV_UPSTREAM}/t/err`
- Crawler fetches (`GPTBot`, `ClaudeBot`, `PerplexityBot`, etc.) -> `ctx.waitUntil(fetch(${PRISMUV_UPSTREAM}/t/edge))` with `X-Prism-Edge-Secret`.

When proxied on `/_t/*`, set the `<script>` tag to:
```html
<script defer src="/_t/f.js" data-site="SITE_ID" data-api="/_t" data-release="RELEASE_SHA" data-adguard="shadow"></script>
```
**Post-deploy check**: if `PRISMUV_UPSTREAM` is unset, the Worker returns a ~192B `fail_open` stub and drops telemetry. Verify `/_t/f.js` serves the >= 1KB live SDK without `window.pvuv.track=function(){}` or `mode:'fail_open'`.

---

## 3. Custom Funnel & Revenue Events API

Call anywhere in frontend JavaScript:

```ts
// Track a tool execution or signup conversion
window.pvuv?.('event', 'tool_run_success', { tool: 'image-compressor', format: 'webp' });

// Track a revenue goal (USD)
window.pvuv?.('event', 'pro_upgrade', { revenue: 19.0, plan: 'pro' });

// Tie anonymous visitor to authenticated user ID
window.pvuv?.('identify', user.id, { plan: 'pro' });

// Read PrismUV visitor ID for Creem / Stripe Checkout metadata attribution (RPV)
const prismVid = window.pvuv?.vid?.();
```

Check Fail-Open AdGuard status in React components:
```ts
const allowAds = window.__prismVerdict ? (window.__prismVerdict.shadow || window.__prismVerdict.allow_ads !== false) : true;
```

---

## 4. Open REST API & MCP Usage for AI Agents (36 MCP Tools)

All `/v1/*` endpoints accept a scoped read/write Bearer token (`prism_live_...`) created under **Settings -> API Tokens**:

- `GET /v1/sites` — List sites
- `POST /v1/sites` — Register a new site programmatically (requires write token or session)
- `GET /v1/sites/{site_id}/realtime` — Last 30 minutes live traffic, minute pulse & recent hits
- `GET /v1/sites/{site_id}/overview?period=7d` — Clean UV, Raw PV, Purity %, Conversion Rate, Edge AI Crawls, Open JS Errors
- `GET /v1/sites/{site_id}/geo?period=7d` — Country breakdown (clean UV / crawls / bots)
- `GET /v1/sites/{site_id}/pages?period=7d` — Top pages with dwell, scroll depth & goal conversions
- `GET /v1/sites/{site_id}/breakdown?period=7d&dim=channel|source|country|device|browser|os|utm_campaign|entry_page|exit_page|ai_ref|goal`
- `GET /v1/sites/{site_id}/funnels` & `GET /v1/sites/{site_id}/funnels/{funnel_id}/report?period=7d`
- `GET /v1/sites/{site_id}/quality?period=7d` — Bot score distribution, fired signals, suspicious sessions
- `GET /v1/sites/{site_id}/crawlers?period=7d` — AI Edge crawlers + ChatGPT/Perplexity/Claude human referral conversions
- `GET /v1/sites/{site_id}/geo/audits`, `POST /v1/sites/{site_id}/geo/audit`, `POST /v1/sites/{site_id}/geo/audit-sitemap` — Live 100-pt GEO citability & site-wide sitemap batch crawler
- `GET /v1/sites/{site_id}/ai-visibility/summary`, `POST /v1/sites/{site_id}/ai-visibility/prompts`, `POST /v1/sites/{site_id}/ai-visibility/auto-seed`, `POST /v1/sites/{site_id}/ai-visibility/check` — Google AI Overview (`DataForSEO load_async_ai_overview`) & ChatGPT Web Search citation Share-of-Voice tracker
- `GET /v1/sites/{site_id}/keywords?period=30d`, `POST /v1/sites/{site_id}/keywords`, `POST /v1/sites/{site_id}/keywords/check`, `POST /v1/sites/{site_id}/keywords/discover`, `POST /v1/sites/{site_id}/keywords/pull-ranked`, `POST /v1/sites/{site_id}/keywords/enrich` — DataForSEO volume/CPC, Serper Google rank & on-page keyword monitor
- `GET /v1/sites/{site_id}/gsc/queries`, `POST /v1/sites/{site_id}/gsc/sync` — Google Search Console incoming queries correlated with clean human conversions
- `GET /v1/sites/{site_id}/errors?period=7d` — Release-grouped JS errors & P75 LCP/INP/CLS
- `GET /v1/billing/status`, `POST /v1/billing/checkout` & `POST /v1/billing/portal` — Workspace plan quotas & Creem/Stripe billing
- `GET /v1/sites/{site_id}/revenue/summary?period=30d` & `POST /t/pay/{site_id}/creem|stripe` — Native Creem/Stripe payment webhook attribution & RPV
- `GET /v1/sites/{site_id}/keywords/{keyword_id}/history?days=30` & `GET /v1/sites/{site_id}/geo/trend?days=90` — 30/90d rank & GEO score trends with release markers
- `POST /v1/sites/{site_id}/verify-install` — Live HTML tag & SDK bundle validator (detects Cloudflare Worker `fail_open` stubs; returns `sdk_live`, `sdk_fail_open`, `sdk_url`, `sdk_status_code`)
- `GET /v1/sites/{site_id}/copilot/tasks`, `POST /v1/sites/{site_id}/copilot/generate`, `PATCH /v1/sites/{site_id}/copilot/tasks/{task_id}` — Growth Copilot P0–P2 action plan & Before/After impact tracking
- `POST /v1/sites/{site_id}/copilot/generate-assets` — Generate deployable `llms.txt`, `llms-full.txt`, `FAQPage` JSON-LD & `SoftwareApplication` JSON-LD
- `POST /v1/sites/{site_id}/self-test` — 6-point infrastructure & ingestion diagnostic check

### Connect PrismUV MCP (`prismuv-mcp`)
Add to Claude Code (`~/.claude.json`), Cursor, or Codex MCP config:
```json
{
  "mcpServers": {
    "prismuv": {
      "command": "node",
      "args": ["/path/to/prismuv/mcp/index.mjs"],
      "env": {
        "PRISMUV_API_URL": "https://PRISMUV_HOST",
        "PRISMUV_TOKEN": "prism_live_..."
      }
    }
  }
}
```
