Add event structured data, canonical URLs and referrer-based traffic sources
- Event pages emit schema.org Event JSON-LD (dates, venue, image, organizer, ZAR offers, sold-out status) for Google event results. - Event pages, the events list and home page set a canonical URL so tagged and alias links don't split rankings. - Funnel tracking falls back to the referring site (Facebook, Instagram, Google, ...) and fbclid/gclid when a link has no utm_source/src. - Share and Save QR on the event page tag their links as share / qr. - getServerSettings moves to lib/serverSettings.ts for reuse. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -56,11 +56,45 @@ export function analyticsSessionId(): string | undefined {
|
||||
}
|
||||
}
|
||||
|
||||
/** Where the visitor came from: ?utm_source=… or ?src=<short-link alias>. */
|
||||
// Referring sites we name ourselves; any other site is recorded by its hostname.
|
||||
const REFERRER_SOURCES: [RegExp, string][] = [
|
||||
[/(^|\.)(facebook\.com|fb\.com|fb\.me)$/, "facebook"],
|
||||
[/(^|\.)instagram\.com$/, "instagram"],
|
||||
[/(^|\.)(whatsapp\.com|wa\.me)$/, "whatsapp"],
|
||||
[/(^|\.)google\.[a-z.]+$/, "google"],
|
||||
[/(^|\.)bing\.com$/, "bing"],
|
||||
[/(^|\.)duckduckgo\.com$/, "duckduckgo"],
|
||||
[/(^|\.)yahoo\.com$/, "yahoo"],
|
||||
[/(^|\.)(twitter\.com|x\.com|t\.co)$/, "x"],
|
||||
[/(^|\.)(linkedin\.com|lnkd\.in)$/, "linkedin"],
|
||||
[/(^|\.)(youtube\.com|youtu\.be)$/, "youtube"],
|
||||
[/(^|\.)tiktok\.com$/, "tiktok"],
|
||||
];
|
||||
|
||||
/** The referring site as a source label; undefined when there's none or it's this site. */
|
||||
function sourceFromReferrer(): string | undefined {
|
||||
try {
|
||||
if (!document.referrer) return undefined;
|
||||
const host = new URL(document.referrer).hostname.toLowerCase();
|
||||
if (!host || host === window.location.hostname.toLowerCase()) return undefined;
|
||||
for (const [re, label] of REFERRER_SOURCES) if (re.test(host)) return label;
|
||||
return host.replace(/^www\./, "");
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the visitor came from: ?utm_source=… or ?src=<short-link alias> when the link
|
||||
* says so, else the referring site (Facebook, Google, …), else Facebook's/Google's click
|
||||
* ids. WhatsApp sends no referrer, so it's only known from a tagged link.
|
||||
*/
|
||||
function sourceFromUrl(): string | undefined {
|
||||
try {
|
||||
const p = new URLSearchParams(window.location.search);
|
||||
return p.get("utm_source") || p.get("src") || undefined;
|
||||
return p.get("utm_source") || p.get("src") || sourceFromReferrer()
|
||||
|| (p.has("fbclid") ? "facebook" : undefined)
|
||||
|| (p.has("gclid") ? "google" : undefined);
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user