-
Notifications
You must be signed in to change notification settings - Fork 451
Expand file tree
/
Copy pathinkeep.config.js
More file actions
58 lines (48 loc) · 1.88 KB
/
Copy pathinkeep.config.js
File metadata and controls
58 lines (48 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Inkeep client module — auto-loaded by @inkeep/cxkit-docusaurus via getClientModules.
// Runs in the browser. Sets window.InkeepConfig so the onEvent function survives to the
// widget — functions attached to themeConfig.inkeep get stripped during Docusaurus's
// build-time JSON serialization, which is why PR #3308 didn't actually wire events.
if (typeof window !== 'undefined') {
const handleInkeepEvent = (event) => {
if (!window.posthog) return;
const { eventName, properties } = event;
const trackedEvents = [
// Chat events
'assistant_message_received',
'user_message_submitted',
'assistant_positive_feedback_submitted',
'assistant_negative_feedback_submitted',
'assistant_source_item_clicked',
'chat_share_button_clicked',
// Search events
'search_query_submitted',
'search_result_clicked',
'search_query_response_received',
];
if (!trackedEvents.includes(eventName)) return;
const eventProperties = {
component_type: properties?.componentType,
widget_version: properties?.widgetLibraryVersion,
};
if (eventName.includes('search')) {
eventProperties.search_query = properties?.searchQuery;
if (properties?.totalResults !== undefined) {
eventProperties.total_results = properties.totalResults;
}
if (properties?.title) {
eventProperties.result_title = properties.title;
}
}
if (eventName.includes('feedback')) {
eventProperties.feedback_reasons = properties?.reasons;
}
if (eventName === 'assistant_source_item_clicked') {
eventProperties.source_link = properties?.link;
}
window.posthog.capture(`inkeep_${eventName}`, eventProperties);
};
window.InkeepConfig = {
SearchBar: { baseSettings: { onEvent: handleInkeepEvent } },
ChatButton: { baseSettings: { onEvent: handleInkeepEvent } },
};
}