Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default { extends: ["@commitlint/config-conventional"] };
module.exports = { extends: ["@commitlint/config-conventional"] };
31 changes: 20 additions & 11 deletions src/lib/amplitude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@

import * as amplitude from "@amplitude/analytics-browser";

const EVENT_NAME_MAP: Record<string, string> = {
"[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,
},
};
},
};

Expand All @@ -34,7 +40,10 @@ async function initAmplitude() {

await amplitude.init(apiKey, undefined, {
autocapture: {
pageViews: true,
pageViews: {
trackHistoryChanges: "all",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like something that the Amplitude package would return an enumeration for.

eventType: "ViewedAPIDocumentation",
},
formInteractions: false,
fileDownloads: false,
},
Expand All @@ -43,7 +52,7 @@ async function initAmplitude() {
},
}).promise;

amplitude.add(renameEventsEnrichmentPlugin);
amplitude.add(whitepagesPropertiesPlugin);
}

if (typeof window !== "undefined") {
Expand Down
Loading