Skip to content

Commit 4d78983

Browse files
committed
catch algolia insights
1 parent 338c6e2 commit 4d78983

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/components/search/index.tsx

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

33
import {Fragment, useCallback, useEffect, useRef, useState} from 'react';
4+
import * as Sentry from '@sentry/nextjs';
45
import {
56
Hit,
67
Result,
@@ -200,15 +201,21 @@ export function Search({path, autoFocus, searchPlatforms = [], showChatBot}: Pro
200201
return;
201202
}
202203

203-
algoliaInsights('clickedObjectIDsAfterSearch', {
204-
eventName: 'documentation_search_result_click',
205-
userToken: randomUserToken,
206-
index: hit.index,
207-
objectIDs: [hit.id],
208-
// Positions in Algolia are 1 indexed
209-
queryID: hit.queryID ?? '',
210-
positions: [position + 1],
211-
});
204+
// we don't want analytics to crash anything or log errors the console
205+
// so we'll catch any errors and send them to Sentry here silently
206+
try {
207+
algoliaInsights('clickedObjectIDsAfterSearch', {
208+
eventName: 'documentation_search_result_click',
209+
userToken: randomUserToken,
210+
index: hit.index,
211+
objectIDs: [hit.id],
212+
// Positions in Algolia are 1 indexed
213+
queryID: hit.queryID ?? '',
214+
positions: [position + 1],
215+
});
216+
} catch (error) {
217+
Sentry.captureException(error);
218+
}
212219
}, []);
213220

214221
return (

0 commit comments

Comments
 (0)