@getlupa/client 1.6.3 → 1.6.4

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.
@@ -6574,21 +6574,21 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
6574
6574
  );
6575
6575
  };
6576
6576
  const sendGa4AnalyticsEvent = (data, options) => {
6577
- var _a, _b, _c, _d, _e;
6577
+ var _a, _b, _c, _d, _e, _f, _g;
6578
6578
  if (!window || !window.dataLayer) {
6579
6579
  console.error("dataLayer object not found.");
6580
6580
  return;
6581
6581
  }
6582
6582
  const sendItemTitle = data.searchQuery !== ((_a = data.analytics) == null ? void 0 : _a.label);
6583
6583
  const title = sendItemTitle ? (_b = data.analytics) == null ? void 0 : _b.label : void 0;
6584
- const params = {
6584
+ const params = __spreadValues2({
6585
6585
  search_text: data.searchQuery,
6586
6586
  item_title: title,
6587
6587
  item_id: data.itemId,
6588
6588
  ecommerce: parseEcommerceData(data, (_c = data.analytics) == null ? void 0 : _c.listLabel)
6589
- };
6589
+ }, (_e = (_d = data.analytics) == null ? void 0 : _d.additionalParams) != null ? _e : {});
6590
6590
  window.dataLayer.push(__spreadValues2({
6591
- event: (_e = (_d = data.analytics) == null ? void 0 : _d.type) != null ? _e : options.parentEventName
6591
+ event: (_g = (_f = data.analytics) == null ? void 0 : _f.type) != null ? _g : options.parentEventName
6592
6592
  }, params));
6593
6593
  };
6594
6594
  const processDebugEvent = (data) => {
@@ -7431,6 +7431,10 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7431
7431
  const searchString = ref("");
7432
7432
  const optionsStore = useOptionsStore();
7433
7433
  const redirectionStore = useRedirectionStore();
7434
+ const sortParams = ref({
7435
+ selectedSortKey: "",
7436
+ previousSortKey: ""
7437
+ });
7434
7438
  const query = computed(() => params.value[QUERY_PARAMS_PARSED.QUERY]);
7435
7439
  const page = computed(() => {
7436
7440
  const page2 = Number(params.value[QUERY_PARAMS_PARSED.PAGE]) || 1;
@@ -7565,6 +7569,12 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7565
7569
  }
7566
7570
  searchResultsLink.value = newSearchResultsLink;
7567
7571
  };
7572
+ const setSortSettings = ({ selectedSortKey, previousSortKey }) => {
7573
+ sortParams.value = {
7574
+ selectedSortKey,
7575
+ previousSortKey
7576
+ };
7577
+ };
7568
7578
  return {
7569
7579
  params,
7570
7580
  defaultLimit,
@@ -7575,6 +7585,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7575
7585
  limit,
7576
7586
  sort,
7577
7587
  filters,
7588
+ sortParams,
7578
7589
  add: add2,
7579
7590
  removeAllFilters,
7580
7591
  removeParameters,
@@ -7582,7 +7593,8 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7582
7593
  goToResults,
7583
7594
  appendParams,
7584
7595
  setDefaultLimit,
7585
- setSearchResultsLink
7596
+ setSearchResultsLink,
7597
+ setSortSettings
7586
7598
  };
7587
7599
  });
7588
7600
  const flattenFacet = (key, facets, suggestion, inputValue) => {
@@ -8891,61 +8903,6 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
8891
8903
  };
8892
8904
  }
8893
8905
  }));
