Skip to content
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: save existing anon tokens for multiple init calls #562

Merged
merged 3 commits into from
Oct 31, 2024

Conversation

shaejaz
Copy link
Contributor

@shaejaz shaejaz commented Oct 28, 2024

Context

In InstantSearch, in order for user tokens to be set in time for the first query on page load, anonymous user tokens are generated and set as both the InstantSearch token and Insights token.

This flow has one issue though. When useCookies flag needs to be changed later (such as with a cookie consent banner), a second init call to insights with the flag set to true does not save the existing token to a cookie.

A short repro is as follows with the very latest version of InstantSearch where this behaviour was added (PR: algolia/instantsearch#6377):

const searchClient = algoliasearch(
  // ...
);

window.aa('init', {
  appId: 'id',
  apiKey: 'key',
});

const search = instantsearch({
  indexName: 'index',
  searchClient,
  insights: true,
});

search.addWidgets([
  // ...
]);

// This does not save the cookie atm
setTimeout(() => {
  window.aa('init', {
    partial: true,
    useCookie: true,
  });
}, 5000);

Copy link

codesandbox-ci bot commented Oct 28, 2024

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.

@shaejaz shaejaz marked this pull request as ready for review October 29, 2024 11:32
@shaejaz shaejaz requested a review from a team as a code owner October 29, 2024 11:32
@shaejaz shaejaz requested a review from Haroenv October 29, 2024 11:32
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the InstantSearch point of view, this is good

@JasonBerry JasonBerry merged commit 86164bb into main Oct 31, 2024
4 checks passed
@JasonBerry JasonBerry deleted the fix/set-anontoken-init branch October 31, 2024 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants