Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 659be55

Browse files
Track insight event when embedded assistant is displayed (#3616)
1 parent 78a632b commit 659be55

File tree

11 files changed

+59
-10
lines changed

11 files changed

+59
-10
lines changed

‎.changeset/funny-experts-destroy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": minor
3+
---
4+
5+
Track insight event when embedded assistant is displayed.

‎bun.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
"react-dom": "^19.0.0",
296296
},
297297
"catalog": {
298-
"@gitbook/api": "^0.137.0",
298+
"@gitbook/api": "^0.138.0",
299299
"bidc": "^0.0.2",
300300
},
301301
"packages": {
@@ -661,7 +661,7 @@
661661

662662
"@fortawesome/fontawesome-svg-core": ["@fortawesome/fontawesome-svg-core@6.6.0", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "6.6.0" } }, "sha512-KHwPkCk6oRT4HADE7smhfsKudt9N/9lm6EJ5BVg0tD1yPA5hht837fB87F8pn15D8JfTqQOjhKTktwmLMiD7Kg=="],
663663

664-
"@gitbook/api": ["@gitbook/api@0.137.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-3pTNbHI4kJT7ikqSdSLa2UCB0dOPOTzOUHcsCTLrk+rJVjTAFAJmTEW/Ax2prnwZ75ran2hz9/FhxUAGhp/8Mg=="],
664+
"@gitbook/api": ["@gitbook/api@0.138.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-6jYH1R5IpmbFj3qUyDGuUBaABCinKQcqNCtTKtql0MSPaFp9KVnqyBsIaq/s9HohjCpyU1/EoddwzAaJWHWkkw=="],
665665

666666
"@gitbook/browser-types": ["@gitbook/browser-types@workspace:packages/browser-types"],
667667

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"workspaces": {
3535
"packages": ["packages/*"],
3636
"catalog": {
37-
"@gitbook/api": "^0.137.0",
37+
"@gitbook/api": "^0.138.0",
3838
"bidc": "^0.0.2"
3939
}
4040
},

‎packages/gitbook/src/components/AIChat/AIChat.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
EmbeddableFrameSubtitle,
2121
EmbeddableFrameTitle,
2222
} from '../Embeddable/EmbeddableFrame';
23+
import { useTrackEvent } from '../Insights';
2324
import { useNow } from '../hooks';
2425
import { Button } from '../primitives';
2526
import { AIChatControlButton } from './AIChatControlButton';
@@ -54,6 +55,16 @@ export function AIChat(props: { trademark: boolean }) {
5455
[]
5556
);
5657

58+
// Track the view of the AI chat
59+
const trackEvent = useTrackEvent();
60+
React.useEffect(() => {
61+
if (chat.opened) {
62+
trackEvent({
63+
type: 'ask_view',
64+
});
65+
}
66+
}, [chat.opened, trackEvent]);
67+
5768
if (!chat.opened) {
5869
return null;
5970
}

