-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(insights): only load script if we write window.aa #5559
fix(insights): only load script if we write window.aa #5559
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 769588d:
|
packages/instantsearch.js/src/middlewares/__tests__/createInsightsMiddleware.ts
Outdated
Show resolved
Hide resolved
…ghtsMiddleware.ts
packages/instantsearch.js/src/middlewares/createInsightsMiddleware.ts
Outdated
Show resolved
Hide resolved
if (!insightsClient) { | ||
if (!potentialInsightsClient) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before this change, if window.AlgoliaAnalyticsObject wasn't a string, insightsClient
still was noop
, and thus not null
window[pointer].shouldAddScript = true; | ||
} | ||
|
||
insightsClient = window[pointer]; | ||
insightsClient.shouldAddScript = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should only add the script if we wrote window.aa, as otherwise nothing will happen with the script
* fix(insights): only load script if we write window.aa * Update packages/instantsearch.js/src/middlewares/__tests__/createInsightsMiddleware.ts * Update packages/instantsearch.js/src/middlewares/createInsightsMiddleware.ts * fix lint
* fix(insights): only load script if we write window.aa * Update packages/instantsearch.js/src/middlewares/__tests__/createInsightsMiddleware.ts * Update packages/instantsearch.js/src/middlewares/createInsightsMiddleware.ts * fix lint
Summary
We were attempting to load search-insights, even if window.aa had potentially already been set up by something different.
Result
Only when window[window.AlgoliaAnalyticsObject] is set by InstantSearch it is safe to load search insights, otherwise it will not be used.