8894
- const getSearchTrackingData = (searchText, type) => {
8895
- return {
8896
- searchQuery: searchText,
8897
- analytics: {
8898
- type,
8899
- label: searchText
8900
- }
8901
- };
8902
- };
8903
- const useTrackingStore = defineStore("tracking", () => {
8904
- const optionsStore = useOptionsStore();
8905
- const trackSearch = ({
8906
- queryKey,
8907
- query,
8908
- type = "search_query"
8909
- }) => {
8910
- var _a, _b;
8911
- const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
8912
- const hasFilters = Object.keys((_b = query.filters) != null ? _b : {}).length > 0;
8913
- if (hasFilters) {
8914
- const data2 = getSearchTrackingData(query.searchText, "search_filters");
8915
- track(queryKey, data2, options);
8916
- return;
8917
- }
8918
- const data = getSearchTrackingData(query.searchText, type);
8919
- track(queryKey, data, options);
8920
- };
8921
- const trackResults = ({
8922
- queryKey,
8923
- results
8924
- }) => {
8925
- var _a;
8926
- const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
8927
- if (results.total > 0) {
8928
- return;
8929
- }
8930
- const data = getSearchTrackingData(results.searchText, "search_zero_results");
8931
- track(queryKey, data, options);
8932
- };
8933
- const trackEvent = ({ queryKey, data }) => {
8934
- var _a, _b, _c, _d, _e;
8935
- const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
8936
- const trackingOptions = (_b = optionsStore.trackingOptions) != null ? _b : {};
8937
- const items = (_d = (_c = data.analytics) == null ? void 0 : _c.items) != null ? _d : [];
8938
- const mappedItems = ((_e = trackingOptions.analytics) == null ? void 0 : _e.itemMap) ? items.map(trackingOptions.analytics.itemMap) : items;
8939
- track(
8940
- queryKey,
8941
- __spreadProps2(__spreadValues2({}, data), {
8942
- analytics: data.analytics ? __spreadProps2(__spreadValues2({}, data.analytics), { items: mappedItems }) : void 0
8943
- }),
8944
- options
8945
- );
8946
- };
8947
- return { trackSearch, trackResults, trackEvent };
8948
- });
8949
8906
  const _hoisted_1$_ = ["href"];
8950
8907
  const _hoisted_2$I = { class: "lupa-search-box-product-image-section" };
8951
8908
  const _hoisted_3$x = { class: "lupa-search-box-product-details-section" };
@@ -8965,11 +8922,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
8965
8922
  emits: ["product-click"],
8966
8923
  setup(__props, { emit: emit2 }) {
8967
8924
  const props = __props;
8968
- const historyStore = useHistoryStore();
8969
- const trackingStore = useTrackingStore();
8970
- const optionsStore = useOptionsStore();
8971
8925
  const isInStock = ref(true);
8972
- const { boxRoutingBehavior } = storeToRefs(optionsStore);
8973
8926
  const link = computed(() => {
8974
8927
  var _a, _b;
8975
8928
  return generateLink((_b = (_a = props.panelOptions.links) == null ? void 0 : _a.details) != null ? _b : "", props.item);
@@ -8984,54 +8937,16 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
8984
8937
  (e) => e.type !== DocumentElementType.IMAGE && e.type !== DocumentElementType.ADDTOCART
8985
8938
  )) != null ? _b : [];
8986
8939
  });
8987
- const id = computed(() => {
8988
- if (props.panelOptions.idKey) {
8989
- return props.item[props.panelOptions.idKey];
8990
- }
8991
- return "";
8992
- });
8993
- const title = computed(() => {
8994
- if (!props.panelOptions.titleKey) {
8995
- return "";
8996
- }
8997
- const title2 = props.item[props.panelOptions.titleKey] || "";
8998
- historyStore.add({
8999
- item: title2
9000
- });
9001
- return title2;
9002
- });
9003
8940
  const addToCartElement = computed(() => {
9004
8941
  var _a;
9005
8942
  return (_a = props.panelOptions.elements) == null ? void 0 : _a.find((e) => e.type === DocumentElementType.ADDTOCART);
9006
8943
  });
9007
8944
  const handleClick = (event) => {
9008
- var _a;
9009
- if (props.panelOptions.titleKey) {
9010
- historyStore.add({
9011
- item: props.item[props.panelOptions.titleKey] || ""
9012
- });
9013
- }
9014
- if (!props.panelOptions.idKey) {
9015
- return;
9016
- }
9017
- trackingStore.trackEvent({
9018
- queryKey: props.panelOptions.queryKey,
9019
- data: {
9020
- itemId: id.value,
9021
- searchQuery: props.inputValue,
9022
- type: "itemClick",
9023
- analytics: {
9024
- type: "autocomplete_product_click",
9025
- label: (_a = title.value) != null ? _a : link.value,
9026
- items: [props.item]
9027
- }
9028
- }
8945
+ emit2("product-click", {
8946
+ item: props.item,
8947
+ eventType: "itemClick",
8948
+ event
9029
8949
  });
9030
- if (!link.value) {
9031
- return;
9032
- }
9033
- emit2("product-click");
9034
- handleRoutingEvent(link.value, event, boxRoutingBehavior.value === "event");
9035
8950
  };
9036
8951
  onMounted(() => {
9037
8952
  checkIfIsInStock();
@@ -9084,6 +8999,61 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9084
8999
  };
9085
9000
  }
9086
9001
  });
