@findlane/browser 0.20.0 → 0.21.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.
package/dist/index.d.ts CHANGED
@@ -295,6 +295,12 @@ export type BrowserEvents = {
295
295
  position?: number;
296
296
  kind?: "typed" | "popular" | "recent";
297
297
  }): void;
298
+ /** A rule's banner was clicked: its rule (each banner in a response says which), the search's query, and
299
+ * its place. The Merchandising page shows each banner's clicks beside how often it was shown. */
300
+ bannerClick(rule: string, details?: {
301
+ query?: string;
302
+ position?: number;
303
+ }): void;
298
304
  addToCart(items: EventItem[], options?: {
299
305
  currency?: string;
300
306
  }): void;
package/dist/index.js CHANGED
@@ -137,6 +137,7 @@ function eventSender(url, fetcher, mode, ids) {
137
137
  },
138
138
  click: (objectID, details) => add({ type: "click", objectID, ...details }),
139
139
  suggestion: (query, details) => add({ type: "suggestion", query, ...details }),
140
+ bannerClick: (rule, details) => add({ type: "bannerClick", rule, ...details }),
140
141
  addToCart: (items, options) => add({ type: "addToCart", items, ...options }),
141
142
  purchase: (order) => add({ type: "purchase", ...order }),
142
143
  consent(granted) {
@@ -73,7 +73,7 @@ export declare function DefaultBanner({ banner }: {
73
73
  banner: Banner;
74
74
  }): import("react").JSX.Element;
75
75
  /** The results. Following a link in a hit sends a click event, with its place and the query. Rules'
76
- * banners show at their places among the first page's hits. */
76
+ * banners show at their places among the first page's hits, and following a banner's link sends a banner click. */
77
77
  export declare function Hits<T = Record<string, unknown>>({ render, renderBanner, empty, relatedTitle, loading, className }: HitsProps<T>): import("react").JSX.Element;
78
78
  export type RefinementListProps = {
79
79
  field: string;
@@ -79,9 +79,9 @@ export function DefaultBanner({ banner }) {
79
79
  return banner.link ? _jsx("a", { href: banner.link, children: content }) : content;
80
80
  }
81
81
  /** The results. Following a link in a hit sends a click event, with its place and the query. Rules'
82
- * banners show at their places among the first page's hits. */
82
+ * banners show at their places among the first page's hits, and following a banner's link sends a banner click. */
83
83
  export function Hits({ render, renderBanner, empty, relatedTitle, loading = null, className }) {
84
- const { hits, related, isLoaded, isPending, error, click, response, request } = useHits();
84
+ const { hits, related, isLoaded, isPending, error, click, bannerClick, response, request } = useHits();
85
85
  const { query } = useSearchBox();
86
86
  if (error && !isLoaded)
87
87
  return _jsx("p", { "data-findlane-note": "", children: messageFor(error) });
@@ -94,7 +94,13 @@ export function Hits({ render, renderBanner, empty, relatedTitle, loading = null
94
94
  // Banners go before the hit at their place, on the first page; past the last hit, after it.
95
95
  const banners = hits.length && !request?.offset ? response?.banners ?? [] : [];
96
96
  const bannerAt = (place) => banners.filter((banner) => Math.min(Math.max(banner.position ?? 1, 1), shown.length) === place);
97
- const bannerItems = (place) => bannerAt(place).map((banner, at) => (_jsx("li", { "data-findlane-banner": "", children: renderBanner ? renderBanner(banner) : _jsx(DefaultBanner, { banner: banner }) }, `banner-${banner.rule}-${at}`)));
97
+ // Following a banner's link sends a banner click, as a hit's sends a click.
98
+ const bannerItems = (place) => bannerAt(place).map((banner, at) => {
99
+ const clicked = (event) => { if (!event.defaultPrevented && onLink(event))
100
+ bannerClick(banner); };
101
+ return (_jsx("li", { "data-findlane-banner": "", onClick: clicked, onAuxClick: (event) => { if (event.button === 1)
102
+ clicked(event); }, children: renderBanner ? renderBanner(banner) : _jsx(DefaultBanner, { banner: banner }) }, `banner-${banner.rule}-${at}`));
103
+ });
98
104
  const list = (_jsx("ol", { className: className, "data-findlane-hits": "", "data-findlane-related": !hits.length || undefined, "data-pending": isPending || undefined, children: shown.map((hit, index) => {
99
105
  // A click, and a middle click that opens the link in a new tab.
100
106
  const clicked = (event) => { if (!event.defaultPrevented && onLink(event))
@@ -54,6 +54,11 @@ export declare function useHits<T = Record<string, unknown>>(): {
54
54
  click: (hit: {
55
55
  id: string;
56
56
  }) => void;
57
+ /** Sends a click on a rule's banner. Hits does it for links in a banner; call it from your own banner. */
58
+ bannerClick: (banner: {
59
+ rule: string;
60
+ position?: number;
61
+ }) => void;
57
62
  };
58
63
  /** Did you mean, with the index's didYouMean setting: the query the results are for when typo tolerance
59
64
  * corrected some words (`applied`, "Showing results for"), or, when nothing matched, a query that
@@ -99,6 +99,8 @@ export function useHits() {
99
99
  /** Sends a click event for a hit, with its place and the query, for click-through in Analytics.
100
100
  * Hits does it for links in a hit; call it from a hit rendered without a link. */
101
101
  click: (hit) => store.click(hit.id),
102
+ /** Sends a click on a rule's banner. Hits does it for links in a banner; call it from your own banner. */
103
+ bannerClick: (banner) => store.bannerClick(banner),
102
104
  };
103
105
  }
104
106
  /** Did you mean, with the index's didYouMean setting: the query the results are for when typo tolerance
@@ -65,6 +65,11 @@ export declare class SearchStore<T = unknown> {
65
65
  /** Sends a click on a result: its place in the results, from 1, and the query they're for. A related
66
66
  * result's click says so (list "related"), with its place among them. */
67
67
  click(objectID: string): void;
68
+ /** Sends a click on a rule's banner, with the query it showed for. */
69
+ bannerClick(banner: {
70
+ rule: string;
71
+ position?: number;
72
+ }): void;
68
73
  /** Searches unless the results already answer the current state; with a state, such as the
69
74
  * URL's, adopts it first. */
70
75
  start(state?: SearchState): void;
@@ -77,6 +77,11 @@ export class SearchStore {
77
77
  ...(index >= 0 ? { position: (results.request.offset ?? 0) + index + 1 } : {}),
78
78
  ...(related >= 0 ? { position: related + 1, list: "related" } : {}) });
79
79
  }
80
+ /** Sends a click on a rule's banner, with the query it showed for. */
81
+ bannerClick(banner) {
82
+ this.client.events.bannerClick(banner.rule, { query: this.snapshot.results?.request.q ?? "",
83
+ ...(banner.position ? { position: banner.position } : {}) });
84
+ }
80
85
  /** Searches unless the results already answer the current state; with a state, such as the
81
86
  * URL's, adopts it first. */
82
87
  start(state) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@findlane/browser",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "Findlane browser SDK: fast, typo-tolerant public search from the browser with an index's public ID, plus React hooks and components.",
5
5
  "keywords": ["findlane", "search", "full-text search", "typo tolerance", "instant search", "ecommerce search", "browser", "react", "autocomplete"],
6
6
  "license": "MIT",