‎packages/gitbook/src/components/Embeddable/EmbeddableAIChat.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import {
77
AIChatDynamicIcon,
88
AIChatSubtitle,
99
} from '@/components/AIChat';
10+
import * as api from '@gitbook/api';
11+
import React from 'react';
12+
import { useTrackEvent } from '../Insights';
1013
import {
1114
EmbeddableFrame,
1215
EmbeddableFrameBody,
@@ -28,6 +31,20 @@ export function EmbeddableAIChat(props: {
2831
const chatController = useAIChatController();
2932
const configuration = useEmbeddableConfiguration();
3033

34+
// Track the view of the AI chat
35+
const trackEvent = useTrackEvent();
36+
React.useEffect(() => {
37+
trackEvent(
38+
{
39+
type: 'ask_view',
40+
},
41+
{
42+
pageId: null,
43+
displayContext: api.SiteInsightsDisplayContext.Embed,
44+
}
45+
);
46+
}, [trackEvent]);
47+
3148
return (
3249
<EmbeddableFrame>
3350
<EmbeddableFrameHeader>

‎packages/gitbook/src/components/Embeddable/EmbeddableDocsPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { type PagePathParams, getSitePageData } from '@/components/SitePage';
22

33
import { PageBody } from '@/components/PageBody';
44
import type { GitBookSiteContext } from '@/lib/context';
5+
import { SiteInsightsDisplayContext } from '@gitbook/api';
56
import type { Metadata } from 'next';
67
import { Button } from '../primitives';
78
import {
@@ -54,6 +55,7 @@ export async function EmbeddableDocsPage(props: EmbeddableDocsPageProps) {
5455
ancestors={ancestors}
5556
document={document}
5657
withPageFeedback={withPageFeedback}
58+
insightsDisplayContext={SiteInsightsDisplayContext.Embed}
5759
/>
5860
</div>
5961
</EmbeddableFrameBody>

‎packages/gitbook/src/components/Insights/InsightsProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type InsightsEventName = api.SiteInsightsEvent['type'];
1616
* Context for an event on a page.
1717
*/
1818
export interface InsightsEventPageContext {
19+
displayContext: api.SiteInsightsDisplayContext;
1920
pageId: string | null;
2021
}
2122

@@ -265,6 +266,7 @@ function transformEvents(input: {
265266
siteShareKey: input.context.siteShareKey ?? null,
266267
revision: input.context.revisionId,
267268
page: input.pageContext.pageId,
269+
displayContext: input.pageContext.displayContext,
268270
};
269271

270272
return input.events.map((partialEvent) => {

‎packages/gitbook/src/components/Insights/TrackPageViewEvent.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22

3+
import type { SiteInsightsDisplayContext } from '@gitbook/api';
34
import * as React from 'react';
45

56
import { useCurrentPage } from '../hooks';
@@ -8,7 +9,10 @@ import { useTrackEvent } from './InsightsProvider';
89
/**
910
* Track a page view event.
1011
*/
11-
export function TrackPageViewEvent() {
12+
export function TrackPageViewEvent(props: {
13+
displayContext: SiteInsightsDisplayContext;
14+
}) {
15+
const { displayContext } = props;
1216
const page = useCurrentPage();
1317
const trackEvent = useTrackEvent();
1418

@@ -19,9 +23,10 @@ export function TrackPageViewEvent() {
1923
},
2024
{
2125
pageId: page?.pageId ?? null,
26+
displayContext,
2227
}
2328
);
24-
}, [page, trackEvent]);
29+
}, [page, trackEvent,displayContext]);
2530

2631
return null;
2732
}

‎packages/gitbook/src/components/PageBody/PageBody.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { GitBookSiteContext } from '@/lib/context';
2-
import type { JSONDocument, RevisionPageDocument } from '@gitbook/api';
2+
import type { JSONDocument, RevisionPageDocument,SiteInsightsDisplayContext } from '@gitbook/api';
33
import React from 'react';
44

55
import { getSpaceLanguage } from '@/intl/server';
@@ -26,8 +26,9 @@ export function PageBody(props: {
2626
ancestors: AncestorRevisionPage[];
2727
document: JSONDocument | null;
2828
withPageFeedback: boolean;
29+
insightsDisplayContext: SiteInsightsDisplayContext;
2930
}) {
30-
const { page, context, ancestors, document, withPageFeedback } = props;
31+
const { page, context, ancestors, document, withPageFeedback, insightsDisplayContext } = props;
3132
const { customization } = context;
3233

3334
const contentFullWidth = document ? hasFullWidthBlock(document) : false;
@@ -117,7 +118,7 @@ export function PageBody(props: {
117118
}
118119
</main>
119120

120-
<TrackPageViewEvent />
121+
<TrackPageViewEvent displayContext={insightsDisplayContext}/>
121122
</CurrentPageProvider>
122123
);
123124
}

‎packages/gitbook/src/components/SitePage/SitePage.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { GitBookSiteContext } from '@/lib/context';
22
import { getPageDocument } from '@/lib/data';
3-
import { CustomizationHeaderPreset, CustomizationThemeMode } from '@gitbook/api';
3+
import {
4+
CustomizationHeaderPreset,
5+
CustomizationThemeMode,
6+
SiteInsightsDisplayContext,
7+
} from '@gitbook/api';
48
import type { Metadata, Viewport } from 'next';
59
import { notFound, redirect } from 'next/navigation';
610
import React from 'react';
@@ -65,6 +69,7 @@ export async function SitePage(props: SitePageProps) {
6569
ancestors={ancestors}
6670
document={document}
6771
withPageFeedback={withPageFeedback}
72+
insightsDisplayContext={SiteInsightsDisplayContext.Site}
6873
/>
6974
</div>
7075
<React.Suspense fallback={null}>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /