using insight search v 2.2.1
1 Like
Looking at devtools the source code has
'development' === process.env.NODE_ENV &&
console.info(
'Since v2.0.4, search-insights no longer validates event payloads.\nYou can visit https://algolia.com/events/debugger instead.',
),
No way to turn it off if in NODE_ENV development
Hi @harry.scheuerle
Early versions of the insights middleware library performed payload validation in the library itself. When we transitioned event debugging to the console, we added this info-level message to alert developers to the change.
This should only be appearing if you have console logging set to INFO or higher. You shouldn’t see it in production. I would imagine at some point we’ll remove the info alert – probably with the next major version.
You can read more on the history in this PR:
algolia:master
← algolia:fix/remove-validation
opened 02:15PM - 12 Oct 21 UTC
This PR removes validation codes before sending events.
## Issues
search-i… nsights currently validates payloads upfront within the library before calling the API. It causes multiple problems:
1. The validation logic might not be the same as the one on the backend.
2. It's a duplicated work, and hard to keep up-to-date with the latest change from the backend (considering the fact that customers have to update search-insights library in their app.)
3. When an error is thrown, it means the API call never happened. And we have no metrics on failed events. Even if it's incomplete, if we send them all, we get to know better insights on wrong payloads, success / failure ratio, etc.
## Why did we validate in the library?
It's hard to know the full history and the context over the decision. However, this is the search-insights has been using `sendBeacon` method, which is a browser API, specifically designed to send events. It falls back to `XHR` only when `sendBeacon` is not supported on users' browser (which is like [3.91%](https://caniuse.com/?search=sendbeacon) these days.) `sendBeacon` doesn't provide HTTP response. It means search-insights has no idea if it was successful or not. Considering Events Debugger is a very recent feature at Algolia, I don't think there was another way to validate events and provide feedback if they're invalid.
We could've tried to fall back to `XHR` only in development mode (and provide error messages from the backend), but with the CDN version of the library cannot do that. Although we have no concrete metrics, but the usage via CDN would be much higher than via NPM, because we started documenting the usage via NPM since 2020.
## Solutions
First, we remove the validation logic from the library and send any events to the Insights API.
Second, we encourage users to go to the Events Debugger on dashboard for validation. Compared to error messages on browser console, the Events Debugger is better because:
1. We can provide information in rich format (code snippet, links to doc, etc.)
2. We can update the way we provide information anytime without customers having to update their search-insights version.
3. We can provide consistent workflows to customers.
- "If you directly use search-insights, after sending an event, go to our Events Debugger."
- "If you use Segment connector, after sending an event, go to Segment's Debugger."
- "If you use Google Tag Manager, after sending an event, go to GTM's debugger."
### Error messages on browser
We are not going to(cannot) display error messages from the backend on browser console. As explained earlier, `sendBeacon` cannot receive the HTTP response. We can consider removing `sendBeacon` and only use `XHR`. We actually need to consider it for some reasons, but it's out of the scope of this RFC.
We will display error messages only when it was unable to make an API call at all (e.g. `init` method was not called yet.)
## How to teach
- We encourage visiting Events Debugger through the documentation and GitHub README.
- We can put a URL for better access like we do with [https://www.algolia.com/api-keys](https://www.algolia.com/api-keys) (probably [https://www.algolia.com/events-debugger](https://www.algolia.com/events/debugger))
- If search-insights is installed via NPM and being used in development mode, we print out the information as a console log.