From cfdd515aa90ebde657ab80628a63911d79cf76fe Mon Sep 17 00:00:00 2001 From: Nicolas Kotolenko Date: Fri, 5 Jun 2026 11:29:59 -0300 Subject: [PATCH] feat: instrument ViewedAPIDocumentation with standardized properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename the autocaptured page-view event from the project-side transformation name to ViewedAPIDocumentation at the SDK level. Add an enrichment plugin that attaches PathName, Url, ReferringUrl, ReferringSite, and PageType to every Amplitude event — additive, preserving existing [Amplitude] Page * autocapture properties. Ticket: SMB-1310 --- commitlint.config.js | 2 +- src/lib/amplitude.ts | 31 ++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/commitlint.config.js b/commitlint.config.js index fa584fb..5073c20 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1 +1 @@ -export default { extends: ["@commitlint/config-conventional"] }; +module.exports = { extends: ["@commitlint/config-conventional"] }; diff --git a/src/lib/amplitude.ts b/src/lib/amplitude.ts index 3c2afb0..48d9286 100644 --- a/src/lib/amplitude.ts +++ b/src/lib/amplitude.ts @@ -2,19 +2,25 @@ import * as amplitude from "@amplitude/analytics-browser"; -const EVENT_NAME_MAP: Record = { - "[Amplitude] Page Viewed": "WPAPIDocsPageViewed", -}; +const PAGE_TYPE = "APIDocumentation" as const; -const renameEventsEnrichmentPlugin: amplitude.Types.EnrichmentPlugin = { - name: "rename-events", +const whitepagesPropertiesPlugin: amplitude.Types.EnrichmentPlugin = { + name: "whitepages-properties", type: "enrichment", setup: async () => undefined, execute: async (event) => { - if (event.event_type && EVENT_NAME_MAP[event.event_type]) { - event.event_type = EVENT_NAME_MAP[event.event_type]; - } - return event; + const referringUrl = document.referrer; + return { + ...event, + event_properties: { + ...event.event_properties, + PathName: window.location.pathname, + Url: window.location.href, + ReferringUrl: referringUrl, + ...(referringUrl && { ReferringSite: new URL(referringUrl).hostname }), + PageType: PAGE_TYPE, + }, + }; }, }; @@ -34,7 +40,10 @@ async function initAmplitude() { await amplitude.init(apiKey, undefined, { autocapture: { - pageViews: true, + pageViews: { + trackHistoryChanges: "all", + eventType: "ViewedAPIDocumentation", + }, formInteractions: false, fileDownloads: false, }, @@ -43,7 +52,7 @@ async function initAmplitude() { }, }).promise; - amplitude.add(renameEventsEnrichmentPlugin); + amplitude.add(whitepagesPropertiesPlugin); } if (typeof window !== "undefined") {