instantsearch.js 4.54.1 → 4.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/cjs/components/Hits/Hits.js +16 -7
  2. package/cjs/components/InfiniteHits/InfiniteHits.js +13 -2
  3. package/cjs/connectors/autocomplete/connectAutocomplete.js +1 -1
  4. package/cjs/connectors/geo-search/connectGeoSearch.js +1 -1
  5. package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +1 -1
  6. package/cjs/connectors/hits/connectHits.js +1 -1
  7. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +39 -31
  8. package/cjs/connectors/menu/connectMenu.js +1 -1
  9. package/cjs/connectors/numeric-menu/connectNumericMenu.js +1 -1
  10. package/cjs/connectors/rating-menu/connectRatingMenu.js +7 -3
  11. package/cjs/connectors/refinement-list/connectRefinementList.js +1 -1
  12. package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +14 -4
  13. package/cjs/helpers/insights.js +3 -4
  14. package/cjs/lib/InstantSearch.js +18 -2
  15. package/cjs/lib/insights/listener.js +43 -36
  16. package/cjs/lib/routers/history.js +1 -0
  17. package/cjs/lib/stateMappings/simple.js +1 -0
  18. package/cjs/lib/stateMappings/singleIndex.js +1 -0
  19. package/cjs/lib/utils/createSendEventForFacet.js +12 -2
  20. package/cjs/lib/utils/createSendEventForHits.js +34 -11
  21. package/cjs/lib/version.js +1 -1
  22. package/cjs/middlewares/createInsightsMiddleware.js +135 -33
  23. package/cjs/middlewares/createMetadataMiddleware.js +17 -5
  24. package/cjs/middlewares/createRouterMiddleware.js +5 -1
  25. package/cjs/widgets/hits/hits.js +1 -2
  26. package/cjs/widgets/infinite-hits/infinite-hits.js +1 -2
  27. package/dist/instantsearch.development.d.ts +67 -8
  28. package/dist/instantsearch.development.js +433 -251
  29. package/dist/instantsearch.development.js.map +1 -1
  30. package/dist/instantsearch.production.d.ts +67 -8
  31. package/dist/instantsearch.production.min.d.ts +67 -8
  32. package/dist/instantsearch.production.min.js +2 -2
  33. package/dist/instantsearch.production.min.js.map +1 -1
  34. package/es/components/Hits/Hits.d.ts +5 -5
  35. package/es/components/Hits/Hits.js +15 -5
  36. package/es/components/InfiniteHits/InfiniteHits.d.ts +3 -2
  37. package/es/components/InfiniteHits/InfiniteHits.js +13 -2
  38. package/es/connectors/autocomplete/connectAutocomplete.js +1 -1
  39. package/es/connectors/geo-search/connectGeoSearch.js +1 -1
  40. package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +1 -1
  41. package/es/connectors/hits/connectHits.js +1 -1
  42. package/es/connectors/infinite-hits/connectInfiniteHits.js +39 -31
  43. package/es/connectors/menu/connectMenu.js +1 -1
  44. package/es/connectors/numeric-menu/connectNumericMenu.js +1 -1
  45. package/es/connectors/rating-menu/connectRatingMenu.js +7 -3
  46. package/es/connectors/refinement-list/connectRefinementList.js +1 -1
  47. package/es/connectors/toggle-refinement/connectToggleRefinement.js +13 -3
  48. package/es/helpers/insights.d.ts +2 -1
  49. package/es/helpers/insights.js +3 -3
  50. package/es/lib/InstantSearch.d.ts +11 -1
  51. package/es/lib/InstantSearch.js +18 -2
  52. package/es/lib/insights/listener.d.ts +10 -6
  53. package/es/lib/insights/listener.js +42 -36
  54. package/es/lib/routers/history.d.ts +1 -0
  55. package/es/lib/routers/history.js +1 -0
  56. package/es/lib/stateMappings/simple.js +1 -0
  57. package/es/lib/stateMappings/singleIndex.js +1 -0
  58. package/es/lib/utils/createSendEventForFacet.js +12 -2
  59. package/es/lib/utils/createSendEventForHits.d.ts +8 -0
  60. package/es/lib/utils/createSendEventForHits.js +33 -11
  61. package/es/lib/version.d.ts +1 -1
  62. package/es/lib/version.js +1 -1
  63. package/es/middlewares/createInsightsMiddleware.d.ts +12 -12
  64. package/es/middlewares/createInsightsMiddleware.js +136 -34
  65. package/es/middlewares/createMetadataMiddleware.d.ts +3 -1
  66. package/es/middlewares/createMetadataMiddleware.js +17 -5
  67. package/es/middlewares/createRouterMiddleware.js +5 -1
  68. package/es/types/insights.d.ts +19 -1
  69. package/es/types/middleware.d.ts +16 -0
  70. package/es/types/router.d.ts +8 -0
  71. package/es/widgets/hits/hits.js +2 -3
  72. package/es/widgets/infinite-hits/infinite-hits.js +2 -3
  73. package/package.json +6 -6
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.54.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.55.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -748,10 +748,13 @@
748
748
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
749
749
  args[_key] = arguments[_key];
750
750
  }
751
- var eventType = args[0],
752
- facetValue = args[1],
751
+ var facetValue = args[1],
753
752
  _args$ = args[2],
754
753
  eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
754
+ var _args$0$split = args[0].split(':'),
755
+ _args$0$split2 = _slicedToArray(_args$0$split, 2),
756
+ eventType = _args$0$split2[0],
757
+ eventModifier = _args$0$split2[1];
755
758
  var attribute = typeof attr === 'string' ? attr : attr(facetValue);
756
759
  if (args.length === 1 && _typeof(args[0]) === 'object') {
757
760
  instantSearchInstance.sendEventToInsights(args[0]);
@@ -762,6 +765,7 @@
762
765
  insightsMethod: 'clickedFilters',
763
766
  widgetType: widgetType,
764
767
  eventType: eventType,
768
+ eventModifier: eventModifier,
765
769
  payload: {
766
770
  eventName: eventName,
767
771
  index: helper.getIndex(),
@@ -792,7 +796,7 @@
792
796
  }
793
797
  return chunks;
794
798
  }
795
- var buildPayloads = function buildPayloads(_ref) {
799
+ function _buildEventPayloadsForHits(_ref) {
796
800
  var index = _ref.index,
797
801
  widgetType = _ref.widgetType,
798
802
  methodName = _ref.methodName,
@@ -802,7 +806,10 @@
802
806
  if (args.length === 1 && _typeof(args[0]) === 'object') {
803
807
  return [args[0]];
804
808
  }
805
- var eventType = args[0];
809
+ var _args$0$split = args[0].split(':'),
810
+ _args$0$split2 = _slicedToArray(_args$0$split, 2),
811
+ eventType = _args$0$split2[0],
812
+ eventModifier = _args$0$split2[1];
806
813
  var hits = args[1];
807
814
  var eventName = args[2];
808
815
  if (!hits) {
@@ -845,7 +852,8 @@
845
852
  index: index,
846
853
  objectIDs: objectIDsByChunk[i]
847
854
  },
848
- hits: batch
855
+ hits: batch,
856
+ eventModifier: eventModifier
849
857
  };
850
858
  });
851
859
  } else if (eventType === 'click') {
@@ -855,13 +863,14 @@
855
863
  widgetType: widgetType,
856
864
  eventType: eventType,
857
865
  payload: {
858
- eventName: eventName,
866
+ eventName: eventName || 'Hit Clicked',
859
867
  index: index,
860
868
  queryID: queryID,
861
869
  objectIDs: objectIDsByChunk[i],
862
870
  positions: positionsByChunk[i]
863
871
  },
864
- hits: batch
872
+ hits: batch,
873
+ eventModifier: eventModifier
865
874
  };
866
875
  });
867
876
  } else if (eventType === 'conversion') {
@@ -871,27 +880,30 @@
871
880
  widgetType: widgetType,
872
881
  eventType: eventType,
873
882
  payload: {
874
- eventName: eventName,
883
+ eventName: eventName || 'Hit Converted',
875
884
  index: index,
876
885
  queryID: queryID,
877
886
  objectIDs: objectIDsByChunk[i]
878
887
  },
879
- hits: batch
888
+ hits: batch,
889
+ eventModifier: eventModifier
880
890
  };
881
891
  });
882
892
  } else {
883
893
  throw new Error("eventType(\"".concat(eventType, "\") is not supported.\n If you want to send a custom payload, you can pass one object: ").concat(methodName, "(customPayload);\n "));
884
894
  }
885
- };
895
+ }
886
896
  function createSendEventForHits(_ref2) {
887
897
  var instantSearchInstance = _ref2.instantSearchInstance,
888
898
  index = _ref2.index,
889
899
  widgetType = _ref2.widgetType;
900
+ var sentEvents = {};
901
+ var timer = undefined;
890
902
  var sendEventForHits = function sendEventForHits() {
891
903
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
892
904
  args[_key] = arguments[_key];
893
905
  }
894
- var payloads = buildPayloads({
906
+ var payloads = _buildEventPayloadsForHits({
895
907
  widgetType: widgetType,
896
908
  index: index,
897
909
  methodName: 'sendEvent',
@@ -899,8 +911,16 @@
899
911
  instantSearchInstance: instantSearchInstance
900
912
  });
901
913
  payloads.forEach(function (payload) {
902
- return instantSearchInstance.sendEventToInsights(payload);
914
+ if (payload.eventType === 'click' && payload.eventModifier === 'internal' && sentEvents[payload.eventType]) {
915
+ return;
916
+ }
917
+ sentEvents[payload.eventType] = true;
918
+ instantSearchInstance.sendEventToInsights(payload);
903
919
  });
920
+ clearTimeout(timer);
921
+ timer = setTimeout(function () {
922
+ sentEvents = {};
923
+ }, 0);
904
924
  };
905
925
  return sendEventForHits;
906
926
  }
@@ -912,7 +932,7 @@
912
932
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
913
933
  args[_key2] = arguments[_key2];
914
934
  }
915
- var payloads = buildPayloads({
935
+ var payloads = _buildEventPayloadsForHits({
916
936
  widgetType: widgetType,
917
937
  index: index,
918
938
  methodName: 'bindEvent',
@@ -2384,7 +2404,7 @@
2384
2404
  }
2385
2405
  if (!_refine) {
2386
2406
  _refine = function _refine(facetValue) {
2387
- sendEvent('click', facetValue);
2407
+ sendEvent('click:internal', facetValue);
2388
2408
  helper.toggleFacetRefinement(hierarchicalFacetName, facetValue).search();
2389
2409
  };
2390
2410
  }
@@ -2490,7 +2510,7 @@
2490
2510
  renderFn(_objectSpread2(_objectSpread2({}, renderState), {}, {
2491
2511
  instantSearchInstance: renderOptions.instantSearchInstance
2492
2512
  }), false);
2493
- renderState.sendEvent('view', renderState.hits);
2513
+ renderState.sendEvent('view:internal', renderState.hits);
2494
2514
  },
2495
2515
  getRenderState: function getRenderState(renderState, renderOptions) {
2496
2516
  return _objectSpread2(_objectSpread2({}, renderState), {}, {
@@ -2667,6 +2687,7 @@
2667
2687
 
2668
2688
  var n,l,u,t,o,r,f={},e=[],c=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function s(n,l){for(var u in l)n[u]=l[u];return n}function a(n){var l=n.parentNode;l&&l.removeChild(n);}function h(l,u,i){var t,o,r,f={};for(r in u)"key"==r?t=u[r]:"ref"==r?o=u[r]:f[r]=u[r];if(arguments.length>2&&(f.children=arguments.length>3?n.call(arguments,2):i),"function"==typeof l&&null!=l.defaultProps)for(r in l.defaultProps)void 0===f[r]&&(f[r]=l.defaultProps[r]);return v(l,f,t,o,null)}function v(n,i,t,o,r){var f={type:n,props:i,key:t,ref:o,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==r?++u:r};return null==r&&null!=l.vnode&&l.vnode(f),f}function y(){return {current:null}}function p(n){return n.children}function d(n,l){this.props=n,this.context=l;}function _(n,l){if(null==l)return n.__?_(n.__,n.__.__k.indexOf(n)+1):null;for(var u;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e)return u.__e;return "function"==typeof n.type?_(n):null}function k(n){var l,u;if(null!=(n=n.__)&&null!=n.__c){for(n.__e=n.__c.base=null,l=0;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e){n.__e=n.__c.base=u.__e;break}return k(n)}}function b(n){(!n.__d&&(n.__d=!0)&&t.push(n)&&!g.__r++||o!==l.debounceRendering)&&((o=l.debounceRendering)||setTimeout)(g);}function g(){for(var n;g.__r=t.length;)n=t.sort(function(n,l){return n.__v.__b-l.__v.__b}),t=[],n.some(function(n){var l,u,i,t,o,r;n.__d&&(o=(t=(l=n).__v).__e,(r=l.__P)&&(u=[],(i=s({},t)).__v=t.__v+1,j(r,t,i,l.__n,void 0!==r.ownerSVGElement,null!=t.__h?[o]:null,u,null==o?_(t):o,t.__h),z(u,t),t.__e!=o&&k(t)));});}function w(n,l,u,i,t,o,r,c,s,a){var h,y,d,k,b,g,w,x=i&&i.__k||e,C=x.length;for(u.__k=[],h=0;h<l.length;h++)if(null!=(k=u.__k[h]=null==(k=l[h])||"boolean"==typeof k?null:"string"==typeof k||"number"==typeof k||"bigint"==typeof k?v(null,k,null,null,k):Array.isArray(k)?v(p,{children:k},null,null,null):k.__b>0?v(k.type,k.props,k.key,k.ref?k.ref:null,k.__v):k)){if(k.__=u,k.__b=u.__b+1,null===(d=x[h])||d&&k.key==d.key&&k.type===d.type)x[h]=void 0;else for(y=0;y<C;y++){if((d=x[y])&&k.key==d.key&&k.type===d.type){x[y]=void 0;break}d=null;}j(n,k,d=d||f,t,o,r,c,s,a),b=k.__e,(y=k.ref)&&d.ref!=y&&(w||(w=[]),d.ref&&w.push(d.ref,null,k),w.push(y,k.__c||b,k)),null!=b?(null==g&&(g=b),"function"==typeof k.type&&k.__k===d.__k?k.__d=s=m(k,s,n):s=A(n,k,d,x,b,s),"function"==typeof u.type&&(u.__d=s)):s&&d.__e==s&&s.parentNode!=n&&(s=_(d));}for(u.__e=g,h=C;h--;)null!=x[h]&&("function"==typeof u.type&&null!=x[h].__e&&x[h].__e==u.__d&&(u.__d=_(i,h+1)),N(x[h],x[h]));if(w)for(h=0;h<w.length;h++)M(w[h],w[++h],w[++h]);}function m(n,l,u){for(var i,t=n.__k,o=0;t&&o<t.length;o++)(i=t[o])&&(i.__=n,l="function"==typeof i.type?m(i,l,u):A(u,i,i,t,i.__e,l));return l}function A(n,l,u,i,t,o){var r,f,e;if(void 0!==l.__d)r=l.__d,l.__d=void 0;else if(null==u||t!=o||null==t.parentNode)n:if(null==o||o.parentNode!==n)n.appendChild(t),r=null;else{for(f=o,e=0;(f=f.nextSibling)&&e<i.length;e+=2)if(f==t)break n;n.insertBefore(t,o),r=o;}return void 0!==r?r:t.nextSibling}function C(n,l,u,i,t){var o;for(o in u)"children"===o||"key"===o||o in l||H(n,o,null,u[o],i);for(o in l)t&&"function"!=typeof l[o]||"children"===o||"key"===o||"value"===o||"checked"===o||u[o]===l[o]||H(n,o,l[o],u[o],i);}function $(n,l,u){"-"===l[0]?n.setProperty(l,u):n[l]=null==u?"":"number"!=typeof u||c.test(l)?u:u+"px";}function H(n,l,u,i,t){var o;n:if("style"===l)if("string"==typeof u)n.style.cssText=u;else{if("string"==typeof i&&(n.style.cssText=i=""),i)for(l in i)u&&l in u||$(n.style,l,"");if(u)for(l in u)i&&u[l]===i[l]||$(n.style,l,u[l]);}else if("o"===l[0]&&"n"===l[1])o=l!==(l=l.replace(/Capture$/,"")),l=l.toLowerCase()in n?l.toLowerCase().slice(2):l.slice(2),n.l||(n.l={}),n.l[l+o]=u,u?i||n.addEventListener(l,o?T:I,o):n.removeEventListener(l,o?T:I,o);else if("dangerouslySetInnerHTML"!==l){if(t)l=l.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("href"!==l&&"list"!==l&&"form"!==l&&"tabIndex"!==l&&"download"!==l&&l in n)try{n[l]=null==u?"":u;break n}catch(n){}"function"==typeof u||(null!=u&&(!1!==u||"a"===l[0]&&"r"===l[1])?n.setAttribute(l,u):n.removeAttribute(l));}}function I(n){this.l[n.type+!1](l.event?l.event(n):n);}function T(n){this.l[n.type+!0](l.event?l.event(n):n);}function j(n,u,i,t,o,r,f,e,c){var a,h,v,y,_,k,b,g,m,x,A,C,$,H=u.type;if(void 0!==u.constructor)return null;null!=i.__h&&(c=i.__h,e=u.__e=i.__e,u.__h=null,r=[e]),(a=l.__b)&&a(u);try{n:if("function"==typeof H){if(g=u.props,m=(a=H.contextType)&&t[a.__c],x=a?m?m.props.value:a.__:t,i.__c?b=(h=u.__c=i.__c).__=h.__E:("prototype"in H&&H.prototype.render?u.__c=h=new H(g,x):(u.__c=h=new d(g,x),h.constructor=H,h.render=O),m&&m.sub(h),h.props=g,h.state||(h.state={}),h.context=x,h.__n=t,v=h.__d=!0,h.__h=[]),null==h.__s&&(h.__s=h.state),null!=H.getDerivedStateFromProps&&(h.__s==h.state&&(h.__s=s({},h.__s)),s(h.__s,H.getDerivedStateFromProps(g,h.__s))),y=h.props,_=h.state,v)null==H.getDerivedStateFromProps&&null!=h.componentWillMount&&h.componentWillMount(),null!=h.componentDidMount&&h.__h.push(h.componentDidMount);else{if(null==H.getDerivedStateFromProps&&g!==y&&null!=h.componentWillReceiveProps&&h.componentWillReceiveProps(g,x),!h.__e&&null!=h.shouldComponentUpdate&&!1===h.shouldComponentUpdate(g,h.__s,x)||u.__v===i.__v){h.props=g,h.state=h.__s,u.__v!==i.__v&&(h.__d=!1),h.__v=u,u.__e=i.__e,u.__k=i.__k,u.__k.forEach(function(n){n&&(n.__=u);}),h.__h.length&&f.push(h);break n}null!=h.componentWillUpdate&&h.componentWillUpdate(g,h.__s,x),null!=h.componentDidUpdate&&h.__h.push(function(){h.componentDidUpdate(y,_,k);});}if(h.context=x,h.props=g,h.__v=u,h.__P=n,A=l.__r,C=0,"prototype"in H&&H.prototype.render)h.state=h.__s,h.__d=!1,A&&A(u),a=h.render(h.props,h.state,h.context);else do{h.__d=!1,A&&A(u),a=h.render(h.props,h.state,h.context),h.state=h.__s;}while(h.__d&&++C<25);h.state=h.__s,null!=h.getChildContext&&(t=s(s({},t),h.getChildContext())),v||null==h.getSnapshotBeforeUpdate||(k=h.getSnapshotBeforeUpdate(y,_)),$=null!=a&&a.type===p&&null==a.key?a.props.children:a,w(n,Array.isArray($)?$:[$],u,i,t,o,r,f,e,c),h.base=u.__e,u.__h=null,h.__h.length&&f.push(h),b&&(h.__E=h.__=null),h.__e=!1;}else null==r&&u.__v===i.__v?(u.__k=i.__k,u.__e=i.__e):u.__e=L(i.__e,u,i,t,o,r,f,c);(a=l.diffed)&&a(u);}catch(n){u.__v=null,(c||null!=r)&&(u.__e=e,u.__h=!!c,r[r.indexOf(e)]=null),l.__e(n,u,i);}}function z(n,u){l.__c&&l.__c(u,n),n.some(function(u){try{n=u.__h,u.__h=[],n.some(function(n){n.call(u);});}catch(n){l.__e(n,u.__v);}});}function L(l,u,i,t,o,r,e,c){var s,h,v,y=i.props,p=u.props,d=u.type,k=0;if("svg"===d&&(o=!0),null!=r)for(;k<r.length;k++)if((s=r[k])&&"setAttribute"in s==!!d&&(d?s.localName===d:3===s.nodeType)){l=s,r[k]=null;break}if(null==l){if(null===d)return document.createTextNode(p);l=o?document.createElementNS("http://www.w3.org/2000/svg",d):document.createElement(d,p.is&&p),r=null,c=!1;}if(null===d)y===p||c&&l.data===p||(l.data=p);else{if(r=r&&n.call(l.childNodes),h=(y=i.props||f).dangerouslySetInnerHTML,v=p.dangerouslySetInnerHTML,!c){if(null!=r)for(y={},k=0;k<l.attributes.length;k++)y[l.attributes[k].name]=l.attributes[k].value;(v||h)&&(v&&(h&&v.__html==h.__html||v.__html===l.innerHTML)||(l.innerHTML=v&&v.__html||""));}if(C(l,p,y,o,c),v)u.__k=[];else if(k=u.props.children,w(l,Array.isArray(k)?k:[k],u,i,t,o&&"foreignObject"!==d,r,e,r?r[0]:i.__k&&_(i,0),c),null!=r)for(k=r.length;k--;)null!=r[k]&&a(r[k]);c||("value"in p&&void 0!==(k=p.value)&&(k!==l.value||"progress"===d&&!k||"option"===d&&k!==y.value)&&H(l,"value",k,y.value,!1),"checked"in p&&void 0!==(k=p.checked)&&k!==l.checked&&H(l,"checked",k,y.checked,!1));}return l}function M(n,u,i){try{"function"==typeof n?n(u):n.current=u;}catch(n){l.__e(n,i);}}function N(n,u,i){var t,o;if(l.unmount&&l.unmount(n),(t=n.ref)&&(t.current&&t.current!==n.__e||M(t,null,u)),null!=(t=n.__c)){if(t.componentWillUnmount)try{t.componentWillUnmount();}catch(n){l.__e(n,u);}t.base=t.__P=null,n.__c=void 0;}if(t=n.__k)for(o=0;o<t.length;o++)t[o]&&N(t[o],u,"function"!=typeof n.type);i||null==n.__e||a(n.__e),n.__=n.__e=n.__d=void 0;}function O(n,l,u){return this.constructor(n,u)}function P(u,i,t){var o,r,e;l.__&&l.__(u,i),r=(o="function"==typeof t)?null:t&&t.__k||i.__k,e=[],j(i,u=(!o&&t||i).__k=h(p,null,[u]),r||f,f,void 0!==i.ownerSVGElement,!o&&t?[t]:r?null:i.firstChild?n.call(i.childNodes):null,e,!o&&t?t:r?r.__e:i.firstChild,o),z(e,u);}n=e.slice,l={__e:function(n,l,u,i){for(var t,o,r;l=l.__;)if((t=l.__c)&&!t.__)try{if((o=t.constructor)&&null!=o.getDerivedStateFromError&&(t.setState(o.getDerivedStateFromError(n)),r=t.__d),null!=t.componentDidCatch&&(t.componentDidCatch(n,i||{}),r=t.__d),r)return t.__E=t}catch(l){n=l;}throw n}},u=0,d.prototype.setState=function(n,l){var u;u=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=s({},this.state),"function"==typeof n&&(n=n(s({},u),this.props)),n&&s(u,n),null!=n&&this.__v&&(l&&this.__h.push(l),b(this));},d.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),b(this));},d.prototype.render=p,t=[],g.__r=0,r=0;
2669
2689
 
2690
+ /** @deprecated use bindEvent instead */
2670
2691
  function readDataAttributes(domElement) {
2671
2692
  var method = domElement.getAttribute('data-insights-method');
2672
2693
  var serializedPayload = domElement.getAttribute('data-insights-payload');
@@ -2683,9 +2704,8 @@
2683
2704
  throw new Error('The insights helper was unable to parse `data-insights-payload`.');
2684
2705
  }
2685
2706
  }
2686
- function hasDataAttributes(domElement) {
2687
- return domElement.hasAttribute('data-insights-method');
2688
- }
2707
+
2708
+ /** @deprecated use bindEvent instead */
2689
2709
  function writeDataAttributes(_ref) {
2690
2710
  var method = _ref.method,
2691
2711
  payload = _ref.payload;
@@ -2712,7 +2732,34 @@
2712
2732
  });
