Skip to main content
Prerequisites

Install

Cloudflare clones the repo and sets up the worker.
1

Deploy worker

Deploy to Cloudflare
2

Route it over your site

Domains → Add Route, e.g. example.com/*.
Use Worker Routes, not Custom Domains: a Custom Domain replaces your origin and breaks the proxy.
You can reduce the number of requests to your worker by excluding assets, see Reducing Worker invocations.

Install (manual)

1

Setup

2

Add tinytrack websiteId secret

3

Deploy

4

Cloudflare configuration

Workers & Pages → tinytrack-cloudflare-worker → Domains → Add Route, e.g. example.com/*, covering the whole site.

Reducing Worker Invocations

A example.com/* route sends every request through the worker, including assets it just passes through. The worker only needs to see HTML document requests and /_tinytrack/*. To stop paying invocations for the rest, add routes with the Worker set to None for your high-volume static prefixes. To add exclusions:
1

Open your domains

Go to Cloudflare → Domains.
2

Select your domain

Select your domain, such as example.com.
3

Open Workers routes

Go to Workers routes.
4

Add an exclusion route

Click Add Route and enter the route you want to exclude.
5

Set the Worker to None

Set Worker to None.
Route patterns match path prefixes only (no file extensions) and a route without a Worker negates broader patterns, see the Workers routes docs. Example exclusions:
  • example.com/_app/immutable/* (SvelteKit)
  • example.com/_next/static/* (Next.js)
  • example.com/assets/*
  • example.com/static/*
  • example.com/images/*
  • example.com/api/*

How It Works

The Worker runs on a Cloudflare route that covers your site. For each request it:
  • Counts one page_view per HTML document request, server-side at the edge.
  • Injects the TinyTrack script into the HTML response, so your source stays untouched.
  • Serves the tracker from /_tinytrack/tracker.js and takes client events at /_tinytrack/track, first-party on your own domain.

Configuration

string
required
Your TinyTrack website ID, from Settings → Tracking. Public by design — it is embedded in the injected script.
string
The domain events are attributed to. Defaults to the request hostname with www. stripped. Set it explicitly when your route spans multiple subdomains, otherwise sessions split across them.
string
default:"true"
Whether the worker injects the TinyTrack script into HTML responses. Set to "false" for server-side pageviews only.
string
default:"/_tinytrack"
The first-party path prefix the worker serves itself: the tracker at <prefix>/tracker.js and client events at <prefix>/track.
string
default:"false"
Set to "true" for step-by-step debug logs on HTML document requests, visible via npx wrangler tail.
Only TINYTRACK_WEBSITE_ID is declared in wrangler.jsonc, so it is the only field shown on the one-click deploy setup page. The optional vars fall back to the defaults above; to override one, add it in Workers & Pages → Settings → Variables (kept across deploys, the config sets keep_vars) or to the vars block in wrangler.jsonc.
Already have the TinyTrack script in your HTML? Remove it, or set INJECT_SCRIPT to "false". Running both causes duplicate client-side events.

What Gets Tracked

  • Server-side: one page_view per HTML request (any status). Static assets, /api/-style paths, prefetches, and non-GET requests are skipped.
  • Client-side: SPA navigations, outbound clicks, goals, scroll depth, session pings, custom events. The injected script skips the initial pageview, so there is no double counting.
  • Bots are recorded for crawler and AI traffic analytics.

Troubleshooting

  • npx wrangler tail shows live logs; pageview failures log as [TinyTrack] pageview tracking failed.
  • No data? Check the route covers the page and TINYTRACK_WEBSITE_ID is set.
  • Client events missing? Check the browser console for /_tinytrack/tracker.js (usually CSP or a leftover manual snippet).

Uninstall

Remove the Worker Route and your site instantly serves direct from origin. Then npx wrangler delete when done. Roll back a bad deploy from Workers & Pages → Deployments → Rollback.