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:
parent
3fafd7f92c
commit
6289e7203f
13 changed files with 284 additions and 4 deletions
|
|
@ -29,6 +29,7 @@ import { blogPosts } from "./adminSchema/blog.ts";
|
|||
import { siteSettings } from "./adminSchema/siteSettings.ts";
|
||||
import { personTagTypes } from "./adminSchema/personTags.ts";
|
||||
import { contactTypes } from "./adminSchema/contactTypes.ts";
|
||||
import { redirects } from "./adminSchema/redirects.ts";
|
||||
import {
|
||||
communityPage,
|
||||
retreatsPage,
|
||||
|
|
@ -43,6 +44,7 @@ export const ADMIN_ENTITIES: Record<string, any> = {
|
|||
people,
|
||||
person_tag_types: personTagTypes,
|
||||
contact_types: contactTypes,
|
||||
redirects,
|
||||
teams,
|
||||
awards,
|
||||
timeline,
|
||||
|
|
|
|||
53
src/lib/adminSchema/redirects.ts
Normal file
53
src/lib/adminSchema/redirects.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* ── Links/redirects (068_redirects.sql) ─────────────────────────
|
||||
Data → Links/redirects: short links on our own domain, /go/<URL ID>,
|
||||
for the newsletter and anywhere a link should be counted. Each
|
||||
click is counted here, sent to Plausible as a pageview of
|
||||
/go/<URL ID>, and passed on with the link's UTM tags. Server side:
|
||||
server/src/admin-schema/redirects.js and routes/redirects.js. */
|
||||
|
||||
import { SITE_ORIGIN } from "../site.ts";
|
||||
|
||||
const GO = `${SITE_ORIGIN.replace(/^https?:\/\//, "").replace(/\/$/, "")}/go/`;
|
||||
|
||||
export const redirects = {
|
||||
key: "redirects",
|
||||
label: "Links/redirects",
|
||||
singular: "redirect",
|
||||
idLabel: "URL ID",
|
||||
idPrefix: GO,
|
||||
|
||||
list: {
|
||||
columns: [
|
||||
{ key: "id", label: "Link", primary: true },
|
||||
{ key: "target_url", label: "Goes to" },
|
||||
{ key: "clicks", label: "Clicks" },
|
||||
{ key: "last_clicked_at", label: "Last click" },
|
||||
],
|
||||
filters: [],
|
||||
},
|
||||
|
||||
groups: [
|
||||
{
|
||||
legend: "Redirect",
|
||||
fields: [
|
||||
{
|
||||
path: "target_url",
|
||||
label: "Goes to",
|
||||
required: true,
|
||||
full: true,
|
||||
help: "A web address, eg. https://ngu.churchcenter.com/registrations/events/123, or a page on this site, eg. /retreats",
|
||||
},
|
||||
{ path: "note", label: "Note", full: true, help: "What it's for, for us only. eg. October newsletter, retreat button" },
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Tracking (UTM tags)",
|
||||
note: "Added to the destination, so a click that lands on our site (or another one with analytics) is credited to where the link was shared. Clicks are counted either way.",
|
||||
fields: [
|
||||
{ path: "utm_source", label: "Source", help: "eg. newsletter. Default: none" },
|
||||
{ path: "utm_medium", label: "Medium", help: "eg. email. Default: none" },
|
||||
{ path: "utm_campaign", label: "Campaign", help: "eg. october-2026. Default: none" },
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
@ -431,8 +431,10 @@ export default function EntityEdit() {
|
|||
field={{
|
||||
path: "id",
|
||||
label: manifest.idLabel,
|
||||
prefix: isNew && qualifierPaths.length ? prefixOf(form) || prefixHint : undefined,
|
||||
prefixPending: isNew && !prefixOf(form),
|
||||
// A fixed lead-in shown in the box (redirects' domain/go/), or
|
||||
// the qualifiers' prefix as it fills in.
|
||||
prefix: isNew ? (qualifierPaths.length ? prefixOf(form) || prefixHint : manifest.idPrefix) : undefined,
|
||||
prefixPending: isNew && qualifierPaths.length > 0 && !prefixOf(form),
|
||||
placeholder: isNew && qualifierPaths.length ? "board" : undefined,
|
||||
readOnly: !isNew,
|
||||
help: !isNew
|
||||
|
|
|
|||
|
|
@ -85,6 +85,11 @@ export const DATA_NAV = {
|
|||
label: "People tags",
|
||||
blurb: "Directories people can be tagged into, eg. Musicians. Who carries a tag is edited on the person.",
|
||||
},
|
||||
{
|
||||
to: "/admin/redirects",
|
||||
label: "Links/redirects",
|
||||
blurb: "Short /go/ links for the newsletter, with click counts, Plausible and UTM tracking.",
|
||||
},
|
||||
{
|
||||
to: "/admin/blog_posts",
|
||||
label: "Blog posts",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue