@getlupa/vue 0.7.3 → 0.7.5

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.
@@ -1928,21 +1928,21 @@ const sendUaAnalyticsEvent = (data, options) => {
1928
1928
  );
1929
1929
  };
1930
1930
  const sendGa4AnalyticsEvent = (data, options) => {
1931
- var _a, _b, _c, _d, _e;
1931
+ var _a, _b, _c, _d, _e, _f, _g;
1932
1932
  if (!window || !window.dataLayer) {
1933
1933
  console.error("dataLayer object not found.");
1934
1934
  return;
1935
1935
  }
1936
1936
  const sendItemTitle = data.searchQuery !== ((_a = data.analytics) == null ? void 0 : _a.label);
1937
1937
  const title = sendItemTitle ? (_b = data.analytics) == null ? void 0 : _b.label : void 0;
1938
- const params = {
1938
+ const params = __spreadValues({
1939
1939
  search_text: data.searchQuery,
1940
1940
  item_title: title,
1941
1941
  item_id: data.itemId,
1942
1942
  ecommerce: parseEcommerceData(data, (_c = data.analytics) == null ? void 0 : _c.listLabel)
1943
- };
1943
+ }, (_e = (_d = data.analytics) == null ? void 0 : _d.additionalParams) != null ? _e : {});
1944
1944
  window.dataLayer.push(__spreadValues({
1945
- event: (_e = (_d = data.analytics) == null ? void 0 : _d.type) != null ? _e : options.parentEventName
1945
+ event: (_g = (_f = data.analytics) == null ? void 0 : _f.type) != null ? _g : options.parentEventName
1946
1946
  }, params));
1947
1947
  };
