Skip to content

Commit

Permalink
feat: GROW-284 - PR remarks and reverting amplitude changes and keepi…
Browse files Browse the repository at this point in the history
…ng only the track
  • Loading branch information
hba-fingerprint committed Nov 25, 2024
1 parent 760647e commit 1cf8ee3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 58 deletions.
66 changes: 32 additions & 34 deletions src/client/thirdParty/Amplitude.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,51 +37,49 @@ type AmplitudeProps = {
apiKey: string;
};

function initAmplitude(apiKey: string) {
amplitude.init(apiKey, {
defaultTracking: {
attribution: false,
sessions: false,
formInteractions: false,
fileDownloads: false,
},
serverUrl: AMPLITUDE_INGRESS_PROXY,
export function trackAskAIkHelpMethodChosen(
helpMethod: string,
visitorId: string,
pagePath: string,
pageTitle: string,
) {
debugger;
amplitude.track(ASK_AI_CHOSEN_EVENT_TYPE, {
helpMethod,
visitorId,
'Docs Page Path': pagePath,
'Docs Page Title': pageTitle,
});
}

function usePlaygroundSignalsWrapper() {

export const Amplitude: FunctionComponent<AmplitudeProps> = ({ apiKey }) => {
usePlaygroundSignals({
onServerApiSuccess: (event) => {
const visitorId = event.products.identification?.data?.visitorId;
const botDetected = event?.products?.botd?.data?.bot?.result === 'bad' ? 'True' : 'False';

amplitude.add(demoPageViewedEventPropertiesEnrichment(botDetected));

amplitude.track(EVENT_TYPE, {
botDetected,
visitorId,
amplitude.init(apiKey, {
defaultTracking: {
pageViews: {
eventType: EVENT_TYPE,
},
attribution: false,
sessions: false,
formInteractions: false,
fileDownloads: false,
},
deviceId: visitorId,
serverUrl: AMPLITUDE_INGRESS_PROXY,
});
},
});
}

export async function trackAskAIkHelpMethodChosen(
helpMethod: string,
visitorId: string,
pagePath: string,
pageTitle: string,
) {
amplitude.track(ASK_AI_CHOSEN_EVENT_TYPE, {
helpMethod,
visitorId,
'Docs Page Path': pagePath,
'Docs Page Title': pageTitle,
// Set Amplify user's custom `botDetected` property based on Fingerprint Bot Detection result
const identifyEvent = new amplitude.Identify();
identifyEvent.set('botDetected', botDetected);
amplitude.identify(identifyEvent);
},
});
}

export const Amplitude: FunctionComponent<AmplitudeProps> = ({ apiKey }) => {
initAmplitude(apiKey);
usePlaygroundSignalsWrapper();

return null;
};
};
43 changes: 19 additions & 24 deletions src/client/thirdParty/Inkeep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,27 @@ type InkeepSharedSettings = {
};

export const createCustomAnalyticsCallback = (
getVisitorData: (getDataOptions?: GetDataOptions<boolean>) => Promise<VisitorData<boolean>>,
location: LocationSensorState,
visitorId: string,
) => {
return async (event: any) => {
if (event.eventName === GET_HELP_OPTIONS_CLICKED) {
const { visitorId } = await getVisitorData({ ignoreCache: true });

const { name } = event.properties;
const pagePath = location.pathname || '';
const pagePath = document.location.pathname;
const pageTitle = document.title;

await trackAskAIkHelpMethodChosen(name, visitorId, pagePath, pageTitle);
trackAskAIkHelpMethodChosen(name, visitorId, pagePath, pageTitle);
}
};
};

const useInkeepSettings = (
getVisitorData: (getDataOptions?: GetDataOptions<boolean>) => Promise<VisitorData<boolean>>,
location: LocationSensorState,
visitorId: string
): 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 customAnalyticsCallback = createCustomAnalyticsCallback(getVisitorData, location);
const customAnalyticsCallback = createCustomAnalyticsCallback(visitorId);

const baseSettings: InkeepBaseSettings = {
apiKey,
Expand Down Expand Up @@ -113,22 +109,21 @@ const useInkeepSettings = (
};

export function InkeepChatButton() {
const { getData: getVisitorData } = useVisitorData(
{ ignoreCache: true, timeout: FPJS_CLIENT_TIMEOUT },
{
immediate: false,
},
);
const location = useLocation();
const { data } = useVisitorData({ extendedResult: true, timeout: FPJS_CLIENT_TIMEOUT });

const { baseSettings, aiChatSettings, searchSettings, modalSettings } = useInkeepSettings(getVisitorData, location);
const visitorId = data?.visitorId

const chatButtonProps: InkeepChatButtonProps = {
baseSettings,
aiChatSettings,
searchSettings,
modalSettings,
};
debugger;
if (visitorId) {
const { baseSettings, aiChatSettings, searchSettings, modalSettings } = useInkeepSettings(visitorId);

const chatButtonProps: InkeepChatButtonProps = {
baseSettings,
aiChatSettings,
searchSettings,
modalSettings,
};

return <ChatButton {...chatButtonProps} />;
return <ChatButton {...chatButtonProps} />;
}
}

0 comments on commit 1cf8ee3

Please sign in to comment.