-
Notifications
You must be signed in to change notification settings - Fork 332
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
feat(plugins): introduce Insights plugin #373
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 e369512:
|
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.
overall, looks pretty good!
item, | ||
insightsEvents: [ | ||
{ | ||
eventName: 'Item Selected', |
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 might want to prefix these event names with autocomplete, that way it would be clearer how the usage is working exactly. Selected can mean a lot otherwise
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.
Yeah I asked the Insights team recommendation about that—waiting for their answer.
packages/autocomplete-plugin-algolia-insights/src/createAlgoliaInsightsPlugin.ts
Show resolved
Hide resolved
packages/autocomplete-plugin-algolia-insights/src/createSearchInsightsApi.ts
Show resolved
Hide resolved
packages/autocomplete-plugin-algolia-insights/src/createViewedEvents.ts
Outdated
Show resolved
Hide resolved
packages/autocomplete-preset-algolia/src/search/getAlgoliaInsightsHits.ts
Outdated
Show resolved
Hide resolved
In 11fcb2c I removed the |
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.
looks good, quick question
packages/autocomplete-plugin-algolia-insights/src/createAlgoliaInsightsPlugin.ts
Outdated
Show resolved
Hide resolved
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.
I think this is good, but would like to keep freedom to consolidate or override the events. Could maybe done after the fact though, not sure!
Should there be a |
Does the current API not provide enough flexibility?
Possibly! We can introduce this in other PRs. |
I misread what the public API is, it totally makes sense for the function call to be able to override the event name! |
This introduces a new Autocomplete plugin for Algolia Insights.
Introduction
This plugin aims at integrating Algolia Insights in your Autocomplete experience without setup. For advanced use cases, we inject the Insights API in the Context to have access to its methods anywhere in the Autocomplete hooks.
Usage
Insights events can be sent by default from:
onStateState
: 400ms debounced when items change. The default is to sendviewedObjectIDs
events for each Algolia index.onSelect
: the default is to send aclickedObjectIDsAfterSearch
event.onHighlight
: no defaultIf users need to send events for other actions, they can use the Context API.
Basic usage
Custom usage
Usage with other plugins
Other plugins usually using
getAlgoliaHits
need this search method to be replaced with an Insights-compatible method. We support this in the Query Suggestions plugin:The hits coming from the QS index will now have their index name and query ID attached for the Insights plugin to work.
Advanced usage using Context
If you want to send custom events from your templates (e.g., a conversion event from an "Add to cart" button), the Insights API is stored in the Context.
Implementation
The plugin API has changed its subscription API
We used to have a
subscribed
object like this:We now have a
subscribe
method that received all the setters and subscriber functions.This reduces the API surface and make initial interactions with State and Context possible.
The Query Suggestions plugin now accepts a
getAlgoliaHits
methodThis allows to plug the
getAlgoliaInsightsHit
method to make your QS compatible with Insights.Next steps
state.context
TypeScript type from plugins.