Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
JuroUhlar committed Nov 28, 2024
1 parent 9a8ee0b commit 639db7c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
26 changes: 15 additions & 11 deletions src/client/thirdParty/Amplitude.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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<AmplitudeProps> = ({ apiKey }) => {
Expand All @@ -56,7 +60,7 @@ export const Amplitude: FunctionComponent<AmplitudeProps> = ({ apiKey }) => {
amplitude.init(apiKey, {
defaultTracking: {
pageViews: {
eventType: EVENT_TYPE,
eventType: AMPLITUDE_EVENT.DEMO_PAGE_VIEWED,
},
attribution: false,
sessions: false,
Expand Down
18 changes: 9 additions & 9 deletions src/client/thirdParty/Inkeep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
});
}
};

Expand Down

0 comments on commit 639db7c

Please sign in to comment.