9002
+ const getSearchTrackingData = (searchText, type) => {
9003
+ return {
9004
+ searchQuery: searchText,
9005
+ analytics: {
9006
+ type,
9007
+ label: searchText
9008
+ }
9009
+ };
9010
+ };
9011
+ const useTrackingStore = defineStore("tracking", () => {
9012
+ const optionsStore = useOptionsStore();
9013
+ const trackSearch = ({
9014
+ queryKey,
9015
+ query,
9016
+ type = "search_query"
9017
+ }) => {
9018
+ var _a, _b;
9019
+ const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
9020
+ const hasFilters = Object.keys((_b = query.filters) != null ? _b : {}).length > 0;
9021
+ if (hasFilters) {
9022
+ const data2 = getSearchTrackingData(query.searchText, "search_filters");
9023
+ track(queryKey, data2, options);
9024
+ return;
9025
+ }
9026
+ const data = getSearchTrackingData(query.searchText, type);
9027
+ track(queryKey, data, options);
9028
+ };
9029
+ const trackResults = ({
9030
+ queryKey,
9031
+ results
9032
+ }) => {
9033
+ var _a;
9034
+ const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
9035
+ if (results.total > 0) {
9036
+ return;
9037
+ }
9038
+ const data = getSearchTrackingData(results.searchText, "search_zero_results");
9039
+ track(queryKey, data, options);
9040
+ };
9041
+ const trackEvent = ({ queryKey, data }) => {
9042
+ var _a, _b, _c, _d, _e;
9043
+ const options = (_a = optionsStore.envOptions) != null ? _a : { environment: "production" };
9044
+ const trackingOptions = (_b = optionsStore.trackingOptions) != null ? _b : {};
9045
+ const items = (_d = (_c = data.analytics) == null ? void 0 : _c.items) != null ? _d : [];
9046
+ const mappedItems = ((_e = trackingOptions.analytics) == null ? void 0 : _e.itemMap) ? items.map(trackingOptions.analytics.itemMap) : items;
9047
+ track(
9048
+ queryKey,
9049
+ __spreadProps2(__spreadValues2({}, data), {
9050
+ analytics: data.analytics ? __spreadProps2(__spreadValues2({}, data.analytics), { items: mappedItems }) : void 0
9051
+ }),
9052
+ options
9053
+ );
9054
+ };
9055
+ return { trackSearch, trackResults, trackEvent };
9056
+ });
9087
9057
  const _hoisted_1$Z = { id: "lupa-search-box-products" };
9088
9058
  const _sfc_main$11 = /* @__PURE__ */ defineComponent({
9089
9059
  __name: "SearchBoxProducts",
@@ -9093,9 +9063,14 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9093
9063
  panelOptions: {},
9094
9064
  labels: {}
9095
9065
  },
9096
- setup(__props) {
9066
+ emits: ["product-click"],
9067
+ setup(__props, { emit: emit2 }) {
9097
9068
  const props = __props;
9098
9069
  const searchBoxStore = useSearchBoxStore();
9070
+ const historyStore = useHistoryStore();
9071
+ const trackingStore = useTrackingStore();
9072
+ const optionsStore = useOptionsStore();
9073
+ const { boxRoutingBehavior } = storeToRefs(optionsStore);
9099
9074
  const { highlightedItem } = storeToRefs(searchBoxStore);
9100
9075
  const highlightedIndex = computed(() => {
9101
9076
  var _a, _b, _c;
@@ -9104,6 +9079,42 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9104
9079
  }
9105
9080
  return (_c = (_b = highlightedItem.value) == null ? void 0 : _b.index) != null ? _c : -1;
9106
9081
  });
9082
+ const handleProductClick = ({
9083
+ item,
9084
+ eventType,
9085
+ event
9086
+ }) => {
9087
+ var _a, _b;
9088
+ const link = generateLink((_b = (_a = props.panelOptions.links) == null ? void 0 : _a.details) != null ? _b : "", item);
9089
+ const title = props.panelOptions.titleKey ? item[props.panelOptions.titleKey] || "" : "";
9090
+ const id = props.panelOptions.idKey ? item[props.panelOptions.idKey] : "";
9091
+ if (props.panelOptions.titleKey) {
9092
+ historyStore.add({
9093
+ item: item[props.panelOptions.titleKey] || ""
9094
+ });
9095
+ }
9096
+ if (!props.panelOptions.idKey) {
9097
+ return;
9098
+ }
9099
+ trackingStore.trackEvent({
9100
+ queryKey: props.panelOptions.queryKey,
9101
+ data: {
9102
+ itemId: id,
9103
+ searchQuery: props.inputValue,
9104
+ type: eventType || "itemClick",
9105
+ analytics: {
9106
+ type: "autocomplete_product_click",
9107
+ label: title != null ? title : link,
9108
+ items: [item]
9109
+ }
9110
+ }
9111
+ });
9112
+ if (!link) {
9113
+ return;
9114
+ }
9115
+ emit2("product-click");
9116
+ handleRoutingEvent(link, event, boxRoutingBehavior.value === "event");
9117
+ };
9107
9118
  return (_ctx, _cache) => {
9108
9119
  return openBlock(), createElementBlock("div", _hoisted_1$Z, [
9109
9120
  _ctx.$slots.productCard ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(_ctx.items, (item, index) => {
@@ -9114,7 +9125,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9114
9125
  labels: _ctx.labels,
9115
9126
  highlighted: index === highlightedIndex.value,
9116
9127
  inputValue: _ctx.inputValue,
9117
- onProductClick: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("product-click"))
9128
+ itemClicked: handleProductClick
9118
9129
  });
9119
9130
  }), 128)) : (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(_ctx.items, (item, index) => {
9120
9131
  return openBlock(), createBlock(_sfc_main$12, {
@@ -9124,7 +9135,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9124
9135
  labels: _ctx.labels,
9125
9136
  highlighted: index === highlightedIndex.value,
9126
9137
  inputValue: _ctx.inputValue,
9127
- onProductClick: _cache[1] || (_cache[1] = ($event) => _ctx.$emit("product-click"))
9138
+ onProductClick: handleProductClick
9128
9139
  }, null, 8, ["item", "panelOptions", "labels", "highlighted", "inputValue"]);
9129
9140
  }), 128))
