Links/redirects: /go/ short links with click counts, Plausible and UTM tags (migration 068)

Data > Links/redirects (editors and up) makes short links on our
domain. GET /go/<id> counts the click, reports it to Plausible as a
pageview of /go/<id> (the visitor's browser and address, no key
needed), and redirects (302, no-store) with the link's UTM tags added
to the destination. Unknown ids fall through to the not-found page.
The editor can show a fixed lead-in in the URL ID box (idPrefix).
Vite proxies /go in dev. docs/redirects.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-10-05 00:37:26 -05:00
parent 3fafd7f92c
commit 6289e7203f
13 changed files with 284 additions and 4 deletions

View file

@ -0,0 +1,32 @@
-- ═══════════════════════════════════════════════════════════════
-- 068 REDIRECTS
--
-- Short links on our own domain (Data → Links/redirects), eg.
-- /go/retreat-signup, for the newsletter and anywhere else a link
-- should be counted. routes/redirects.js answers /go/<id>: it counts
-- the click here, tells Plausible about it, and sends the visitor on
-- with the link's UTM tags added.
--
-- target_url where it goes: a web address, or a path on this
-- site starting with /
-- utm_* added to the destination's query, when set
-- clicks, kept by the redirect route, not the editor
-- last_clicked_at
-- ═══════════════════════════════════════════════════════════════
CREATE TABLE redirects (
id TEXT PRIMARY KEY
CONSTRAINT "A redirect's URL ID can use only lowercase letters, numbers and hyphens, eg. retreat-signup."
CHECK (id <> '' AND id NOT GLOB '*[^a-z0-9-]*'),
target_url TEXT NOT NULL
CONSTRAINT "A redirect goes to a web address (https://...) or a path on this site starting with /."
CHECK (target_url GLOB 'https://?*' OR target_url GLOB 'http://?*'
OR (target_url GLOB '/*' AND target_url NOT GLOB '//*')),
note TEXT, -- what it's for, admin only
utm_source TEXT, -- 'newsletter'
utm_medium TEXT, -- 'email'
utm_campaign TEXT, -- 'october-2026'
clicks INTEGER NOT NULL DEFAULT 0,
last_clicked_at TEXT,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
) STRICT;