diff --git a/src/useSearchClient.ts b/src/useSearchClient.ts index 015833708..afa9b2447 100644 --- a/src/useSearchClient.ts +++ b/src/useSearchClient.ts @@ -11,7 +11,18 @@ export function useSearchClient( ): SearchClient { const searchClient = React.useMemo(() => { const client = algoliasearch(appId, apiKey); - client.addAlgoliaAgent(`docsearch (${version})`); + client.addAlgoliaAgent('docsearch', version); + + // Since DocSearch.js relies on DocSearch React with an alias to Preact, + // we cannot add the `docsearch-react` user agent by default, otherwise + // it would also be sent on a DocSearch.js integration. + // We therefore only add the `docsearch-react` user agent if `docsearch.js` + // is not present. + if ( + /docsearch.js \(.*\)/.test(client.transporter.userAgent.value) === false + ) { + client.addAlgoliaAgent('docsearch-react', version); + } return transformSearchClient(client); }, [appId, apiKey, transformSearchClient]);