9130
9141
  ]);
@@ -12460,6 +12471,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
12460
12471
  if (!value) {
12461
12472
  return;
12462
12473
  }
12474
+ paramStore.setSortSettings({ selectedSortKey: value, previousSortKey: previousKey.value });
12463
12475
  (_c = (_b = props.callbacks) == null ? void 0 : _b.onSortChange) == null ? void 0 : _c.call(_b, { selectedSortKey: value, previousSortKey: previousKey.value });
12464
12476
  paramStore.appendParams({
12465
12477
  params: [{ name: QUERY_PARAMS$1.SORT, value }],
@@ -14166,7 +14178,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
14166
14178
  return (_a = props.initialFilters) != null ? _a : {};
14167
14179
  });
14168
14180
  const { currentQueryText, hasResults, currentFilterCount } = storeToRefs(searchResultStore);
14169
- const { searchString } = storeToRefs(paramStore);
14181
+ const { searchString, sortParams } = storeToRefs(paramStore);
14170
14182
  const { defaultSearchResultPageSize } = storeToRefs(optionStore);
14171
14183
  const searchResultsFilters = ref(null);
14172
14184
  const mounted = ref(false);
@@ -14203,6 +14215,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
14203
14215
  window.removeEventListener("popstate", handlePopState);
14204
14216
  });
14205
14217
  const trackItemListView = (title, items = []) => {
14218
+ var _a, _b;
14206
14219
  trackingStore.trackEvent({
14207
14220
  queryKey: props.options.queryKey,
14208
14221
  data: {
@@ -14210,7 +14223,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
14210
14223
  type: "view_item_list",
14211
14224
  label: title,
14212
14225
  listLabel: title,
14213
- items
14226
+ items,
14227
+ additionalParams: {
14228
+ previousSortKey: (_a = sortParams.value) == null ? void 0 : _a.previousSortKey,
14229
+ newSortKey: (_b = sortParams.value) == null ? void 0 : _b.selectedSortKey
14230
+ }
14214
14231
  },
14215
14232
  options: { allowEmptySearchQuery: true }
14216
14233
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getlupa/client",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "main": "dist/lupaSearch.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/src/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "devDependencies": {
22
22
  "@getlupa/client-sdk": "^1.3.4",
23
- "@getlupa/vue": "0.7.3",
23
+ "@getlupa/vue": "0.7.4",
24
24
  "@rushstack/eslint-patch": "^1.3.2",
25
25
  "@tsconfig/node18": "^2.0.1",
26
26
  "@types/jsdom": "^21.1.1",