2713
2733
  }
2714
2734
 
2715
- var findInsightsTarget = function findInsightsTarget(startElement, endElement, validator) {
2735
+ var createInsightsEventHandler = function createInsightsEventHandler(_ref) {
2736
+ var insights = _ref.insights,
2737
+ sendEvent = _ref.sendEvent;
2738
+ return function (event) {
2739
+ // new way, e.g. bindEvent("click", hit, "Hit clicked")
2740
+ var insightsThroughSendEvent = findInsightsTarget(event.target, event.currentTarget, function (element) {
2741
+ return element.hasAttribute('data-insights-event');
2742
+ });
2743
+ if (insightsThroughSendEvent) {
2744
+ var payload = parseInsightsEvent(insightsThroughSendEvent);
2745
+ payload.forEach(function (single) {
2746
+ return sendEvent(single);
2747
+ });
2748
+ }
2749
+
2750
+ // old way, e.g. instantsearch.insights("clickedObjectIDsAfterSearch", { .. })
2751
+ var insightsThroughFunction = findInsightsTarget(event.target, event.currentTarget, function (element) {
2752
+ return element.hasAttribute('data-insights-method') && element.hasAttribute('data-insights-payload');
2753
+ });
2754
+ if (insightsThroughFunction) {
2755
+ var _readDataAttributes = readDataAttributes(insightsThroughFunction),
2756
+ method = _readDataAttributes.method,
2757
+ _payload = _readDataAttributes.payload;
2758
+ insights(method, _payload);
2759
+ }
2760
+ };
2761
+ };
2762
+ function findInsightsTarget(startElement, endElement, validator) {
2716
2763
  var element = startElement;
2717
2764
  while (element && !validator(element)) {
2718
2765
  if (element === endElement) {
@@ -2721,8 +2768,8 @@
2721
2768
  element = element.parentElement;
2722
2769
  }
2723
2770
  return element;
2724
- };
2725
- var parseInsightsEvent = function parseInsightsEvent(element) {
2771
+ }
2772
+ function parseInsightsEvent(element) {
2726
2773
  var serializedPayload = element.getAttribute('data-insights-event');
2727
2774
  if (typeof serializedPayload !== 'string') {
2728
2775
  throw new Error('The insights middleware expects `data-insights-event` to be a base64-encoded JSON string.');
@@ -2732,40 +2779,7 @@
2732
2779
  } catch (error) {
2733
2780
  throw new Error('The insights middleware was unable to parse `data-insights-event`.');
2734
2781
  }
2735
- };
2736
- var insightsListener = function insightsListener(BaseComponent) {
2737
- function WithInsightsListener(props) {
2738
- var handleClick = function handleClick(event) {
2739
- if (props.sendEvent) {
2740
- // new way with insights middleware
2741
- var targetWithEvent = findInsightsTarget(event.target, event.currentTarget, function (element) {
2742
- return element.hasAttribute('data-insights-event');
2743
- });
2744
- if (targetWithEvent) {
2745
- var payload = parseInsightsEvent(targetWithEvent);
2746
- payload.forEach(function (single) {
2747
- return props.sendEvent(single);
2748
- });
2749
- }
2750
- }
2751
-
2752
- // old way, e.g. instantsearch.insights("clickedObjectIDsAfterSearch", { .. })
2753
- var insightsTarget = findInsightsTarget(event.target, event.currentTarget, function (element) {
2754
- return hasDataAttributes(element);
2755
- });
2756
- if (insightsTarget) {
2757
- var _readDataAttributes = readDataAttributes(insightsTarget),
2758
- method = _readDataAttributes.method,
2759
- _payload = _readDataAttributes.payload;
2760
- props.insights(method, _payload);
2761
- }
2762
- };
2763
- return h("div", {
2764
- onClick: handleClick
2765
- }, h(BaseComponent, props));
2766
- }
2767
- return WithInsightsListener;
2768
- };
2782
+ }
2769
2783
 
2770
2784
  var connectHitsWithInsights = withInsights(connectHits);
2771
2785
 
@@ -2897,7 +2911,8 @@
2897
2911
  };
2898
2912
  };
2899
2913
 
