@@ -26,7 +26,7 @@ import {
2626}  from  './types' ; 
2727
2828const  VIEW_EVENT_DELAY  =  400 ; 
29- const  ALGOLIA_INSIGHTS_VERSION  =  '2.6 .0' ; 
29+ const  ALGOLIA_INSIGHTS_VERSION  =  '2.13 .0' ; 
3030const  ALGOLIA_INSIGHTS_SRC  =  `https://cdn.jsdelivr.net/npm/search-insights@${ ALGOLIA_INSIGHTS_VERSION }  /dist/search-insights.min.js` ; 
3131
3232type  SendViewedObjectIDsParams  =  { 
@@ -170,14 +170,16 @@ export function createAlgoliaInsightsPlugin(
170170  return  { 
171171    name : 'aa.algoliaInsightsPlugin' , 
172172    subscribe ( {  setContext,  onSelect,  onActive } )  { 
173-       function  setInsightsContext ( userToken ?: string )  { 
173+       function  setInsightsContext ( userToken ?: string   |   number )  { 
174174        setContext ( { 
175175          algoliaInsightsPlugin : { 
176176            __algoliaSearchParameters : { 
177177              ...( __autocomplete_clickAnalytics 
178178                ? {  clickAnalytics : true  } 
179179                : { } ) , 
180-               ...( userToken  ? {  userToken }  : { } ) , 
180+               ...( userToken 
181+                 ? {  userToken : normalizeUserToken ( userToken )  } 
182+                 : { } ) , 
181183            } , 
182184            insights, 
183185          } , 
@@ -304,3 +306,11 @@ function loadInsights(environment: typeof window) {
304306    console . error ( errorMessage ) ; 
305307  } 
306308} 
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