Click tracking
features.clicks counts a listing’s Visit button: 'ping' beacons from the real link,
'redirect' routes through /out/<id>/, 'off' counts nothing. Every listing has a row id, so
it works in every build.
-
Switch it on.
site.config.ts features: { clicks: 'ping' }, -
Deploy with
pnpm deploy. -
Read one listing page’s link.
Terminal curl -s https://<your domain>/<listingBase>/<slug>/ | grep -o 'ping="/out/[^"]*"'ping="/out/<id>/"
-
Switch it on.
site.config.ts features: { clicks: 'redirect' }, -
Deploy with
pnpm deploy. -
Read the link and
robots.txt.Terminal curl -s https://<your domain>/<listingBase>/<slug>/ | grep -o 'href="/docs/out/[^"]*"'curl -s https://<your domain>/robots.txt | grep outhref="/docs/out/<id>/"andDisallow: /out/.
Verify
Section titled “Verify”| What to check | Where | You should see |
|---|---|---|
| The endpoint | curl -sI https://<your domain>/out/<id>/ | head -1 |
HTTP/2 405 in ping mode; HTTP/2 302 in redirect mode |
| A counted click | click Visit in a browser, then pnpm exec wrangler d1 execute DB --remote --command "SELECT listing_id, day, count FROM clicks ORDER BY day DESC LIMIT 5" |
one row per listing per UTC day, count incremented |
| The stats | /admin/stats/ → Top outbound clicks, last 30 days |
the listing and its count |
| Popularity | after the next build, /search/?sort=popularity or any grid |
clicked listings sort first |
Worth knowing
Section titled “Worth knowing”pingkeeps the realhref: a failed write loses the count, not the click.redirectcounts in every browser but sends no dofollow.- Never counted:
HEAD;bot|crawl|spider|slurp|preview|facebookexternalhit|curl|wget; unapproved id (404); wrong content type (400); another origin (403). /admin/stats/is live; sort order moves only at the next build, whose log line is30-day clicks for <n>.- Past the request quota, tracking fails and nothing alerts you.
When it is off or degraded
Section titled “When it is off or degraded”| State | Visitor sees | /admin/ reports |
Fix |
|---|---|---|---|
'off' (the default) |
a plain link; /out/<id>/ answers 404 |
stats: features.clicks is "off", so nothing is counted. |
set the mode |
| Firefox in ping mode | the link works; the beacon is not sent | nothing | accept it, or redirect |
| D1 write fails, or the free-plan quota is spent | ping: 204 and the visitor arrives; the count is lost silently | clicks: recording a click for listing <id> failed in the Worker log |
Cost and limits |
| Redirect mode, the lookup fails | 503 “Try again shortly.” | the lookup’s own log line | retry; consider ping |
Configuration
Section titled “Configuration”features.clicks, listing.defaultSort and listing.outboundRel — features, listing.
Directorysrc/
- server/clicks.ts
handleOutbound(), the guards, the upsert - pages/out/[id].ts the route, every method
Directorycomponents/listing/
- OutLink.astro the anchor in each mode
- Detail.astro where it renders
Directorylib/
- seo.ts
robotsDisallow()adds/out/ - listing.ts
outboundRel(), the sort comparators - search.ts the popularity sort on
/search/
- seo.ts
- loaders/d1.ts the 30-day aggregate at build time
- db/schema.ts
clicks - templates/admin/StatsPage.astro the top-clicks list
- server/clicks.ts
Related
Section titled “Related”SearchThe popularity sort order.
Cost and limitsThe free plan's D1 write budget.
The build's databaseWhich database the build reads, and the credentials a builder needs.
SEODofollow, sponsored and robots.txt.