Skip to content

Commit 79a972b

Browse files
feat(docsearch): track docsearch-react UA
1 parent 267c22f commit 79a972b

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/useSearchClient.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@ export function useSearchClient(
1111
): SearchClient {
1212
const searchClient = React.useMemo(() => {
1313
const client = algoliasearch(appId, apiKey);
14-
client.addAlgoliaAgent(`docsearch (${version})`);
14+
client.addAlgoliaAgent('docsearch', version);
15+
16+
// Since DocSearch.js relies on DocSearch React with an alias to Preact,
17+
// we cannot add the `docsearch-react` user agent by default, otherwise
18+
// it would also be sent on a DocSearch.js integration.
19+
// We therefore only add the `docsearch-react` user agent if `docsearch.js`
20+
// is not present.
21+
if (
22+
/docsearch.js \(.*\)/.test(client.transporter.userAgent.value) === false
23+
) {
24+
client.addAlgoliaAgent('docsearch-react', version);
25+
}
1526

1627
return transformSearchClient(client);
1728
}, [appId, apiKey, transformSearchClient]);

0 commit comments

Comments
 (0)