Skip to content

Commit

Permalink
feat(docsearch): track docsearch-react UA
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Jul 9, 2020
1 parent 267c22f commit 79a972b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/useSearchClient.ts
Expand Up @@ -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]);
Expand Down

0 comments on commit 79a972b

Please sign in to comment.