1948
1948
  const processDebugEvent = (data) => {
@@ -2785,6 +2785,10 @@ const useParamsStore = defineStore("params", () => {
2785
2785
  const searchString = vue.ref("");
2786
2786
  const optionsStore = useOptionsStore();
2787
2787
  const redirectionStore = useRedirectionStore();
2788
+ const sortParams = vue.ref({
2789
+ selectedSortKey: "",
2790
+ previousSortKey: ""
2791
+ });
2788
2792
  const query = vue.computed(() => params.value[QUERY_PARAMS_PARSED.QUERY]);
2789
2793
  const page = vue.computed(() => {
2790
2794
  const page2 = Number(params.value[QUERY_PARAMS_PARSED.PAGE]) || 1;
@@ -2919,6 +2923,12 @@ const useParamsStore = defineStore("params", () => {
2919
2923
  }
2920
2924
  searchResultsLink.value = newSearchResultsLink;
2921
2925
  };
2926
+ const setSortSettings = ({ selectedSortKey, previousSortKey }) => {
2927
+ sortParams.value = {
2928
+ selectedSortKey,
2929
+ previousSortKey
2930
+ };
2931
+ };
2922
2932
  return {
2923
2933
  params,
2924
2934
  defaultLimit,
@@ -2929,6 +2939,7 @@ const useParamsStore = defineStore("params", () => {
2929
2939
  limit,
2930
2940
  sort,
2931
2941
  filters,
2942
+ sortParams,
2932
2943
  add,
2933
2944
  removeAllFilters,
2934
2945
  removeParameters,
@@ -2936,7 +2947,8 @@ const useParamsStore = defineStore("params", () => {
2936
2947
  goToResults,
2937
2948
  appendParams,
2938
2949
  setDefaultLimit,
2939
- setSearchResultsLink
2950
+ setSearchResultsLink,
2951
+ setSortSettings
2940
2952
  };
2941
2953
  });
2942
2954
  const flattenFacet = (key, facets, suggestion, inputValue) => {
@@ -4245,61 +4257,6 @@ const _sfc_main$13 = /* @__PURE__ */ vue.defineComponent(__spreadProps(__spreadV
4245
4257
  };
4246
4258
  }
4247
4259
  }));
4248
- const getSearchTrackingData = (searchText, type) => {
4249
- return {
4250
- searchQuery: searchText,
4251
- analytics: {
4252
- type,
4253
- label: searchText
4254
- }
4255
- };
4256
- };
4257
- const useTrackingStore = defineStore("tracking", () => {
4258
- const optionsStore = useOptionsStore();
4259
- const trackSearch = ({
4260
- queryKey,
4261
- query,
4262
- type = "search_query"
4263
- }) => {
4264
- var _a, _b;
4265
- const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
4266
- const hasFilters = Object.keys((_b = query.filters) != null ? _b : {}).length > 0;
4267
- if (hasFilters) {
4268
- const data2 = getSearchTrackingData(query.searchText, "search_filters");
4269
- track(queryKey, data2, options);
4270
- return;
4271
- }
4272
- const data = getSearchTrackingData(query.searchText, type);
4273
- track(queryKey, data, options);
4274
- };
4275
- const trackResults = ({
4276
- queryKey,
4277
- results
4278
- }) => {
4279
- var _a;
4280
- const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
4281
- if (results.total > 0) {
4282
- return;
4283
- }
4284
- const data = getSearchTrackingData(results.searchText, "search_zero_results");
4285
- track(queryKey, data, options);
4286
- };
4287
- const trackEvent = ({ queryKey, data }) => {
4288
- var _a, _b, _c, _d, _e;
4289
- const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
4290
- const trackingOptions = (_b = optionsStore.trackingOptions) != null ? _b : {};
4291
- const items = (_d = (_c = data.analytics) == null ? void 0 : _c.items) != null ? _d : [];
4292
- const mappedItems = ((_e = trackingOptions.analytics) == null ? void 0 : _e.itemMap) ? items.map(trackingOptions.analytics.itemMap) : items;
4293
- track(
4294
- queryKey,
4295
- __spreadProps(__spreadValues({}, data), {
4296
- analytics: data.analytics ? __spreadProps(__spreadValues({}, data.analytics), { items: mappedItems }) : void 0
4297
- }),
4298
- options
4299
- );
4300
- };
4301
- return { trackSearch, trackResults, trackEvent };
4302
- });
4303
4260
  const _hoisted_1$_ = ["href"];
4304
4261
  const _hoisted_2$I = { class: "lupa-search-box-product-image-section" };
4305
4262
  const _hoisted_3$x = { class: "lupa-search-box-product-details-section" };
@@ -4319,11 +4276,7 @@ const _sfc_main$12 = /* @__PURE__ */ vue.defineComponent({
4319
4276
  emits: ["product-click"],
4320
4277
  setup(__props, { emit }) {
4321
4278
  const props = __props;
4322
- const historyStore = useHistoryStore();
4323
- const trackingStore = useTrackingStore();
4324
- const optionsStore = useOptionsStore();
4325
4279
  const isInStock = vue.ref(true);
4326
- const { boxRoutingBehavior } = storeToRefs(optionsStore);
4327
4280
  const link = vue.computed(() => {
4328
4281
  var _a, _b;
4329
4282
  return generateLink((_b = (_a = props.panelOptions.links) == null ? void 0 : _a.details) != null ? _b : "", props.item);
@@ -4338,54 +4291,16 @@ const _sfc_main$12 = /* @__PURE__ */ vue.defineComponent({
4338
4291
  (e) => e.type !== DocumentElementType.IMAGE && e.type !== DocumentElementType.ADDTOCART
4339
4292
  )) != null ? _b : [];
4340
4293
  });
4341
- const id = vue.computed(() => {
4342
- if (props.panelOptions.idKey) {
4343
- return props.item[props.panelOptions.idKey];
4344
- }
4345
- return "";
4346
- });
4347
- const title = vue.computed(() => {
4348
- if (!props.panelOptions.titleKey) {
4349
- return "";
4350
- }
4351
- const title2 = props.item[props.panelOptions.titleKey] || "";
4352
- historyStore.add({
4353
- item: title2
4354
- });
4355
- return title2;
4356
- });
4357
4294
  const addToCartElement = vue.computed(() => {
4358
4295
  var _a;
4359
4296
  return (_a = props.panelOptions.elements) == null ? void 0 : _a.find((e) => e.type === DocumentElementType.ADDTOCART);
4360
4297
  });
4361
4298
  const handleClick = (event) => {
4362
- var _a;
4363
- if (props.panelOptions.titleKey) {
4364
- historyStore.add({
4365
- item: props.item[props.panelOptions.titleKey] || ""
4366
- });
4367
- }
4368
- if (!props.panelOptions.idKey) {
4369
- return;
4370
- }
4371
- trackingStore.trackEvent({
4372
- queryKey: props.panelOptions.queryKey,
4373
- data: {
4374
- itemId: id.value,
4375
- searchQuery: props.inputValue,
4376
- type: "itemClick",
4377
- analytics: {
4378
- type: "autocomplete_product_click",
4379
- label: (_a = title.value) != null ? _a : link.value,
4380
- items: [props.item]
4381
- }
4382
- }
4299
+ emit("product-click", {
4300
+ item: props.item,
4301
+ eventType: "itemClick",
4302
+ event
4383
4303
  });
4384
- if (!link.value) {
4385
- return;
4386
- }
4387
- emit("product-click");
4388
- handleRoutingEvent(link.value, event, boxRoutingBehavior.value === "event");
4389
4304
  };
4390
4305
  vue.onMounted(() => {
4391
4306
  checkIfIsInStock();
@@ -4438,6 +4353,61 @@ const _sfc_main$12 = /* @__PURE__ */ vue.defineComponent({
4438
4353
  };
4439
4354
  }
4440
4355
  });
4356
+ const getSearchTrackingData = (searchText, type) => {
4357
+ return {
4358
+ searchQuery: searchText,
4359
+ analytics: {
4360
+ type,
4361
+ label: searchText
4362
+ }
4363
+ };
4364
+ };
4365
+ const useTrackingStore = defineStore("tracking", () => {
4366
+ const optionsStore = useOptionsStore();
4367
+ const trackSearch = ({
4368
+ queryKey,
4369
+ query,
4370
+ type = "search_query"
4371
+ }) => {
4372
+ var _a, _b;
4373
+ const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
4374
+ const hasFilters = Object.keys((_b = query.filters) != null ? _b : {}).length > 0;
4375
+ if (hasFilters) {
4376
+ const data2 = getSearchTrackingData(query.searchText, "search_filters");
4377
+ track(queryKey, data2, options);
4378
+ return;
4379
+ }
4380
+ const data = getSearchTrackingData(query.searchText, type);
4381
+ track(queryKey, data, options);
4382
+ };
4383
+ const trackResults = ({
4384
+ queryKey,
4385
+ results
4386
+ }) => {
4387
+ var _a;
4388
+ const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
4389
+ if (results.total > 0) {
4390
+ return;
4391
+ }
4392
+ const data = getSearchTrackingData(results.searchText, "search_zero_results");
4393
+ track(queryKey, data, options);
4394
+ };
4395
+ const trackEvent = ({ queryKey, data }) => {
4396
+ var _a, _b, _c, _d, _e;
4397
+ const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
4398
+ const trackingOptions = (_b = optionsStore.trackingOptions) != null ? _b : {};
4399
+ const items = (_d = (_c = data.analytics) == null ? void 0 : _c.items) != null ? _d : [];
4400
+ const mappedItems = ((_e = trackingOptions.analytics) == null ? void 0 : _e.itemMap) ? items.map(trackingOptions.analytics.itemMap) : items;
4401
+ track(
4402
+ queryKey,
4403
+ __spreadProps(__spreadValues({}, data), {
4404
+ analytics: data.analytics ? __spreadProps(__spreadValues({}, data.analytics), { items: mappedItems }) : void 0
4405
+ }),
4406
+ options
4407
+ );
4408
+ };
4409
+ return { trackSearch, trackResults, trackEvent };
4410
+ });
4441
4411
  const _hoisted_1$Z = { id: "lupa-search-box-products" };
4442
4412
  const _sfc_main$11 = /* @__PURE__ */ vue.defineComponent({
4443
4413
  __name: "SearchBoxProducts",
@@ -4447,9 +4417,14 @@ const _sfc_main$11 = /* @__PURE__ */ vue.defineComponent({
4447
4417
  panelOptions: {},
4448
4418
  labels: {}
4449
4419
  },
4450
- setup(__props) {
4420
+ emits: ["product-click"],
4421
+ setup(__props, { emit }) {
4451
4422
  const props = __props;
4452
4423
  const searchBoxStore = useSearchBoxStore();
4424
+ const historyStore = useHistoryStore();
4425
+ const trackingStore = useTrackingStore();
4426
+ const optionsStore = useOptionsStore();
4427
+ const { boxRoutingBehavior } = storeToRefs(optionsStore);
4453
4428
  const { highlightedItem } = storeToRefs(searchBoxStore);
4454
4429
  const highlightedIndex = vue.computed(() => {
4455
4430
  var _a, _b, _c;
@@ -4458,6 +4433,42 @@ const _sfc_main$11 = /* @__PURE__ */ vue.defineComponent({
4458
4433
  }
4459
4434
  return (_c = (_b = highlightedItem.value) == null ? void 0 : _b.index) != null ? _c : -1;
4460
4435
  });
4436
+ const handleProductClick = ({
4437
+ item,
4438
+ eventType,
4439
+ event
4440
+ }) => {
4441
+ var _a, _b;
4442
+ const link = generateLink((_b = (_a = props.panelOptions.links) == null ? void 0 : _a.details) != null ? _b : "", item);
4443
+ const title = props.panelOptions.titleKey ? item[props.panelOptions.titleKey] || "" : "";
4444
+ const id = props.panelOptions.idKey ? item[props.panelOptions.idKey] : "";
4445
+ if (props.panelOptions.titleKey) {
4446
+ historyStore.add({
4447
+ item: item[props.panelOptions.titleKey] || ""
4448
+ });
4449
+ }
4450
+ if (!props.panelOptions.idKey) {
4451
+ return;
4452
+ }
4453
+ trackingStore.trackEvent({
4454
+ queryKey: props.panelOptions.queryKey,
4455
+ data: {
4456
+ itemId: id,
4457
+ searchQuery: props.inputValue,
4458
+ type: eventType || "itemClick",
4459
+ analytics: {
4460
+ type: "autocomplete_product_click",
4461
+ label: title != null ? title : link,
4462
+ items: [item]
4463
+ }
4464
+ }
4465
+ });
4466
+ if (!link) {
4467
+ return;
4468
+ }
4469
+ emit("product-click");
4470
+ handleRoutingEvent(link, event, boxRoutingBehavior.value === "event");
4471
+ };
4461
4472
  return (_ctx, _cache) => {
4462
4473
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$Z, [
4463
4474
  _ctx.$slots.productCard ? (vue.openBlock(true), vue.createElementBlock(vue.Fragment, { key: 0 }, vue.renderList(_ctx.items, (item, index) => {
@@ -4468,7 +4479,7 @@ const _sfc_main$11 = /* @__PURE__ */ vue.defineComponent({
4468
4479
  labels: _ctx.labels,
4469
4480
  highlighted: index === highlightedIndex.value,
4470
4481
  inputValue: _ctx.inputValue,
4471
- onProductClick: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("product-click"))
4482
+ itemClicked: handleProductClick
4472
4483
  });
4473
4484
  }), 128)) : (vue.openBlock(true), vue.createElementBlock(vue.Fragment, { key: 1 }, vue.renderList(_ctx.items, (item, index) => {
4474
4485
  return vue.openBlock(), vue.createBlock(_sfc_main$12, {
@@ -4478,7 +4489,7 @@ const _sfc_main$11 = /* @__PURE__ */ vue.defineComponent({
4478
4489
  labels: _ctx.labels,
4479
4490
  highlighted: index === highlightedIndex.value,
4480
4491
  inputValue: _ctx.inputValue,
4481
- onProductClick: _cache[1] || (_cache[1] = ($event) => _ctx.$emit("product-click"))
4492
+ onProductClick: handleProductClick
4482
4493
  }, null, 8, ["item", "panelOptions", "labels", "highlighted", "inputValue"]);
4483
4494
  }), 128))
4484
4495
  ]);
@@ -7830,6 +7841,7 @@ const _sfc_main$D = /* @__PURE__ */ vue.defineComponent({
7830
7841
  if (!value) {
7831
7842
  return;
7832
7843
  }
7844
+ paramStore.setSortSettings({ selectedSortKey: value, previousSortKey: previousKey.value });
7833
7845
  (_c = (_b = props.callbacks) == null ? void 0 : _b.onSortChange) == null ? void 0 : _c.call(_b, { selectedSortKey: value, previousSortKey: previousKey.value });
7834
7846
  paramStore.appendParams({
7835
7847
  params: [{ name: QUERY_PARAMS.SORT, value }],
@@ -9536,7 +9548,7 @@ const _sfc_main$c = /* @__PURE__ */ vue.defineComponent({
9536
9548
  return (_a = props.initialFilters) != null ? _a : {};
9537
9549
  });
9538
9550
  const { currentQueryText, hasResults, currentFilterCount } = storeToRefs(searchResultStore);
9539
- const { searchString } = storeToRefs(paramStore);
9551
+ const { searchString, sortParams } = storeToRefs(paramStore);
9540
9552
  const { defaultSearchResultPageSize } = storeToRefs(optionStore);
9541
9553
  const searchResultsFilters = vue.ref(null);
9542
9554
  const mounted = vue.ref(false);
@@ -9573,6 +9585,7 @@ const _sfc_main$c = /* @__PURE__ */ vue.defineComponent({
9573
9585
  window.removeEventListener("popstate", handlePopState);
9574
9586
  });
9575
9587
  const trackItemListView = (title, items = []) => {
9588
+ var _a, _b;
9576
9589
  trackingStore.trackEvent({
9577
9590
  queryKey: props.options.queryKey,
9578
9591
  data: {
@@ -9580,7 +9593,11 @@ const _sfc_main$c = /* @__PURE__ */ vue.defineComponent({
9580
9593
  type: "view_item_list",
9581
9594
  label: title,
9582
9595
  listLabel: title,
9583
- items
9596
+ items,
9597
+ additionalParams: {
9598
+ previousSortKey: (_a = sortParams.value) == null ? void 0 : _a.previousSortKey,
9599
+ newSortKey: (_b = sortParams.value) == null ? void 0 : _b.selectedSortKey
9600
+ }
9584
9601
  },
9585
9602
  options: { allowEmptySearchQuery: true }
9586
9603
  }
@@ -1926,21 +1926,21 @@ const sendUaAnalyticsEvent = (data, options) => {
1926
1926
  );
1927
1927
  };
1928
1928
  const sendGa4AnalyticsEvent = (data, options) => {
1929
- var _a, _b, _c, _d, _e;
1929
+ var _a, _b, _c, _d, _e, _f, _g;
1930
1930
  if (!window || !window.dataLayer) {
1931
1931
  console.error("dataLayer object not found.");
1932
1932
  return;
1933
1933
  }
1934
1934
  const sendItemTitle = data.searchQuery !== ((_a = data.analytics) == null ? void 0 : _a.label);
1935
1935
  const title = sendItemTitle ? (_b = data.analytics) == null ? void 0 : _b.label : void 0;
1936
- const params = {
1936
+ const params = __spreadValues({
1937
1937
  search_text: data.searchQuery,
1938
1938
  item_title: title,
1939
1939
  item_id: data.itemId,
1940
1940
  ecommerce: parseEcommerceData(data, (_c = data.analytics) == null ? void 0 : _c.listLabel)
1941
- };
1941
+ }, (_e = (_d = data.analytics) == null ? void 0 : _d.additionalParams) != null ? _e : {});
1942
1942
  window.dataLayer.push(__spreadValues({
1943
- event: (_e = (_d = data.analytics) == null ? void 0 : _d.type) != null ? _e : options.parentEventName
1943
+ event: (_g = (_f = data.analytics) == null ? void 0 : _f.type) != null ? _g : options.parentEventName
1944
1944
  }, params));
1945
1945
  };
1946
1946
  const processDebugEvent = (data) => {
@@ -2783,6 +2783,10 @@ const useParamsStore = defineStore("params", () => {
2783
2783
  const searchString = ref("");
2784
2784
  const optionsStore = useOptionsStore();
2785
2785
  const redirectionStore = useRedirectionStore();
2786
+ const sortParams = ref({
2787
+ selectedSortKey: "",
2788
+ previousSortKey: ""
2789
+ });
2786
2790
  const query = computed(() => params.value[QUERY_PARAMS_PARSED.QUERY]);
2787
2791
  const page = computed(() => {
2788
2792
  const page2 = Number(params.value[QUERY_PARAMS_PARSED.PAGE]) || 1;
@@ -2917,6 +2921,12 @@ const useParamsStore = defineStore("params", () => {
2917
2921
  }
2918
2922
  searchResultsLink.value = newSearchResultsLink;
2919
2923
  };
2924
+ const setSortSettings = ({ selectedSortKey, previousSortKey }) => {
2925
+ sortParams.value = {
2926
+ selectedSortKey,
2927
+ previousSortKey
2928
+ };
2929
+ };
2920
2930
  return {
2921
2931
  params,
2922
2932
  defaultLimit,
@@ -2927,6 +2937,7 @@ const useParamsStore = defineStore("params", () => {
2927
2937
  limit,
2928
2938
  sort,
2929
2939
  filters,
2940
+ sortParams,
2930
2941
  add,
2931
2942
  removeAllFilters,
2932
2943
  removeParameters,
@@ -2934,7 +2945,8 @@ const useParamsStore = defineStore("params", () => {
2934
2945
  goToResults,
2935
2946
  appendParams,
2936
2947
  setDefaultLimit,
2937
- setSearchResultsLink
2948
+ setSearchResultsLink,
2949
+ setSortSettings
2938
2950
  };
2939
2951
  });
2940
2952
  const flattenFacet = (key, facets, suggestion, inputValue) => {
@@ -4243,61 +4255,6 @@ const _sfc_main$13 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValue
4243
4255
  };
4244
4256
  }
4245
4257
  }));
4246
- const getSearchTrackingData = (searchText, type) => {
4247
- return {
4248
- searchQuery: searchText,
4249
- analytics: {
4250
- type,
4251
- label: searchText
4252
- }
4253
- };
4254
- };
4255
- const useTrackingStore = defineStore("tracking", () => {
4256
- const optionsStore = useOptionsStore();
4257
- const trackSearch = ({
4258
- queryKey,
4259
- query,
4260
- type = "search_query"
4261
- }) => {
4262
- var _a, _b;
4263
- const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
4264
- const hasFilters = Object.keys((_b = query.filters) != null ? _b : {}).length > 0;
4265
- if (hasFilters) {
4266
- const data2 = getSearchTrackingData(query.searchText, "search_filters");
4267
- track(queryKey, data2, options);
4268
- return;
4269
- }
4270
- const data = getSearchTrackingData(query.searchText, type);
4271
- track(queryKey, data, options);
4272
- };
4273
- const trackResults = ({
4274
- queryKey,
4275
- results
4276
- }) => {
4277
- var _a;
4278
- const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
4279
- if (results.total > 0) {
4280
- return;
4281
- }
4282
- const data = getSearchTrackingData(results.searchText, "search_zero_results");
4283
- track(queryKey, data, options);
4284
- };
4285
- const trackEvent = ({ queryKey, data }) => {
4286
- var _a, _b, _c, _d, _e;
4287
- const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
4288
- const trackingOptions = (_b = optionsStore.trackingOptions) != null ? _b : {};
4289
- const items = (_d = (_c = data.analytics) == null ? void 0 : _c.items) != null ? _d : [];
4290
- const mappedItems = ((_e = trackingOptions.analytics) == null ? void 0 : _e.itemMap) ? items.map(trackingOptions.analytics.itemMap) : items;
4291
- track(
4292
- queryKey,
4293
- __spreadProps(__spreadValues({}, data), {
4294
- analytics: data.analytics ? __spreadProps(__spreadValues({}, data.analytics), { items: mappedItems }) : void 0
4295
- }),
4296
- options
4297
- );
4298
- };
4299
- return { trackSearch, trackResults, trackEvent };
4300
- });
4301
4258
  const _hoisted_1$_ = ["href"];
4302
4259
  const _hoisted_2$I = { class: "lupa-search-box-product-image-section" };
4303
4260
  const _hoisted_3$x = { class: "lupa-search-box-product-details-section" };
@@ -4317,11 +4274,7 @@ const _sfc_main$12 = /* @__PURE__ */ defineComponent({
4317
4274
  emits: ["product-click"],
4318
4275
  setup(__props, { emit }) {
4319
4276
  const props = __props;
4320
- const historyStore = useHistoryStore();
4321
- const trackingStore = useTrackingStore();
4322
- const optionsStore = useOptionsStore();
4323
4277
  const isInStock = ref(true);
4324
- const { boxRoutingBehavior } = storeToRefs(optionsStore);
4325
4278
  const link = computed(() => {
4326
4279
  var _a, _b;
4327
4280
  return generateLink((_b = (_a = props.panelOptions.links) == null ? void 0 : _a.details) != null ? _b : "", props.item);
@@ -4336,54 +4289,16 @@ const _sfc_main$12 = /* @__PURE__ */ defineComponent({
4336
4289
  (e) => e.type !== DocumentElementType.IMAGE && e.type !== DocumentElementType.ADDTOCART
4337
4290
  )) != null ? _b : [];
4338
4291
  });
4339
- const id = computed(() => {
4340
- if (props.panelOptions.idKey) {
4341
- return props.item[props.panelOptions.idKey];
4342
- }
4343
- return "";
4344
- });
4345
- const title = computed(() => {
4346
- if (!props.panelOptions.titleKey) {
4347
- return "";
4348
- }
4349
- const title2 = props.item[props.panelOptions.titleKey] || "";
4350
- historyStore.add({
4351
- item: title2
4352
- });
4353
- return title2;
4354
- });
4355
4292
  const addToCartElement = computed(() => {
4356
4293
  var _a;
4357
4294
  return (_a = props.panelOptions.elements) == null ? void 0 : _a.find((e) => e.type === DocumentElementType.ADDTOCART);
4358
4295
  });
4359
4296
  const handleClick = (event) => {
4360
- var _a;
4361
- if (props.panelOptions.titleKey) {
4362
- historyStore.add({
4363
- item: props.item[props.panelOptions.titleKey] || ""
4364
- });
4365
- }
4366
- if (!props.panelOptions.idKey) {
4367
- return;
4368
- }
4369
- trackingStore.trackEvent({
4370
- queryKey: props.panelOptions.queryKey,
4371
- data: {
4372
- itemId: id.value,
4373
- searchQuery: props.inputValue,
4374
- type: "itemClick",
4375
- analytics: {
4376
- type: "autocomplete_product_click",
4377
- label: (_a = title.value) != null ? _a : link.value,
4378
- items: [props.item]
4379
- }
4380
- }
4297
+ emit("product-click", {
4298
+ item: props.item,
4299
+ eventType: "itemClick",
4300
+ event
4381
4301
  });
4382
- if (!link.value) {
4383
- return;
4384
- }
4385
- emit("product-click");
4386
- handleRoutingEvent(link.value, event, boxRoutingBehavior.value === "event");
4387
4302
  };
4388
4303
  onMounted(() => {
4389
4304
  checkIfIsInStock();
@@ -4436,6 +4351,61 @@ const _sfc_main$12 = /* @__PURE__ */ defineComponent({
4436
4351
  };
4437
4352
  }
4438
4353
  });
4354
+ const getSearchTrackingData = (searchText, type) => {
4355
+ return {
4356
+ searchQuery: searchText,
4357
+ analytics: {
4358
+ type,
4359
+ label: searchText
4360
+ }
4361
+ };
4362
+ };
4363
+ const useTrackingStore = defineStore("tracking", () => {
4364
+ const optionsStore = useOptionsStore();
4365
+ const trackSearch = ({
4366
+ queryKey,
4367
+ query,
4368
+ type = "search_query"
4369
+ }) => {
4370
+ var _a, _b;
4371
+ const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
4372
+ const hasFilters = Object.keys((_b = query.filters) != null ? _b : {}).length > 0;
4373
+ if (hasFilters) {
4374
+ const data2 = getSearchTrackingData(query.searchText, "search_filters");
4375
+ track(queryKey, data2, options);
4376
+ return;
4377
+ }
4378
+ const data = getSearchTrackingData(query.searchText, type);
4379
+ track(queryKey, data, options);
4380
+ };
4381
+ const trackResults = ({
4382
+ queryKey,
4383
+ results
4384
+ }) => {
4385
+ var _a;
4386
+ const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
4387
+ if (results.total > 0) {
4388
+ return;
4389
+ }
4390
+ const data = getSearchTrackingData(results.searchText, "search_zero_results");
4391
+ track(queryKey, data, options);
4392
+ };
4393
+ const trackEvent = ({ queryKey, data }) => {
4394
+ var _a, _b, _c, _d, _e;
4395
+ const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
4396
+ const trackingOptions = (_b = optionsStore.trackingOptions) != null ? _b : {};
4397
+ const items = (_d = (_c = data.analytics) == null ? void 0 : _c.items) != null ? _d : [];
4398
+ const mappedItems = ((_e = trackingOptions.analytics) == null ? void 0 : _e.itemMap) ? items.map(trackingOptions.analytics.itemMap) : items;
4399
+ track(
4400
+ queryKey,
4401
+ __spreadProps(__spreadValues({}, data), {
4402
+ analytics: data.analytics ? __spreadProps(__spreadValues({}, data.analytics), { items: mappedItems }) : void 0
4403
+ }),
4404
+ options
4405
+ );
4406
+ };
4407
+ return { trackSearch, trackResults, trackEvent };
4408
+ });
4439
4409
  const _hoisted_1$Z = { id: "lupa-search-box-products" };
4440
4410
  const _sfc_main$11 = /* @__PURE__ */ defineComponent({
4441
4411
  __name: "SearchBoxProducts",
@@ -4445,9 +4415,14 @@ const _sfc_main$11 = /* @__PURE__ */ defineComponent({
4445
4415
  panelOptions: {},
4446
4416
  labels: {}
4447
4417
  },
4448
- setup(__props) {
4418
+ emits: ["product-click"],
4419
+ setup(__props, { emit }) {
4449
4420
  const props = __props;
4450
4421
  const searchBoxStore = useSearchBoxStore();
4422
+ const historyStore = useHistoryStore();
4423
+ const trackingStore = useTrackingStore();
4424
+ const optionsStore = useOptionsStore();
4425
+ const { boxRoutingBehavior } = storeToRefs(optionsStore);
4451
4426
  const { highlightedItem } = storeToRefs(searchBoxStore);
4452
4427
  const highlightedIndex = computed(() => {
4453
4428
  var _a, _b, _c;
@@ -4456,6 +4431,42 @@ const _sfc_main$11 = /* @__PURE__ */ defineComponent({
4456
4431
  }
4457
4432
  return (_c = (_b = highlightedItem.value) == null ? void 0 : _b.index) != null ? _c : -1;
4458
4433
  });
4434
+ const handleProductClick = ({
4435
+ item,
4436
+ eventType,
4437
+ event
4438
+ }) => {
4439
+ var _a, _b;
4440
+ const link = generateLink((_b = (_a = props.panelOptions.links) == null ? void 0 : _a.details) != null ? _b : "", item);
4441
+ const title = props.panelOptions.titleKey ? item[props.panelOptions.titleKey] || "" : "";
4442
+ const id = props.panelOptions.idKey ? item[props.panelOptions.idKey] : "";
4443
+ if (props.panelOptions.titleKey) {
4444
+ historyStore.add({
4445
+ item: item[props.panelOptions.titleKey] || ""
4446
+ });
4447
+ }
4448
+ if (!props.panelOptions.idKey) {
4449
+ return;
4450
+ }
4451
+ trackingStore.trackEvent({
4452
+ queryKey: props.panelOptions.queryKey,
4453
+ data: {
4454
+ itemId: id,
4455
+ searchQuery: props.inputValue,
4456
+ type: eventType || "itemClick",
4457
+ analytics: {
4458
+ type: "autocomplete_product_click",
4459
+ label: title != null ? title : link,
4460
+ items: [item]
4461
+ }
4462
+ }
4463
+ });
4464
+ if (!link) {
4465
+ return;
4466
+ }
4467
+ emit("product-click");
4468
+ handleRoutingEvent(link, event, boxRoutingBehavior.value === "event");
4469
+ };
4459
4470
  return (_ctx, _cache) => {
4460
4471
  return openBlock(), createElementBlock("div", _hoisted_1$Z, [
4461
4472
  _ctx.$slots.productCard ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(_ctx.items, (item, index) => {
@@ -4466,7 +4477,7 @@ const _sfc_main$11 = /* @__PURE__ */ defineComponent({
4466
4477
  labels: _ctx.labels,
4467
4478
  highlighted: index === highlightedIndex.value,
4468
4479
  inputValue: _ctx.inputValue,
4469
- onProductClick: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("product-click"))
4480
+ itemClicked: handleProductClick
4470
4481
  });
4471
4482
  }), 128)) : (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(_ctx.items, (item, index) => {
4472
4483
  return openBlock(), createBlock(_sfc_main$12, {
@@ -4476,7 +4487,7 @@ const _sfc_main$11 = /* @__PURE__ */ defineComponent({
4476
4487
  labels: _ctx.labels,
4477
4488
  highlighted: index === highlightedIndex.value,
4478
4489
  inputValue: _ctx.inputValue,
4479
- onProductClick: _cache[1] || (_cache[1] = ($event) => _ctx.$emit("product-click"))
4490
+ onProductClick: handleProductClick
4480
4491
  }, null, 8, ["item", "panelOptions", "labels", "highlighted", "inputValue"]);
4481
4492
  }), 128))
4482
4493
  ]);
@@ -7828,6 +7839,7 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
7828
7839
  if (!value) {
7829
7840
  return;
7830
7841
  }
7842
+ paramStore.setSortSettings({ selectedSortKey: value, previousSortKey: previousKey.value });
7831
7843
  (_c = (_b = props.callbacks) == null ? void 0 : _b.onSortChange) == null ? void 0 : _c.call(_b, { selectedSortKey: value, previousSortKey: previousKey.value });
7832
7844
  paramStore.appendParams({
7833
7845
  params: [{ name: QUERY_PARAMS.SORT, value }],
@@ -9534,7 +9546,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
9534
9546
  return (_a = props.initialFilters) != null ? _a : {};
9535
9547
  });
9536
9548
  const { currentQueryText, hasResults, currentFilterCount } = storeToRefs(searchResultStore);
9537
- const { searchString } = storeToRefs(paramStore);
9549
+ const { searchString, sortParams } = storeToRefs(paramStore);
9538
9550
  const { defaultSearchResultPageSize } = storeToRefs(optionStore);
9539
9551
  const searchResultsFilters = ref(null);
9540
9552
  const mounted = ref(false);
@@ -9571,6 +9583,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
9571
9583
  window.removeEventListener("popstate", handlePopState);
9572
9584
  });
9573
9585
  const trackItemListView = (title, items = []) => {
9586
+ var _a, _b;
9574
9587
  trackingStore.trackEvent({
9575
9588
  queryKey: props.options.queryKey,
9576
9589
  data: {
@@ -9578,7 +9591,11 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
9578
9591
  type: "view_item_list",
9579
9592
  label: title,
9580
9593
  listLabel: title,
9581
- items
9594
+ items,
9595
+ additionalParams: {
9596
+ previousSortKey: (_a = sortParams.value) == null ? void 0 : _a.previousSortKey,
9597
+ newSortKey: (_b = sortParams.value) == null ? void 0 : _b.selectedSortKey
9598
+ }
9582
9599
  },
9583
9600
  options: { allowEmptySearchQuery: true }
9584
9601
  }
@@ -19,7 +19,7 @@ declare const _sfc_main: import("vue").DefineComponent<{
19
19
  type: __PropType<SearchBoxOptionLabels>;
20
20
  required: false;
21
21
  };
22
- }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
22
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "product-click"[], "product-click", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
23
23
  items: {
24
24
  type: __PropType<Document[]>;
25
25
  required: true;
@@ -36,5 +36,7 @@ declare const _sfc_main: import("vue").DefineComponent<{
36
36
  type: __PropType<SearchBoxOptionLabels>;
37
37
  required: false;
38
38
  };
39
- }>>, {}, {}>;
39
+ }>> & {
40
+ "onProduct-click"?: (...args: any[]) => any;
41
+ }, {}, {}>;
40
42
  export default _sfc_main;
@@ -1,7 +1,7 @@
1
1
  import { type Ref } from 'vue';
2
2
  import type { QueryParams } from '../types/search-results/QueryParams';
3
3
  import type { InputSuggestionFacet } from '../types/search-box/Common';
4
- import { SsrOptions } from '..';
4
+ import { SortCallbackContext, SsrOptions } from '..';
5
5
  export declare const useParamsStore: import("pinia").StoreDefinition<"params", import("pinia")._UnwrapAll<Pick<{
6
6
  params: Ref<QueryParams>;
7
7
  defaultLimit: Ref<number>;
@@ -12,6 +12,10 @@ export declare const useParamsStore: import("pinia").StoreDefinition<"params", i
12
12
  limit: import("vue").ComputedRef<number>;
13
13
  sort: import("vue").ComputedRef<string>;
14
14
  filters: import("vue").ComputedRef<import("@getlupa/client-sdk/Types").FilterGroup>;
15
+ sortParams: Ref<{
16
+ selectedSortKey: string;
17
+ previousSortKey: string;
18
+ }>;
15
19
  add: (newParams: QueryParams, ssr?: SsrOptions) => {
16
20
  params: QueryParams;
17
21
  };
@@ -42,7 +46,8 @@ export declare const useParamsStore: import("pinia").StoreDefinition<"params", i
42
46
  };
43
47
  setDefaultLimit: (newDefaultLimit: number) => number;
44
48
  setSearchResultsLink: (newSearchResultsLink: string) => void;
45
- }, "params" | "searchResultsLink" | "defaultLimit" | "searchString">>, Pick<{
49
+ setSortSettings: ({ selectedSortKey, previousSortKey }: SortCallbackContext) => void;
50
+ }, "params" | "searchResultsLink" | "defaultLimit" | "searchString" | "sortParams">>, Pick<{
46
51
  params: Ref<QueryParams>;
47
52
  defaultLimit: Ref<number>;
48
53
  searchResultsLink: Ref<string>;
@@ -52,6 +57,10 @@ export declare const useParamsStore: import("pinia").StoreDefinition<"params", i
52
57
  limit: import("vue").ComputedRef<number>;
53
58
  sort: import("vue").ComputedRef<string>;
54
59
  filters: import("vue").ComputedRef<import("@getlupa/client-sdk/Types").FilterGroup>;
60
+ sortParams: Ref<{
61
+ selectedSortKey: string;
62
+ previousSortKey: string;
63
+ }>;
55
64
  add: (newParams: QueryParams, ssr?: SsrOptions) => {
56
65
  params: QueryParams;
57
66
  };
@@ -82,6 +91,7 @@ export declare const useParamsStore: import("pinia").StoreDefinition<"params", i
82
91
  };
83
92
  setDefaultLimit: (newDefaultLimit: number) => number;
84
93
  setSearchResultsLink: (newSearchResultsLink: string) => void;
94
+ setSortSettings: ({ selectedSortKey, previousSortKey }: SortCallbackContext) => void;
85
95
  }, "sort" | "filters" | "query" | "page" | "limit">, Pick<{
86
96
  params: Ref<QueryParams>;
87
97
  defaultLimit: Ref<number>;
@@ -92,6 +102,10 @@ export declare const useParamsStore: import("pinia").StoreDefinition<"params", i
92
102
  limit: import("vue").ComputedRef<number>;
93
103
  sort: import("vue").ComputedRef<string>;
94
104
  filters: import("vue").ComputedRef<import("@getlupa/client-sdk/Types").FilterGroup>;
105
+ sortParams: Ref<{
106
+ selectedSortKey: string;
107
+ previousSortKey: string;
108
+ }>;
95
109
  add: (newParams: QueryParams, ssr?: SsrOptions) => {
96
110
  params: QueryParams;
97
111
  };
@@ -122,4 +136,5 @@ export declare const useParamsStore: import("pinia").StoreDefinition<"params", i
122
136
  };
123
137
  setDefaultLimit: (newDefaultLimit: number) => number;
124
138
  setSearchResultsLink: (newSearchResultsLink: string) => void;
125
- }, "add" | "removeAllFilters" | "removeParameters" | "handleNoResultsFlag" | "goToResults" | "appendParams" | "setDefaultLimit" | "setSearchResultsLink">>;
139
+ setSortSettings: ({ selectedSortKey, previousSortKey }: SortCallbackContext) => void;
140
+ }, "add" | "removeAllFilters" | "removeParameters" | "handleNoResultsFlag" | "goToResults" | "appendParams" | "setDefaultLimit" | "setSearchResultsLink" | "setSortSettings">>;
@@ -37,6 +37,7 @@ export type TrackableEventData = {
37
37
  listLabel?: string;
38
38
  items?: Record<string, unknown>[];
39
39
  itemId?: string;
40
+ additionalParams?: Record<string, unknown>;
40
41
  };
41
42
  options?: {
42
43
  allowEmptySearchQuery: boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@getlupa/vue",
3
- "version": "0.7.3",
4
- "main": "dist/lupaSearch.js",
3
+ "version": "0.7.5",
4
+ "main": "dist/lupaSearch.mjs",
5
5
  "module": "dist/lupaSearch.mjs",
6
6
  "types": "dist/src/index.d.ts",
7
7
  "scripts": {