2900
- var _excluded$2 = ["page"];
2914
+ var _excluded$2 = ["page"],
2915
+ _excluded2 = ["clickAnalytics", "userToken"];
2901
2916
  var withUsage$7 = createDocumentationMessageGenerator({
2902
2917
  name: 'infinite-hits',
2903
2918
  connector: true
@@ -2908,17 +2923,24 @@
2908
2923
  rest = _objectWithoutProperties(_ref, _excluded$2);
2909
2924
  return rest;
2910
2925
  }
2926
+ function normalizeState(state) {
2927
+ var _ref2 = state || {},
2928
+ clickAnalytics = _ref2.clickAnalytics,
2929
+ userToken = _ref2.userToken,
2930
+ rest = _objectWithoutProperties(_ref2, _excluded2);
2931
+ return rest;
2932
+ }
2911
2933
  function getInMemoryCache() {
2912
2934
  var cachedHits = null;
2913
2935
  var cachedState = null;
2914
2936
  return {
2915
- read: function read(_ref2) {
2916
- var state = _ref2.state;
2937
+ read: function read(_ref3) {
2938
+ var state = _ref3.state;
2917
2939
  return isEqual(cachedState, getStateWithoutPage(state)) ? cachedHits : null;
2918
2940
  },
2919
- write: function write(_ref3) {
2920
- var state = _ref3.state,
2921
- hits = _ref3.hits;
2941
+ write: function write(_ref4) {
2942
+ var state = _ref4.state,
2943
+ hits = _ref4.hits;
2922
2944
  cachedState = getStateWithoutPage(state);
2923
2945
  cachedHits = hits;
2924
2946
  }
@@ -2938,15 +2960,15 @@
2938
2960
  // @TODO: this should be a generic, but a Connector can not yet be generic itself
2939
2961
 
2940
2962
  return function (widgetParams) {
2941
- var _ref4 = widgetParams || {},
2942
- _ref4$escapeHTML = _ref4.escapeHTML,
2943
- escapeHTML = _ref4$escapeHTML === void 0 ? true : _ref4$escapeHTML,
2944
- _ref4$transformItems = _ref4.transformItems,
2945
- transformItems = _ref4$transformItems === void 0 ? function (items) {
2963
+ var _ref5 = widgetParams || {},
2964
+ _ref5$escapeHTML = _ref5.escapeHTML,
2965
+ escapeHTML = _ref5$escapeHTML === void 0 ? true : _ref5$escapeHTML,
2966
+ _ref5$transformItems = _ref5.transformItems,
2967
+ transformItems = _ref5$transformItems === void 0 ? function (items) {
2946
2968
  return items;
2947
- } : _ref4$transformItems,
2948
- _ref4$cache = _ref4.cache,
2949
- cache = _ref4$cache === void 0 ? getInMemoryCache() : _ref4$cache;
2969
+ } : _ref5$transformItems,
2970
+ _ref5$cache = _ref5.cache,
2971
+ cache = _ref5$cache === void 0 ? getInMemoryCache() : _ref5$cache;
2950
2972
  var showPrevious;
2951
2973
  var showMore;
2952
2974
  var sendEvent;
@@ -2977,7 +2999,7 @@
2977
2999
  // avoid updating the browser URL when the user displays the previous page.
2978
3000
  helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), {}, {
2979
3001
  page: getFirstReceivedPage(helper.state, cache.read({
2980
- state: helper.state
3002
+ state: normalizeState(helper.state)
2981
3003
  }) || {}) - 1
2982
3004
  })).searchWithoutTriggeringOnStateChange();
2983
3005
  };
@@ -2985,7 +3007,7 @@
2985
3007
  var getShowMore = function getShowMore(helper) {
2986
3008
  return function () {
2987
3009
  helper.setPage(getLastReceivedPage(helper.state, cache.read({
2988
- state: helper.state
3010
+ state: normalizeState(helper.state)
2989
3011
  }) || {}) + 1).search();
2990
3012
  };
2991
3013
  };
@@ -3002,19 +3024,19 @@
3002
3024
  renderFn(_objectSpread2(_objectSpread2({}, widgetRenderState), {}, {
3003
3025
  instantSearchInstance: instantSearchInstance
3004
3026
  }), false);
3005
- sendEvent('view', widgetRenderState.currentPageHits);
3027
+ sendEvent('view:internal', widgetRenderState.currentPageHits);
3006
3028
  },
3007
3029
  getRenderState: function getRenderState(renderState, renderOptions) {
3008
3030
  return _objectSpread2(_objectSpread2({}, renderState), {}, {
3009
3031
  infiniteHits: this.getWidgetRenderState(renderOptions)
3010
3032
  });
3011
3033
  },
3012
- getWidgetRenderState: function getWidgetRenderState(_ref5) {
3013
- var results = _ref5.results,
3014
- helper = _ref5.helper,
3015
- parent = _ref5.parent,
3016
- existingState = _ref5.state,
3017
- instantSearchInstance = _ref5.instantSearchInstance;
3034
+ getWidgetRenderState: function getWidgetRenderState(_ref6) {
3035
+ var results = _ref6.results,
3036
+ helper = _ref6.helper,
3037
+ parent = _ref6.parent,
3038
+ existingState = _ref6.state,
3039
+ instantSearchInstance = _ref6.instantSearchInstance;
3018
3040
  var isFirstPage;
3019
3041
  var currentPageHits = [];
3020
3042
  /**
@@ -3024,7 +3046,7 @@
3024
3046
  */
3025
3047
  var state = parent.getPreviousState() || existingState;
3026
3048
  var cachedHits = cache.read({
3027
- state: state
3049
+ state: normalizeState(state)
3028
3050
  }) || {};
3029
3051
  if (!results) {
3030
3052
  showPrevious = getShowPrevious(helper);
@@ -3054,7 +3076,7 @@
3054
3076
  if (cachedHits[_page] === undefined && !results.__isArtificial && instantSearchInstance.status === 'idle') {
3055
3077
  cachedHits[_page] = transformedHits;
3056
3078
  cache.write({
3057
- state: state,
3079
+ state: normalizeState(state),
3058
3080
  hits: cachedHits
3059
3081
  });
3060
3082
  }
@@ -3076,8 +3098,8 @@
3076
3098
  widgetParams: widgetParams
3077
3099
  };
3078
3100
  },
3079
- dispose: function dispose(_ref6) {
3080
- var state = _ref6.state;
3101
+ dispose: function dispose(_ref7) {
3102
+ var state = _ref7.state;
3081
3103
  unmountFn();
3082
3104
  var stateWithoutPage = state.setQueryParameter('page', undefined);
3083
3105
  if (!escapeHTML) {
@@ -3087,8 +3109,8 @@
3087
3109
  return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, undefined));
3088
3110
  }, {}));
3089
3111
  },
3090
- getWidgetUiState: function getWidgetUiState(uiState, _ref7) {
3091
- var searchParameters = _ref7.searchParameters;
3112
+ getWidgetUiState: function getWidgetUiState(uiState, _ref8) {
3113
+ var searchParameters = _ref8.searchParameters;
3092
3114
  var page = searchParameters.page || 0;
3093
3115
  if (!page) {
3094
3116
  // return without adding `page` to uiState
@@ -3101,8 +3123,8 @@
3101
3123
  page: page + 1
3102
3124
  });
3103
3125
  },
3104
- getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref8) {
3105
- var uiState = _ref8.uiState;
3126
+ getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref9) {
3127
+ var uiState = _ref9.uiState;
3106
3128
  var widgetSearchParameters = searchParameters;
3107
3129
  if (escapeHTML) {
3108
3130
  widgetSearchParameters = searchParameters.setQueryParameters(TAG_PLACEHOLDER);
@@ -3227,7 +3249,7 @@
3227
3249
  var _helper$getHierarchic = helper.getHierarchicalFacetBreadcrumb(attribute),
3228
3250
  _helper$getHierarchic2 = _slicedToArray(_helper$getHierarchic, 1),
3229
3251
  refinedItem = _helper$getHierarchic2[0];
3230
- sendEvent('click', facetValue ? facetValue : refinedItem);
3252
+ sendEvent('click:internal', facetValue ? facetValue : refinedItem);
3231
3253
  helper.toggleFacetRefinement(attribute, facetValue ? facetValue : refinedItem).search();
3232
3254
  };
3233
3255
  }
@@ -3428,7 +3450,7 @@
3428
3450
  if (!connectorState.refine) {
3429
3451
  connectorState.refine = function (facetValue) {
3430
3452
  var refinedState = getRefinedState(helper.state, attribute, facetValue);
3431
- connectorState.sendEvent('click', facetValue);
3453
+ connectorState.sendEvent('click:internal', facetValue);
3432
3454
  helper.setState(refinedState).search();
3433
3455
  };
3434
3456
  }
@@ -3992,7 +4014,7 @@
3992
4014
  };
3993
4015
 
3994
4016
  var _excluded$4 = ["name", "escapedValue"],
