Skip to main content
All Integrations/Stack Guide · First-Party /_t Proxy + Edge Telemetry·Setup time: 4 minutes

Cloudflare Workers First-Party /_t Proxy, AI Crawler Beacon & Fail-Open Guide

Architecture Summary

Serving analytics from `/_t/f.js` on your own domain eliminates third-party ad-blocker blind spots while logging every `OAI-SearchBot`, `GPTBot`, `ClaudeBot`, `Claude-SearchBot`, and `PerplexityBot` edge hit via `ctx.waitUntil()`. Configure strictly fail-open timeouts so upstream issues never interrupt your site.

First-party `/_t/f.js`, `/_t/in`, `/_t/v`, `/_t/err` routing on your apex domain
Non-blocking `ctx.waitUntil()` AI crawler logging to `/t/edge` using `PRISMUV_EDGE_SECRET`
Zero-impact fail-open behavior (if upstream times out, Worker returns empty HTTP 204)
Works seamlessly with static Cloudflare Cache Rules (`CF-Cache-Status: HIT`)

1. Configure Worker Secrets & Environment Variables

Copy your site-scoped `PRISMUV_EDGE_SECRET` (`pve_...`) from PrismUV Dashboard -> Install & Export -> Site Credentials, and store it securely using Wrangler.

wrangler.toml + secret setup
# Store per-site edge secret cleanly (never hardcode in Git)
npx wrangler secret put PRISMUV_EDGE_SECRET

# wrangler.toml [vars]
[vars]
PRISMUV_UPSTREAM = "https://prismuv.com"
PRISMUV_SITE_ID = "YOUR_SITE_ID"

2. Mount the Fail-Open /_t/* Proxy & AI Crawler Beacon

Handle `/_t/*` first-party requests by proxying cleanly with strict header forwarding (`CF-Connecting-IP`, `CF-IPCountry`), and enqueue non-blocking `/t/edge` logs when AI/Search bots request HTML or `/llms*.txt` documents.

worker/index.ts
const BOT_RE = /(oai-searchbot|chatgpt-user|gptbot|claudebot|claude-searchbot|claude-user|perplexitybot|googlebot|bingbot)/i;

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    const url = new URL(request.url);

    // 1. First-party /_t/* proxy
    if (url.pathname.startsWith('/_t/')) {
      const upstreamPath = url.pathname.replace(/^\/_t/, '');
      const target = new URL(upstreamPath + url.search, env.PRISMUV_UPSTREAM);
      try {
        const resp = await fetch(target.toString(), {
          method: request.method,
          headers: request.headers,
          body: request.method === 'GET' || request.method === 'HEAD' ? undefined : request.body,
        });
        return resp;
      } catch {
        return new Response(null, { status: 204 }); // Fail-open
      }
    }

    // 2. Serve origin / static assets and log AI crawlers without blocking TTFB
    const response = await env.ASSETS.fetch(request);
    const ua = request.headers.get('user-agent') || '';
    if (ua && BOT_RE.test(ua) && response.status < 400) {
      ctx.waitUntil(
        fetch(`${env.PRISMUV_UPSTREAM}/t/edge`, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            'X-Prism-Edge-Secret': env.PRISMUV_EDGE_SECRET || '',
          },
          body: JSON.stringify({
            site_id: env.PRISMUV_SITE_ID,
            path: url.pathname,
            status_code: response.status,
            ua: ua.slice(0, 300),
            country: request.headers.get('cf-ipcountry') || '',
            ip: request.headers.get('cf-connecting-ip') || '',
          }),
        }).catch(() => {})
      );
    }
    return response;
  },
};

3. Reference the First-Party Script in HTML

Load `/_t/f.js` from your own apex origin with `data-site` pointing to your site ID and `data-endpoint="/_t"` so zero cross-origin analytics calls appear.

Root Layout <head>
<script
  defer
  src="/_t/f.js"
  data-site="YOUR_SITE_ID"
  data-endpoint="/_t"
  data-release="v1.0.0"
></script>

Common Production Pitfalls to Avoid

  • Never wrap `/_t/f.js` with a hardcoded dummy fail-open stub returning `window.pvuv=function(){}`—real analytics drops cleanly if it proxies upstream directly or falls back only on network exception.
  • Exclude `/_t/*` inside your site Service Worker (`public/sw.js`) with an immediate `if (url.pathname.startsWith("/_t/")) return;` guard so offline caches never hijack live beacons.
  • Ensure `/robots.txt` allows AI search crawlers (`OAI-SearchBot`, `Claude-SearchBot`, `PerplexityBot`) while keeping `private` or `/_t/` paths isolated as intended.

Instant Verification Check

Verify live header delivery and crawler visibility right after deploying:

curl -sI https://yourdomain.com/_t/f.js && curl -A "OAI-SearchBot/1.0" -sI https://yourdomain.com/

Cloudflare Workers & Edge Proxy Integration FAQ

Does proxying through Cloudflare Workers add noticeable latency for human visitors?

No. Because `/_t/f.js` loads with `defer` alongside global edge POP caching, critical LCP rendering finishes untouched.

Do I still pay Cloudflare Workers fees on high traffic?

Cloudflare Workers’ Free tier includes 100,000 requests/day, and Workers Paid ($5/mo) handles 10M+ requests—plenty for nearly all SaaS & utility tool hubs.

Why must public/sw.js explicitly bypass /_t/* routes?

If a Service Worker caches `/_t/v` or `/_t/in` responses offline or strips POST bodies, telemetry and AdGuard checks misfire. A single early `return;` keeps beacons network-only.

What does ctx.waitUntil() do if /t/edge takes 100ms to respond?

Not at all—`ctx.waitUntil()` resolves asynchronously after the origin HTML response has already streamed back to the crawler.

Can Cloudflare Workers preserve visitor country and real client IP for SHA-256 hashing?

Yes—forwarding `CF-Connecting-IP` and `CF-IPCountry` lets PrismUV hash daily rotating `ip_hash` accurately without ever saving raw IPs.

What triggers if Cloudflare Edge Cache returns CF-Cache-Status: HIT?

Yes—when the Cloudflare Worker runs in front of your asset/route pipeline before cache returns, `ctx.waitUntil()` captures every cache HIT sweep by `Googlebot`, `OAI-SearchBot`, and `ClaudeBot`.