@@ -26,7 +26,7 @@ import {
26
26
} from './types' ;
27
27
28
28
const VIEW_EVENT_DELAY = 400 ;
29
- const ALGOLIA_INSIGHTS_VERSION = '2.6 .0' ;
29
+ const ALGOLIA_INSIGHTS_VERSION = '2.13 .0' ;
30
30
const ALGOLIA_INSIGHTS_SRC = `https://cdn.jsdelivr.net/npm/search-insights@${ ALGOLIA_INSIGHTS_VERSION } /dist/search-insights.min.js` ;
31
31
32
32
type SendViewedObjectIDsParams = {
@@ -170,14 +170,16 @@ export function createAlgoliaInsightsPlugin(
170
170
return {
171
171
name : 'aa.algoliaInsightsPlugin' ,
172
172
subscribe ( { setContext, onSelect, onActive } ) {
173
- function setInsightsContext ( userToken ?: string ) {
173
+ function setInsightsContext ( userToken ?: string | number ) {
174
174
setContext ( {
175
175
algoliaInsightsPlugin : {
176
176
__algoliaSearchParameters : {
177
177
...( __autocomplete_clickAnalytics
178
178
? { clickAnalytics : true }
179
179
: { } ) ,
180
- ...( userToken ? { userToken } : { } ) ,
180
+ ...( userToken
181
+ ? { userToken : normalizeUserToken ( userToken ) }
182
+ : { } ) ,
181
183
} ,
182
184
insights,
183
185
} ,
@@ -304,3 +306,11 @@ function loadInsights(environment: typeof window) {
304
306
console . error ( errorMessage ) ;
305
307
}
306
308
}
309
+
310
+ /**
311
+ * While `search-insights` supports both string and number user tokens,
312
+ * the Search API only accepts strings. This function normalizes the user token.
313
+ */
314
+ function normalizeUserToken ( userToken : string | number ) : string {
315
+ return typeof userToken === 'number' ? userToken . toString ( ) : userToken ;
316
+ }
0 commit comments