From 639db7ce1401c25fd26639d227f23194f8a53014 Mon Sep 17 00:00:00 2001 From: Juraj Uhlar Date: Thu, 28 Nov 2024 11:47:42 +0000 Subject: [PATCH] chore: clean up --- src/client/thirdParty/Amplitude.tsx | 26 +++++++++++++++----------- src/client/thirdParty/Inkeep.tsx | 18 +++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/client/thirdParty/Amplitude.tsx b/src/client/thirdParty/Amplitude.tsx index 72cbd109..7d10d0d9 100644 --- a/src/client/thirdParty/Amplitude.tsx +++ b/src/client/thirdParty/Amplitude.tsx @@ -3,8 +3,10 @@ import { usePlaygroundSignals } from '../../app/playground/hooks/usePlaygroundSi import { FunctionComponent } from 'react'; const AMPLITUDE_INGRESS_PROXY = 'https://demo.fingerprint.com/ampl-api/2/httpapi'; -const EVENT_TYPE = 'Demo Page Viewed'; -const ASK_AI_CHOSEN_EVENT_TYPE = 'Demo Ask AI Help Chosen'; +const AMPLITUDE_EVENT = { + DEMO_PAGE_VIEWED: 'Demo Page Viewed', + DEMO_ASK_AI_HELP_CHOSEN: 'Demo Ask AI Help Chosen', +} as const; /** * This is an Amplitude plugin that renames the Page view event_properties according to our analytics needs @@ -15,7 +17,7 @@ const demoPageViewedEventPropertiesEnrichment = (botDetected: 'True' | 'False'): setup: async () => undefined, execute: async (event) => { // Only apply to Demo Page View events - if (event.event_type !== EVENT_TYPE) { + if (event.event_type !== AMPLITUDE_EVENT.DEMO_PAGE_VIEWED) { return event; } @@ -37,13 +39,15 @@ type AmplitudeProps = { apiKey: string; }; -export function trackAskAIHelpMethodChosen(helpMethod: string, visitorId: string, pagePath: string, pageTitle: string) { - amplitude.track(ASK_AI_CHOSEN_EVENT_TYPE, { - helpMethod, - visitorId, - 'Demo Page Path': pagePath, - 'Demo Page Title': pageTitle, - }); +type AskAIHelpChosenEventProperties = { + visitorId: string; + helpMethod: string; + 'Demo Page Path': string; + 'Demo Page Title': string; +}; + +export function trackAskAIHelpChosen(properties: AskAIHelpChosenEventProperties) { + amplitude.track(AMPLITUDE_EVENT.DEMO_ASK_AI_HELP_CHOSEN, properties); } export const Amplitude: FunctionComponent = ({ apiKey }) => { @@ -56,7 +60,7 @@ export const Amplitude: FunctionComponent = ({ apiKey }) => { amplitude.init(apiKey, { defaultTracking: { pageViews: { - eventType: EVENT_TYPE, + eventType: AMPLITUDE_EVENT.DEMO_PAGE_VIEWED, }, attribution: false, sessions: false, diff --git a/src/client/thirdParty/Inkeep.tsx b/src/client/thirdParty/Inkeep.tsx index 8c4ea637..aaee31bb 100644 --- a/src/client/thirdParty/Inkeep.tsx +++ b/src/client/thirdParty/Inkeep.tsx @@ -8,7 +8,7 @@ import type { } from '@inkeep/uikit'; import { env } from '../../env'; import dynamic from 'next/dynamic'; -import { trackAskAIHelpMethodChosen } from './Amplitude'; +import { trackAskAIHelpChosen } from './Amplitude'; import { useVisitorData } from '@fingerprintjs/fingerprintjs-pro-react'; import { FPJS_CLIENT_TIMEOUT } from '../../const'; @@ -34,17 +34,17 @@ const useInkeepSettings = (): InkeepSharedSettings => { const apiKey = env.NEXT_PUBLIC_INKEEP_API_KEY; const integrationId = env.NEXT_PUBLIC_INKEEP_INTEGRATION_ID; const organizationId = env.NEXT_PUBLIC_INKEEP_ORG_ID; - - const { data } = useVisitorData({ extendedResult: true, timeout: FPJS_CLIENT_TIMEOUT }); - const visitorId = data?.visitorId || ''; + const { data } = useVisitorData({ timeout: FPJS_CLIENT_TIMEOUT }); + const visitorId = data?.visitorId ?? ''; const logEventCallback = (event: any) => { if (event.eventName === GET_HELP_OPTIONS_CLICKED) { - const { name } = event.properties; - const pagePath = document.location.pathname; - const pageTitle = document.title; - - trackAskAIHelpMethodChosen(name, visitorId, pagePath, pageTitle); + trackAskAIHelpChosen({ + visitorId, + helpMethod: event.properties.name, + 'Demo Page Path': document.location.pathname, + 'Demo Page Title': document.title, + }); } };