Sometimes you may need to search two separate Algolia Applications in the same page.
Whilst we advise against doing this when it can be avoided (for example if you can move all the indexes onto the same application) sometimes this is not possible.
As such when sending your click and conversion events you will need to make sure that the search for each application uses a separate insights middleware instance so that each set of events get sent to the correct index.
To do this you should initialise the client twice:
const aa = createInsightsClient(getRequesterForBrowser());
const bb = createInsightsClient(getRequesterForBrowser());
Then you can use each insights client to make a middleware instance:
const insightsMiddleware = instantsearch.middlewares.createInsightsMiddleware({ insightsClient: window.aa, }) const insightsMiddleware2 = instantsearch.middlewares.createInsightsMiddleware({ insightsClient: window.bb, })
You can then attach each of these middleware instances to one of your search clients
const search = instantsearch({
searchClient,
indexName: 'INDEX_NAME',
})
search.use(insightsMiddleware)
const search2 = instantsearch({
searchClient2,
indexName: 'INDEX_NAME_2',
})
search.use(insightsMiddleware2)
You will now be able to send your events to each of the two applications.