Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/GROW-284.add_amplitude_to_i…
Browse files Browse the repository at this point in the history
…nkeep_actions' into feat/GROW-284.add_amplitude_to_inkeep_actions

# Conflicts:
#	src/client/thirdParty/Amplitude.tsx
#	src/client/thirdParty/Inkeep.tsx
  • Loading branch information
hba-fingerprint committed Nov 28, 2024
2 parents 3bd4174 + 639db7c commit bf9657a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
24 changes: 14 additions & 10 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,12 +39,14 @@ type AmplitudeProps = {
apiKey: string;
};

export function trackAskAIHelpMethodChosen(helpMethod: string, pagePath: string, pageTitle: string) {
amplitude.track(ASK_AI_CHOSEN_EVENT_TYPE, {
helpMethod,
'Demo Page Path': pagePath,
'Demo Page Title': pageTitle,
});
type AskAIHelpChosenEventProperties = {
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 @@ -55,7 +59,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
12 changes: 6 additions & 6 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';

const GET_HELP_OPTIONS_CLICKED = 'get_help_option_clicked';

Expand All @@ -35,11 +35,11 @@ const useInkeepSettings = (): InkeepSharedSettings => {

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, pagePath, pageTitle);
trackAskAIHelpChosen({
helpMethod: event.properties.name,
'Demo Page Path': document.location.pathname,
'Demo Page Title': document.title,
});
}
};

Expand Down

0 comments on commit bf9657a

Please sign in to comment.