3995
- _excluded2 = ["escapedValue", "value"];
4017
+ _excluded2$1 = ["escapedValue", "value"];
3996
4018
  var withUsage$c = createDocumentationMessageGenerator({
3997
4019
  name: 'refinement-list',
3998
4020
  connector: true
@@ -4101,7 +4123,7 @@
4101
4123
  var normalizedFacetValues = transformItems(facetValues.map(function (_ref3) {
4102
4124
  var escapedValue = _ref3.escapedValue,
4103
4125
  value = _ref3.value,
4104
- item = _objectWithoutProperties(_ref3, _excluded2);
4126
+ item = _objectWithoutProperties(_ref3, _excluded2$1);
4105
4127
  return _objectSpread2(_objectSpread2({}, item), {}, {
4106
4128
  value: escapedValue,
4107
4129
  label: value
@@ -4156,7 +4178,7 @@
4156
4178
  widgetType: this.$$type
4157
4179
  });
4158
4180
  triggerRefine = function triggerRefine(facetValue) {
4159
- sendEvent('click', facetValue);
4181
+ sendEvent('click:internal', facetValue);
4160
4182
  helper.toggleFacetRefinement(attribute, facetValue).search();
4161
4183
  };
4162
4184
  searchForFacetValues = createSearchForFacetValues(helper, this);
@@ -4459,10 +4481,13 @@
4459
4481
  instantSearchInstance.sendEventToInsights(args[0]);
4460
4482
  return;
4461
4483
  }
4462
- var eventType = args[0],
4463
- facetValue = args[1],
4484
+ var facetValue = args[1],
4464
4485
  _args$ = args[2],
4465
4486
  eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
4487
+ var _args$0$split = args[0].split(':'),
4488
+ _args$0$split2 = _slicedToArray(_args$0$split, 2),
4489
+ eventType = _args$0$split2[0],
4490
+ eventModifier = _args$0$split2[1];
4466
4491
  if (eventType !== 'click') {
4467
4492
  return;
4468
4493
  }
@@ -4472,6 +4497,7 @@
4472
4497
  insightsMethod: 'clickedFilters',
4473
4498
  widgetType: $$type$2,
4474
4499
  eventType: eventType,
4500
+ eventModifier: eventModifier,
4475
4501
  payload: {
4476
4502
  eventName: eventName,
4477
4503
  index: helper.getIndex(),
@@ -4547,7 +4573,7 @@
4547
4573
  return emptyState;
4548
4574
  }
4549
4575
  var toggleRefinement = function toggleRefinement(helper, facetValue) {
4550
- sendEvent('click', facetValue);
4576
+ sendEvent('click:internal', facetValue);
4551
4577
  helper.setState(getRefinedState(helper.state, facetValue)).search();
4552
4578
  };
4553
4579
  var connectorState = {
@@ -4776,10 +4802,13 @@
4776
4802
  instantSearchInstance.sendEventToInsights(args[0]);
4777
4803
  return;
4778
4804
  }
4779
- var eventType = args[0],
4780
- isRefined = args[1],
4805
+ var isRefined = args[1],
4781
4806
  _args$ = args[2],
4782
4807
  eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
4808
+ var _args$0$split = args[0].split(':'),
4809
+ _args$0$split2 = _slicedToArray(_args$0$split, 2),
4810
+ eventType = _args$0$split2[0],
4811
+ eventModifier = _args$0$split2[1];
4783
4812
  if (eventType !== 'click' || on === undefined) {
4784
4813
  return;
4785
4814
  }
@@ -4791,6 +4820,7 @@
4791
4820
  insightsMethod: 'clickedFilters',
4792
4821
  widgetType: $$type$3,
4793
4822
  eventType: eventType,
4823
+ eventModifier: eventModifier,
4794
4824
  payload: {
4795
4825
  eventName: eventName,
4796
4826
  index: helper.getIndex(),
@@ -4837,7 +4867,7 @@
4837
4867
  },
4838
4868
  isRefined = _ref3.isRefined;
4839
4869
  if (!isRefined) {
4840
- sendEvent('click', isRefined);
4870
+ sendEvent('click:internal', isRefined);
4841
4871
  if (hasAnOffValue) {
4842
4872
  off.forEach(function (v) {
4843
4873
  return helper.removeDisjunctiveFacetRefinement(attribute, v);
@@ -5298,7 +5328,7 @@
5298
5328
  widgetState.internalToggleRefineOnMapMove = createInternalToggleRefinementOnMapMove(renderArgs, this.render.bind(this));
5299
5329
  widgetState.internalSetMapMoveSinceLastRefine = createInternalSetMapMoveSinceLastRefine(renderArgs, this.render.bind(this));
5300
5330
  var widgetRenderState = this.getWidgetRenderState(renderArgs);
5301
- sendEvent('view', widgetRenderState.items);
5331
+ sendEvent('view:internal', widgetRenderState.items);
5302
5332
  renderFn(_objectSpread2(_objectSpread2({}, widgetRenderState), {}, {
5303
5333
  instantSearchInstance: instantSearchInstance
5304
5334
  }), isFirstRendering);
@@ -11109,7 +11139,7 @@
11109
11139
  renderState.indices.forEach(function (_ref3) {
11110
11140
  var sendEvent = _ref3.sendEvent,
11111
11141
  hits = _ref3.hits;
11112
- sendEvent('view', hits);
11142
+ sendEvent('view:internal', hits);
11113
11143
  });
11114
11144
  renderFn(_objectSpread2(_objectSpread2({}, renderState), {}, {
11115
11145
  instantSearchInstance: instantSearchInstance
@@ -11899,7 +11929,231 @@
11899
11929
  };
11900
11930
  }
11901
11931
 
11902
- function extractPayload(widgets, instantSearchInstance, payload) {
11932
+ var ALGOLIA_INSIGHTS_VERSION = '2.6.0';
11933
+ var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@".concat(ALGOLIA_INSIGHTS_VERSION, "/dist/search-insights.min.js");
11934
+ function createInsightsMiddleware() {
11935
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11936
+ var _insightsClient = props.insightsClient,
11937
+ insightsInitParams = props.insightsInitParams,
11938
+ onEvent = props.onEvent,
11939
+ _props$$$internal = props.$$internal,
11940
+ $$internal = _props$$$internal === void 0 ? false : _props$$$internal;
11941
+ var potentialInsightsClient = _insightsClient;
11942
+ if (!_insightsClient && _insightsClient !== null) {
11943
+ safelyRunOnBrowser(function (_ref) {
11944
+ var window = _ref.window;
11945
+ var pointer = window.AlgoliaAnalyticsObject || 'aa';
11946
+ if (typeof pointer === 'string') {
11947
+ potentialInsightsClient = window[pointer];
11948
+ }
11949
+ if (!potentialInsightsClient) {
11950
+ window.AlgoliaAnalyticsObject = pointer;
11951
+ if (!window[pointer]) {
11952
+ window[pointer] = function () {
11953
+ if (!window[pointer].queue) {
11954
+ window[pointer].queue = [];
11955
+ }
11956
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
11957
+ args[_key] = arguments[_key];
11958
+ }
11959
+ window[pointer].queue.push(args);
11960
+ };
11961
+ window[pointer].version = ALGOLIA_INSIGHTS_VERSION;
11962
+ window[pointer].shouldAddScript = true;
11963
+ }
11964
+ potentialInsightsClient = window[pointer];
11965
+ }
11966
+ });
11967
+ }
11968
+ // if still no insightsClient was found, we use a noop
11969
+ var insightsClient = potentialInsightsClient || noop;
11970
+ return function (_ref2) {
11971
+ var instantSearchInstance = _ref2.instantSearchInstance;
11972
+ // remove existing default insights middleware
11973
+ // user-provided insights middleware takes precedence
11974
+ var existingInsightsMiddlewares = instantSearchInstance.middleware.filter(function (m) {
11975
+ return m.instance.$$type === 'ais.insights' && m.instance.$$internal;
11976
+ }).map(function (m) {
11977
+ return m.creator;
11978
+ });
11979
+ instantSearchInstance.unuse.apply(instantSearchInstance, _toConsumableArray(existingInsightsMiddlewares));
11980
+ var _getAppIdAndApiKey = getAppIdAndApiKey(instantSearchInstance.client),
11981
+ _getAppIdAndApiKey2 = _slicedToArray(_getAppIdAndApiKey, 2),
11982
+ appId = _getAppIdAndApiKey2[0],
11983
+ apiKey = _getAppIdAndApiKey2[1];
11984
+
11985
+ // search-insights.js also throws an error so dev-only clarification is sufficient
11986
+ _warning(Boolean(appId && apiKey), 'could not extract Algolia credentials from searchClient in insights middleware.') ;
11987
+ var queuedUserToken = undefined;
11988
+ var userTokenBeforeInit = undefined;
11989
+ if (Array.isArray(insightsClient.queue)) {
11990
+ // Context: The umd build of search-insights is asynchronously loaded by the snippet.
11991
+ //
11992
+ // When user calls `aa('setUserToken', 'my-user-token')` before `search-insights` is loaded,
11993
+ // ['setUserToken', 'my-user-token'] gets stored in `aa.queue`.
11994
+ // Whenever `search-insights` is finally loaded, it will process the queue.
11995
+ //
11996
+ // But here's the reason why we handle it here:
11997
+ // At this point, even though `search-insights` is not loaded yet,
11998
+ // we still want to read the token from the queue.
11999
+ // Otherwise, the first search call will be fired without the token.
12000
+ var _ref3 = find(insightsClient.queue.slice().reverse(), function (_ref5) {
12001
+ var _ref6 = _slicedToArray(_ref5, 1),
12002
+ method = _ref6[0];
12003
+ return method === 'setUserToken';
12004
+ }) || [];
12005
+ var _ref4 = _slicedToArray(_ref3, 2);
12006
+ queuedUserToken = _ref4[1];
12007
+ }
12008
+ insightsClient('getUserToken', null, function (_error, userToken) {
12009
+ // If user has called `aa('setUserToken', 'my-user-token')` before creating
12010
+ // the `insights` middleware, we store them temporarily and
12011
+ // set it later on.
12012
+ //
12013
+ // Otherwise, the `init` call might override it with anonymous user token.
12014
+ userTokenBeforeInit = userToken;
12015
+ });
12016
+
12017
+ // Only `init` if the `insightsInitParams` option is passed or
12018
+ // if the `insightsClient` version doesn't supports optional `init` calling.
12019
+ if (insightsInitParams || !isModernInsightsClient(insightsClient)) {
12020
+ insightsClient('init', _objectSpread2({
12021
+ appId: appId,
12022
+ apiKey: apiKey,
12023
+ partial: true
12024
+ }, insightsInitParams));
12025
+ }
12026
+ var initialParameters;
12027
+ var helper;
12028
+ return {
12029
+ $$type: 'ais.insights',
12030
+ $$internal: $$internal,
12031
+ onStateChange: function onStateChange() {},
12032
+ subscribe: function subscribe() {
12033
+ if (!insightsClient.shouldAddScript) return;
12034
+ var errorMessage = '[insights middleware]: could not load search-insights.js. Please load it manually following https://alg.li/insights-init';
12035
+ try {
12036
+ var script = document.createElement('script');
12037
+ script.async = true;
12038
+ script.src = ALGOLIA_INSIGHTS_SRC;
12039
+ script.onerror = function () {
12040
+ instantSearchInstance.emit('error', new Error(errorMessage));
12041
+ };
12042
+ document.body.appendChild(script);
12043
+ insightsClient.shouldAddScript = false;
12044
+ } catch (cause) {
12045
+ insightsClient.shouldAddScript = false;
12046
+ instantSearchInstance.emit('error', new Error(errorMessage));
12047
+ }
12048
+ },
12049
+ started: function started() {
12050
+ insightsClient('addAlgoliaAgent', 'insights-middleware');
12051
+ helper = instantSearchInstance.helper;
12052
+ initialParameters = {
12053
+ userToken: helper.state.userToken,
12054
+ clickAnalytics: helper.state.clickAnalytics
12055
+ };
12056
+ helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), {}, {
12057
+ clickAnalytics: true
12058
+ }));
12059
+ if (!$$internal) {
12060
+ instantSearchInstance.scheduleSearch();
12061
+ }
12062
+ var setUserTokenToSearch = function setUserTokenToSearch(userToken) {
12063
+ if (!userToken) {
12064
+ return;
12065
+ }
12066
+ var existingToken = helper.state.userToken;
12067
+ helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), {}, {
12068
+ userToken: userToken
12069
+ }));
12070
+ if (existingToken && existingToken !== userToken) {
12071
+ instantSearchInstance.scheduleSearch();
12072
+ }
12073
+ };
12074
+ var anonymousUserToken = getInsightsAnonymousUserTokenInternal();
12075
+ if (anonymousUserToken) {
12076
+ // When `aa('init', { ... })` is called, it creates an anonymous user token in cookie.
12077
+ // We can set it as userToken.
12078
+ setUserTokenToSearch(anonymousUserToken);
12079
+ }
12080
+
12081
+ // We consider the `userToken` coming from a `init` call to have a higher
12082
+ // importance than the one coming from the queue.
12083
+ if (userTokenBeforeInit) {
12084
+ setUserTokenToSearch(userTokenBeforeInit);
12085
+ insightsClient('setUserToken', userTokenBeforeInit);
12086
+ } else if (queuedUserToken) {
12087
+ setUserTokenToSearch(queuedUserToken);
12088
+ insightsClient('setUserToken', queuedUserToken);
12089
+ }
12090
+
12091
+ // This updates userToken which is set explicitly by `aa('setUserToken', userToken)`
12092
+ insightsClient('onUserTokenChange', setUserTokenToSearch, {
12093
+ immediate: true
12094
+ });
12095
+ var insightsClientWithLocalCredentials = insightsClient;
12096
+ if (isModernInsightsClient(insightsClient)) {
12097
+ insightsClientWithLocalCredentials = function insightsClientWithLocalCredentials(method, payload) {
12098
+ var extraParams = {
12099
+ headers: {
12100
+ 'X-Algolia-Application-Id': appId,
12101
+ 'X-Algolia-API-Key': apiKey
12102
+ }
12103
+ };
12104
+
12105
+ // @ts-ignore we are calling this only when we know that the client actually is correct
12106
+ return insightsClient(method, payload, extraParams);
12107
+ };
12108
+ }
12109
+ instantSearchInstance.sendEventToInsights = function (event) {
12110
+ if (onEvent) {
12111
+ onEvent(event, insightsClientWithLocalCredentials);
12112
+ } else if (event.insightsMethod) {
12113
+ // Source is used to differentiate events sent by instantsearch from those sent manually.
12114
+ event.payload.algoliaSource = ['instantsearch'];
12115
+ if (event.eventModifier === 'internal') {
12116
+ event.payload.algoliaSource.push('instantsearch-internal');
12117
+ }
12118
+ insightsClientWithLocalCredentials(event.insightsMethod, event.payload);
12119
+ _warning(Boolean(helper.state.userToken), "\nCannot send event to Algolia Insights because `userToken` is not set.\n\nSee documentation: https://www.algolia.com/doc/guides/building-search-ui/going-further/send-insights-events/js/#setting-the-usertoken\n") ;
12120
+ } else {
12121
+ _warning(false, 'Cannot send event to Algolia Insights because `insightsMethod` option is missing.') ;
12122
+ }
12123
+ };
12124
+ },
12125
+ unsubscribe: function unsubscribe() {
12126
+ insightsClient('onUserTokenChange', undefined);
12127
+ instantSearchInstance.sendEventToInsights = noop;
12128
+ if (helper && initialParameters) {
12129
+ helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), initialParameters));
12130
+ instantSearchInstance.scheduleSearch();
12131
+ }
12132
+ }
12133
+ };
12134
+ };
12135
+ }
12136
+
12137
+ /**
12138
+ * Determines if a given insights `client` supports the optional call to `init`
12139
+ * and the ability to set credentials via extra parameters when sending events.
12140
+ */
12141
+ function isModernInsightsClient(client) {
12142
+ var _split$map = (client.version || '').split('.').map(Number),
12143
+ _split$map2 = _slicedToArray(_split$map, 2),
12144
+ major = _split$map2[0],
12145
+ minor = _split$map2[1];
12146
+
12147
+ /* eslint-disable @typescript-eslint/naming-convention */
12148
+ var v3 = major >= 3;
12149
+ var v2_6 = major === 2 && minor >= 6;
12150
+ var v1_10 = major === 1 && minor >= 10;
12151
+ /* eslint-enable @typescript-eslint/naming-convention */
12152
+
12153
+ return v3 || v2_6 || v1_10;
12154
+ }
12155
+
12156
+ function extractWidgetPayload(widgets, instantSearchInstance, payload) {
11903
12157
  var initOptions = createInitArgs(instantSearchInstance, instantSearchInstance.mainIndex, instantSearchInstance._initialUiState);
11904
12158
  widgets.forEach(function (widget) {
11905
12159
  var widgetParams = {};
@@ -11921,7 +12175,7 @@
11921
12175
  params: params
11922
12176
  });
11923
12177
  if (widget.$$type === 'ais.index') {
11924
- extractPayload(widget.getWidgets(), instantSearchInstance, payload);
12178
+ extractWidgetPayload(widget.getWidgets(), instantSearchInstance, payload);
11925
12179
  }
11926
12180
  });
