How it works
The worker attaches to one or more routes and acts as a pass-through proxy:- A visitor requests a page that matches a configured route (for example,
example.com/*). - The worker forwards the original request to your origin and returns the response immediately.
- In parallel, the worker sends a page visit event to The Prompting Company. This happens in the background, so it never delays the response to the visitor.
Before you start
You will need:- A Cloudflare account with the domain you want to track added as a zone.
- A TPC API key with the
analytics:writescope. You can create an API key with theanalytics:writescope going to your Organization Settings, then selecting API Keys. Note that creating an API key requires an account with the Enterprise Plan. - The
cf-collectorfolder from the samples repository
Step 1: Install dependencies
From thecf-collector directory, install the dependencies:
Step 2: Set your API key
The API key is stored as an encrypted Wrangler secret, not in the config file. Set it by running:Step 3: Configure your routes
Edit theroutes array in wrangler.jsonc to match the pages you want to track. Set the pattern to your domain and the zone_name to the matching Cloudflare zone:
wrangler.jsonc
Step 4: Deploy
To deploy the worker to Cloudflare, run:Troubleshooting
Events are not appearing
- Confirm the request URL matches a
patternin yourroutesarray, including the correctzone_name. - Make sure the
TPC_API_KEYsecret is set for the environment you deployed to (npx wrangler secret list). - Verify the worker is deployed and bound to the route in the Cloudflare dashboard under Workers & Pages.