diff --git a/packages/gitbook/src/components/AI/useAIChat.tsx b/packages/gitbook/src/components/AI/useAIChat.tsx index 63be4351e..73c34e0e0 100644 --- a/packages/gitbook/src/components/AI/useAIChat.tsx +++ b/packages/gitbook/src/components/AI/useAIChat.tsx @@ -11,9 +11,10 @@ import { type AIStreamResponseToolCallPending, type AIToolCallResult, SiteInsightsDisplayContext, + type SiteInsightsEventAskView, } from '@gitbook/api'; -import { getInsightsSession, trackAskView, useTrackEvent } from '../Insights'; +import { getInsightsSession, useTrackEvent } from '../Insights'; import { type UpdateSearchState, useSetSearchState } from '../Search'; import { addRecentSearchQuery } from '../Search/recent-queries'; import type { AnyAIControl } from './controls'; @@ -60,7 +61,7 @@ export type AIChatStatus = | 'error' | 'confirm'; -export type AskAITrigger = 'hover' | 'selection' | 'site' | 'page' | 'embed'; +export type AskAITrigger = NonNullable; export type AIChatState = { /** @@ -308,7 +309,7 @@ export function AIChatProvider(props: { (trigger?: AskAITrigger) => { setIntercomLauncherHidden(true); if (!renderMessageOptions?.asEmbeddable) { - trackAskView(trackEvent, trigger); + trackEvent({ type: 'ask_view', trigger }); } const { initialQuery } = globalState.getState(); diff --git a/packages/gitbook/src/components/Embeddable/EmbeddableAIChat.tsx b/packages/gitbook/src/components/Embeddable/EmbeddableAIChat.tsx index cbfd68d31..781ee9bd5 100644 --- a/packages/gitbook/src/components/Embeddable/EmbeddableAIChat.tsx +++ b/packages/gitbook/src/components/Embeddable/EmbeddableAIChat.tsx @@ -4,7 +4,7 @@ import React from 'react'; import * as api from '@gitbook/api'; -import { trackAskView, useTrackEvent } from '../Insights'; +import { useTrackEvent } from '../Insights'; import { LinkContext } from '../primitives'; import { useIsVisible } from '../VisibilityContext'; import { @@ -60,10 +60,13 @@ export function EmbeddableAIChat(props: EmbeddableAIChatProps) { return; } - trackAskView(trackEvent, 'embed', { - pageId: null, - displayContext: api.SiteInsightsDisplayContext.Embed, - }); + trackEvent( + { type: 'ask_view', trigger: 'embed' }, + { + pageId: null, + displayContext: api.SiteInsightsDisplayContext.Embed, + } + ); }, [trackEvent, isVisible]); const tabsRef = React.useRef(null); diff --git a/packages/gitbook/src/components/Insights/InsightsProvider.tsx b/packages/gitbook/src/components/Insights/InsightsProvider.tsx index 6f0fa9480..658c5c83f 100644 --- a/packages/gitbook/src/components/Insights/InsightsProvider.tsx +++ b/packages/gitbook/src/components/Insights/InsightsProvider.tsx @@ -7,7 +7,6 @@ import type * as api from '@gitbook/api'; import { SiteInsightsDisplayContext } from '@gitbook/api'; import { OpenAPIOperationContextProvider } from '@gitbook/react-openapi'; -import type { AskAITrigger } from '../AI'; import { type CurrentContentContext, useCurrentContent } from '../hooks'; import { getSession } from './sessions'; import { type VisitorResponse, useVisitor } from './visitorId'; @@ -44,7 +43,7 @@ export type TrackEventInput( +type TrackEventCallback = ( event: TrackEventInput, ctx?: InsightsEventPageContext, options?: InsightsEventOptions @@ -224,16 +223,6 @@ export function useTrackEvent(): TrackEventCallback { return React.useContext(InsightsContext); } -/** Track an ask view while the frontend uses an API type that predates its trigger field. */ -export function trackAskView( - trackEvent: TrackEventCallback, - trigger: AskAITrigger | undefined, - ctx?: InsightsEventPageContext -) { - // TODO: remove this cast once @gitbook/api includes SiteInsightsEventAskView.trigger. - trackEvent({ type: 'ask_view', trigger } as unknown as TrackEventInput<'ask_view'>, ctx); -} - /** * The referrer when it's another page of this origin, so a full page load (e.g. an absolute link * to a missing page) still records the page it came from.