11927
12181
  }
@@ -11945,8 +12199,11 @@
11945
12199
  * - connector name
11946
12200
  */
11947
12201
  function createMetadataMiddleware() {
11948
- return function (_ref2) {
11949
- var instantSearchInstance = _ref2.instantSearchInstance;
12202
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
12203
+ _ref2$$$internal = _ref2.$$internal,
12204
+ $$internal = _ref2$$$internal === void 0 ? false : _ref2$$$internal;
12205
+ return function (_ref3) {
12206
+ var instantSearchInstance = _ref3.instantSearchInstance;
11950
12207
  var payload = {
11951
12208
  widgets: []
11952
12209
  };
@@ -11954,13 +12211,22 @@
11954
12211
  var refNode = document.querySelector('head');
11955
12212
  payloadContainer.name = 'instantsearch:widgets';
11956
12213
  return {
12214
+ $$type: 'ais.metadata',
12215
+ $$internal: $$internal,
11957
12216
  onStateChange: function onStateChange() {},
11958
12217
  subscribe: function subscribe() {
11959
12218
  // using setTimeout here to delay extraction until widgets have been added in a tick (e.g. Vue)
11960
12219
  setTimeout(function () {
11961
12220
  var client = instantSearchInstance.client;
11962
12221
  payload.ua = client.transporter && client.transporter.userAgent ? client.transporter.userAgent.value : client._ua;
11963
- extractPayload(instantSearchInstance.mainIndex.getWidgets(), instantSearchInstance, payload);
12222
+ extractWidgetPayload(instantSearchInstance.mainIndex.getWidgets(), instantSearchInstance, payload);
12223
+ instantSearchInstance.middleware.forEach(function (middleware) {
12224
+ return payload.widgets.push({
12225
+ middleware: true,
12226
+ type: middleware.instance.$$type,
12227
+ internal: middleware.instance.$$internal
12228
+ });
12229
+ });
11964
12230
  payloadContainer.content = JSON.stringify(payload);
11965
12231
  refNode.appendChild(payloadContainer);
11966
12232
  }, 0);
@@ -12812,6 +13078,7 @@
12812
13078
  dispose = _ref.dispose,
12813
13079
  push = _ref.push;
12814
13080
  _classCallCheck(this, BrowserHistory);
13081
+ _defineProperty(this, "$$type", 'ais.browser');
12815
13082
  _defineProperty(this, "windowTitle", void 0);
12816
13083
  _defineProperty(this, "writeDelay", void 0);
12817
13084
  _defineProperty(this, "_createURL", void 0);
@@ -13064,6 +13331,7 @@
13064
13331
  // which excludes "configure" as this function does.
13065
13332
  function simpleStateMapping() {
13066
13333
  return {
13334
+ $$type: 'ais.simple',
13067
13335
  stateToRoute: function stateToRoute(uiState) {
13068
13336
  return Object.keys(uiState).reduce(function (state, indexId) {
13069
13337
  return _objectSpread2(_objectSpread2({}, state), {}, _defineProperty({}, indexId, getIndexStateWithoutConfigure(uiState[indexId])));
@@ -13083,7 +13351,9 @@
13083
13351
  var _props$router = props.router,
13084
13352
  router = _props$router === void 0 ? historyRouter() : _props$router,
13085
13353
  _props$stateMapping = props.stateMapping,
13086
- stateMapping = _props$stateMapping === void 0 ? simpleStateMapping() : _props$stateMapping;
13354
+ stateMapping = _props$stateMapping === void 0 ? simpleStateMapping() : _props$stateMapping,
13355
+ _props$$$internal = props.$$internal,
13356
+ $$internal = _props$$$internal === void 0 ? false : _props$$$internal;
13087
13357
  return function (_ref) {
13088
13358
  var instantSearchInstance = _ref.instantSearchInstance;
13089
13359
  function topLevelCreateURL(nextState) {
@@ -13100,6 +13370,8 @@
13100
13370
  var lastRouteState = undefined;
13101
13371
  var initialUiState = instantSearchInstance._initialUiState;
13102
13372
  return {
13373
+ $$type: "ais.router({router:".concat(router.$$type || '__unknown__', ", stateMapping:").concat(stateMapping.$$type || '__unknown__', "})"),
13374
+ $$internal: $$internal,
13103
13375
  onStateChange: function onStateChange(_ref2) {
13104
13376
  var uiState = _ref2.uiState;
13105
13377
  var routeState = stateMapping.stateToRoute(uiState);
@@ -13660,7 +13932,7 @@
13660
13932
  };
13661
13933
  }
13662
13934
 
13663
- var version$1 = '4.54.1';
13935
+ var version$1 = '4.55.0';
13664
13936
 
13665
13937
  var withUsage$r = createDocumentationMessageGenerator({
13666
13938
  name: 'instantsearch'
@@ -13745,6 +14017,8 @@
13745
14017
  initialUiState = _options$initialUiSta === void 0 ? {} : _options$initialUiSta,
13746
14018
  _options$routing = options.routing,
13747
14019
  routing = _options$routing === void 0 ? null : _options$routing,
14020
+ _options$insights = options.insights,
14021
+ insights = _options$insights === void 0 ? false : _options$insights,
13748
14022
  searchFunction = options.searchFunction,
13749
14023
  _options$stalledSearc = options.stalledSearchDelay,
13750
14024
  stalledSearchDelay = _options$stalledSearc === void 0 ? 200 : _options$stalledSearc,
@@ -13800,11 +14074,22 @@
13800
14074
  }
13801
14075
  _this.sendEventToInsights = noop;
13802
14076
  if (routing) {
13803
- var routerOptions = typeof routing === 'boolean' ? undefined : routing;
14077
+ var routerOptions = typeof routing === 'boolean' ? {} : routing;
14078
+ routerOptions.$$internal = true;
13804
14079
  _this.use(createRouterMiddleware(routerOptions));
13805
14080
  }
14081
+
14082
+ // This is the default middleware,
14083
+ // any user-provided middleware will be added later and override this one.
14084
+ if (insights) {
14085
+ var insightsOptions = typeof insights === 'boolean' ? {} : insights;
14086
+ insightsOptions.$$internal = true;
14087
+ _this.use(createInsightsMiddleware(insightsOptions));
14088
+ }
13806
14089
  if (isMetadataEnabled()) {
13807
- _this.use(createMetadataMiddleware());
14090
+ _this.use(createMetadataMiddleware({
14091
+ $$internal: true
14092
+ }));
13808
14093
  }
13809
14094
  return _this;
13810
14095
  }
@@ -13840,6 +14125,8 @@
13840
14125
  }
13841
14126
  var newMiddlewareList = middleware.map(function (fn) {
13842
14127
  var newMiddleware = _objectSpread2({
14128
+ $$type: '__unknown__',
14129
+ $$internal: false,
13843
14130
  subscribe: noop,
13844
14131
  started: noop,
13845
14132
  unsubscribe: noop,
@@ -14217,6 +14504,7 @@
14217
14504
  }
14218
14505
  function singleIndexStateMapping(indexName) {
14219
14506
  return {
14507
+ $$type: 'ais.singleIndex',
14220
14508
  stateToRoute: function stateToRoute(uiState) {
14221
14509
  return getIndexStateWithoutConfigure$1(uiState[indexName] || {});
14222
14510
  },
@@ -14235,130 +14523,6 @@
14235
14523
  singleIndex: singleIndexStateMapping
14236
14524
  });
14237
14525
 
14238
- function createInsightsMiddleware(props) {
14239
- var _ref = props || {},
14240
- _insightsClient = _ref.insightsClient,
14241
- insightsInitParams = _ref.insightsInitParams,
14242
- onEvent = _ref.onEvent;
14243
- if (_insightsClient !== null && !_insightsClient) {
14244
- {
14245
- throw new Error("The `insightsClient` option is required if you want userToken to be automatically set in search calls. If you don't want this behaviour, set it to `null`.");
14246
- }
14247
- }
14248
- var hasInsightsClient = Boolean(_insightsClient);
14249
- var insightsClient = _insightsClient === null ? noop : _insightsClient;
14250
- return function (_ref2) {
14251
- var instantSearchInstance = _ref2.instantSearchInstance;
14252
- var _getAppIdAndApiKey = getAppIdAndApiKey(instantSearchInstance.client),
14253
- _getAppIdAndApiKey2 = _slicedToArray(_getAppIdAndApiKey, 2),
14254
- appId = _getAppIdAndApiKey2[0],
14255
- apiKey = _getAppIdAndApiKey2[1];
14256
-
14257
- // search-insights.js also throws an error so dev-only clarification is sufficient
14258
- if ( !(appId && apiKey)) {
14259
- throw new Error('[insights middleware]: could not extract Algolia credentials from searchClient');
14260
- }
14261
- var queuedUserToken = undefined;
14262
- var userTokenBeforeInit = undefined;
14263
- if (Array.isArray(insightsClient.queue)) {
14264
- // Context: The umd build of search-insights is asynchronously loaded by the snippet.
14265
- //
14266
- // When user calls `aa('setUserToken', 'my-user-token')` before `search-insights` is loaded,
14267
- // ['setUserToken', 'my-user-token'] gets stored in `aa.queue`.
14268
- // Whenever `search-insights` is finally loaded, it will process the queue.
14269
- //
14270
- // But here's the reason why we handle it here:
14271
- // At this point, even though `search-insights` is not loaded yet,
14272
- // we still want to read the token from the queue.
14273
- // Otherwise, the first search call will be fired without the token.
14274
- var _ref3 = find(insightsClient.queue.slice().reverse(), function (_ref5) {
14275
- var _ref6 = _slicedToArray(_ref5, 1),
14276
- method = _ref6[0];
14277
- return method === 'setUserToken';
14278
- }) || [];
14279
- var _ref4 = _slicedToArray(_ref3, 2);
14280
- queuedUserToken = _ref4[1];
14281
- }
14282
- insightsClient('getUserToken', null, function (_error, userToken) {
14283
- // If user has called `aa('setUserToken', 'my-user-token')` before creating
14284
- // the `insights` middleware, we store them temporarily and
14285
- // set it later on.
14286
- //
14287
- // Otherwise, the `init` call might override it with anonymous user token.
14288
- userTokenBeforeInit = userToken;
14289
- });
14290
- insightsClient('init', _objectSpread2({
14291
- appId: appId,
14292
- apiKey: apiKey
14293
- }, insightsInitParams));
14294
- var initialParameters;
14295
- var helper;
14296
- return {
14297
- onStateChange: function onStateChange() {},
14298
- subscribe: function subscribe() {},
14299
- started: function started() {
14300
- insightsClient('addAlgoliaAgent', 'insights-middleware');
14301
- helper = instantSearchInstance.helper;
14302
- initialParameters = {
14303
- userToken: helper.state.userToken,
14304
- clickAnalytics: helper.state.clickAnalytics
14305
- };
14306
- helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), {}, {
14307
- clickAnalytics: true
14308
- }));
14309
- instantSearchInstance.scheduleSearch();
14310
- var setUserTokenToSearch = function setUserTokenToSearch(userToken) {
14311
- helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), {}, {
14312
- userToken: userToken
14313
- }));
14314
- instantSearchInstance.scheduleSearch();
14315
- };
14316
- var anonymousUserToken = getInsightsAnonymousUserTokenInternal();
14317
- if (hasInsightsClient && anonymousUserToken) {
14318
- // When `aa('init', { ... })` is called, it creates an anonymous user token in cookie.
14319
- // We can set it as userToken.
14320
- setUserTokenToSearch(anonymousUserToken);
14321
- }
14322
-
14323
- // We consider the `userToken` coming from a `init` call to have a higher
14324
- // importance than the one coming from the queue.
14325
- if (userTokenBeforeInit) {
14326
- insightsClient('setUserToken', userTokenBeforeInit);
14327
- } else if (queuedUserToken) {
14328
- insightsClient('setUserToken', queuedUserToken);
14329
- }
14330
-
14331
- // This updates userToken which is set explicitly by `aa('setUserToken', userToken)`
14332
- insightsClient('onUserTokenChange', setUserTokenToSearch, {
14333
- immediate: true
14334
- });
14335
- instantSearchInstance.sendEventToInsights = function (event) {
14336
- if (onEvent) {
14337
- onEvent(event, _insightsClient);
14338
- } else if (event.insightsMethod) {
14339
- var hasUserToken = Boolean(helper.state.userToken);
14340
- if (hasUserToken) {
14341
- insightsClient(event.insightsMethod, event.payload);
14342
- } else {
14343
- _warning(false, "\nCannot send event to Algolia Insights because `userToken` is not set.\n\nSee documentation: https://www.algolia.com/doc/guides/building-search-ui/going-further/send-insights-events/js/#setting-the-usertoken\n") ;
14344
- }
14345
- } else {
14346
- _warning(false, 'Cannot send event to Algolia Insights because `insightsMethod` option is missing.') ;
14347
- }
14348
- };
14349
- },
14350
- unsubscribe: function unsubscribe() {
14351
- insightsClient('onUserTokenChange', undefined);
14352
- instantSearchInstance.sendEventToInsights = noop;
14353
- if (helper && initialParameters) {
14354
- helper.setState(_objectSpread2(_objectSpread2({}, helper.state), initialParameters));
14355
- instantSearchInstance.scheduleSearch();
14356
- }
14357
- }
14358
- };
14359
- };
14360
- }
14361
-
14362
14526
 
14363
14527
 
14364
14528
  var middlewares = /*#__PURE__*/Object.freeze({
@@ -15375,7 +15539,7 @@
15375
15539
  }
15376
15540
 
15377
15541
  var _excluded$d = ["hit", "attribute", "cssClasses"],
15378
- _excluded2$1 = ["isHighlighted"];
15542
+ _excluded2$2 = ["isHighlighted"];
15379
15543
  function ReverseHighlight$1(_ref) {
15380
15544
  var hit = _ref.hit,
15381
15545
  attribute = _ref.attribute,
@@ -15388,7 +15552,7 @@
15388
15552
  var value = _ref2.value;
15389
15553
  return getHighlightedParts(unescape$1(value || '')).map(function (_ref3) {
15390
15554
  var isHighlighted = _ref3.isHighlighted,
15391
- rest = _objectWithoutProperties(_ref3, _excluded2$1);
15555
+ rest = _objectWithoutProperties(_ref3, _excluded2$2);
15392
15556
  return _objectSpread2(_objectSpread2({}, rest), {}, {
15393
15557
  isHighlighted: !isHighlighted
15394
15558
  });
@@ -15416,7 +15580,7 @@
15416
15580
  }
15417
15581
 
15418
15582
  var _excluded$f = ["hit", "attribute", "cssClasses"],
15419
- _excluded2$2 = ["isHighlighted"];
15583
+ _excluded2$3 = ["isHighlighted"];
15420
15584
  function ReverseSnippet$1(_ref) {
15421
15585
  var hit = _ref.hit,
15422
15586
  attribute = _ref.attribute,
@@ -15429,7 +15593,7 @@
15429
15593
  var value = _ref2.value;
15430
15594
  return getHighlightedParts(unescape$1(value || '')).map(function (_ref3) {
15431
15595
  var isHighlighted = _ref3.isHighlighted,
15432
- rest = _objectWithoutProperties(_ref3, _excluded2$2);
15596
+ rest = _objectWithoutProperties(_ref3, _excluded2$3);
15433
15597
  return _objectSpread2(_objectSpread2({}, rest), {}, {
15434
15598
  isHighlighted: !isHighlighted
15435
15599
  });
@@ -16719,7 +16883,7 @@
16719
16883
  };
16720
16884
 
16721
16885
  var _excluded$j = ["initialZoom", "initialPosition", "templates", "cssClasses", "builtInMarker", "customHTMLMarker", "enableRefine", "enableClearMapRefinement", "enableRefineControl", "container", "googleReference"],
16722
- _excluded2$3 = ["item"],
16886
+ _excluded2$4 = ["item"],
16723
16887
  _excluded3 = ["item"];
16724
16888
  var withUsage$y = createDocumentationMessageGenerator({
16725
16889
  name: 'geo-search'
@@ -16821,7 +16985,7 @@
16821
16985
  var customHTMLMarker = isCustomHTMLMarker && _objectSpread2(_objectSpread2({}, defaultCustomHTMLMarker), userCustomHTMLMarker);
16822
16986
  var createBuiltInMarker = function createBuiltInMarker(_ref2) {
16823
16987
  var item = _ref2.item,
16824
- rest = _objectWithoutProperties(_ref2, _excluded2$3);
16988
+ rest = _objectWithoutProperties(_ref2, _excluded2$4);
16825
16989
  return new googleReference.maps.Marker(_objectSpread2(_objectSpread2(_objectSpread2({}, builtInMarker.createOptions(item)), rest), {}, {
16826
16990
  // @ts-expect-error @types/googlemaps doesn't document this
16827
16991
  __id: item.objectID,
@@ -17494,18 +17658,24 @@
17494
17658
  });
17495
17659
  };
17496
17660
 
17497
- var Hits = function Hits(_ref) {
17661
+ function Hits(_ref) {
17498
17662
  var results = _ref.results,
17499
17663
  hits = _ref.hits,
17664
+ insights = _ref.insights,
17500
17665
  bindEvent = _ref.bindEvent,
17501
17666
  sendEvent = _ref.sendEvent,
17502
17667
  cssClasses = _ref.cssClasses,
17503
17668
  templateProps = _ref.templateProps;
17669
+ var handleInsightsClick = createInsightsEventHandler({
17670
+ insights: insights,
17671
+ sendEvent: sendEvent
17672
+ });
17504
17673
  if (results.hits.length === 0) {
17505
17674
  return h(Template, _extends({}, templateProps, {
17506
17675
  templateKey: "empty",
17507
17676
  rootProps: {
17508
- className: cx(cssClasses.root, cssClasses.emptyRoot)
17677
+ className: cx(cssClasses.root, cssClasses.emptyRoot),
17678
+ onClick: handleInsightsClick
17509
17679
  },
17510
17680
  data: results
17511
17681
  }));
@@ -17519,7 +17689,11 @@
17519
17689
  templateKey: "item",
17520
17690
  rootTagName: "li",
17521
17691
  rootProps: {
17522
- className: cssClasses.item
17692
+ className: cssClasses.item,
17693
+ onClick: function onClick(event) {
17694
+ handleInsightsClick(event);
17695
+ sendEvent('click:internal', hit, 'Hit Clicked');
17696
+ }
17523
17697
  },
17524
17698
  key: hit.objectID,
17525
17699
  data: _objectSpread2(_objectSpread2({}, hit), {}, {
@@ -17532,7 +17706,7 @@
17532
17706
  sendEvent: sendEvent
17533
17707
  }));
17534
17708
  })));
17535
- };
17709
+ }
17536
17710
 
17537
17711
  var defaultTemplates$5 = {
17538
17712
  empty: function empty() {
@@ -17547,7 +17721,6 @@
17547
17721
  name: 'hits'
17548
17722
  });
17549
17723
  var suit$b = component('Hits');
17550
- var HitsWithInsightsListener = insightsListener(Hits);
17551
17724
  var renderer$6 = function renderer(_ref) {
17552
17725
  var renderState = _ref.renderState,
17553
17726
  cssClasses = _ref.cssClasses,
@@ -17568,7 +17741,7 @@
17568
17741
  });
17569
17742
  return;
17570
17743
  }
17571
- P(h(HitsWithInsightsListener, {
17744
+ P(h(Hits, {
17572
17745
  cssClasses: cssClasses,
17573
17746
  hits: receivedHits,
17574
17747
  results: results,
@@ -17705,6 +17878,7 @@
17705
17878
  var InfiniteHits = function InfiniteHits(_ref) {
17706
17879
  var results = _ref.results,
17707
17880
  hits = _ref.hits,
17881
+ insights = _ref.insights,
17708
17882
  bindEvent = _ref.bindEvent,
17709
17883
  sendEvent = _ref.sendEvent,
17710
17884
  hasShowPrevious = _ref.hasShowPrevious,
@@ -17714,11 +17888,16 @@
17714
17888
  isLastPage = _ref.isLastPage,
17715
17889
  cssClasses = _ref.cssClasses,
17716
17890
  templateProps = _ref.templateProps;
17891
+ var handleInsightsClick = createInsightsEventHandler({
17892
+ insights: insights,
17893
+ sendEvent: sendEvent
17894
+ });
17717
17895
  if (results.hits.length === 0) {
17718
17896
  return h(Template, _extends({}, templateProps, {
17719
17897
  templateKey: "empty",
17720
17898
  rootProps: {
17721
- className: cx(cssClasses.root, cssClasses.emptyRoot)
17899
+ className: cx(cssClasses.root, cssClasses.emptyRoot),
17900
+ onClick: handleInsightsClick
17722
17901
  },
17723
17902
  data: results
17724
17903
  }));
@@ -17740,7 +17919,11 @@
17740
17919
  templateKey: "item",
17741
17920
  rootTagName: "li",
17742
17921
  rootProps: {
17743
- className: cssClasses.item
17922
+ className: cssClasses.item,
17923
+ onClick: function onClick(event) {
17924
+ handleInsightsClick(event);
17925
+ sendEvent('click:internal', hit, 'Hit Clicked');
17926
+ }
17744
17927
  },
17745
17928
  key: hit.objectID,
17746
17929
  data: _objectSpread2(_objectSpread2({}, hit), {}, {
@@ -17782,7 +17965,6 @@
17782
17965
  name: 'infinite-hits'
17783
17966
  });
17784
17967
  var suit$d = component('InfiniteHits');
17785
- var InfiniteHitsWithInsightsListener = insightsListener(InfiniteHits);
17786
17968
  var renderer$8 = function renderer(_ref) {
17787
17969
  var containerNode = _ref.containerNode,
17788
17970
  cssClasses = _ref.cssClasses,
@@ -17808,7 +17990,7 @@
17808
17990
  });
17809
17991
  return;
17810
17992
  }
17811
- P(h(InfiniteHitsWithInsightsListener, {
17993
+ P(h(InfiniteHits, {
17812
17994
  cssClasses: cssClasses,
17813
17995
  hits: hits,
17814
17996
  results: results,
@@ -18741,7 +18923,7 @@
18741
18923
  };
18742
18924
 
18743
18925
  var _excluded$l = ["placesReference", "defaultPosition"],
18744
- _excluded2$4 = ["places"];
18926
+ _excluded2$5 = ["places"];
18745
18927
  /* Places.js is an optional dependency, no error should be reported if the package is missing */
18746
18928
  /** @ts-ignore */
18747
18929
 
@@ -18797,7 +18979,7 @@
18797
18979
  var hasPositionSet = position !== defaultPosition.join(',');
18798
18980
  if (!hasPositionSet && !state.query) {
18799
18981
  var places = uiState.places,
18800
- uiStateWithoutPlaces = _objectWithoutProperties(uiState, _excluded2$4);
18982
+ uiStateWithoutPlaces = _objectWithoutProperties(uiState, _excluded2$5);
18801
18983
  return uiStateWithoutPlaces;
18802
18984
  }
18803
18985
  return _objectSpread2(_objectSpread2({}, uiState), {}, {