@magicx-eng/ai-autocomplete-react 0.63.1 → 0.65.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/README.md CHANGED
@@ -638,7 +638,7 @@ correlate a user's report with the query that produced it.
638
638
 
639
639
  ### Visitor id and submits
640
640
 
641
- Pass `visitorId` to tie searches to what the same visitor does later: a UUID v4 you keep across page loads (for example a first-party cookie), or a function that returns one. A function is called only when the id is needed, so it is safe to create the id lazily inside it.
641
+ Pass `visitorId` to tie searches to what the same visitor does later: a UUID v4 you keep across page loads, or a function that returns one, called only when the id is needed. Or pass `analyticsConsent` and let the SDK keep one: see [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-react/REFERENCE.md).
642
642
 
643
643
  Submits from Enter and from Tier 1's built-in button are recorded for you. If you render your own submit button (Tier 2 or 3), call `recordSubmit(result)` from it, once per submit, with the result you pass to your own submit handler.
644
644
 
package/REFERENCE.md CHANGED
@@ -9,6 +9,8 @@ Longer guides that do not fit in the [README](https://unpkg.com/@magicx-eng/ai-a
9
9
  - [Multiple selections](#multiple-selections)
10
10
  - [Location search](#location-search)
11
11
  - [CSS variables](#css-variables)
12
+ - [Visitor id kept by the SDK](#visitor-id-kept-by-the-sdk)
13
+ - [Search id](#search-id)
12
14
 
13
15
  ## Product strip
14
16
 
@@ -721,3 +723,34 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
721
723
  | `--aia-chip-remove-opacity-hover` | `0.7` | `0.7` | Opacity of that × under a hovering pointer (never on touch). |
722
724
 
723
725
  Legacy `--aia-color-*` variables are still supported as fallbacks.
726
+
727
+ ## Visitor id kept by the SDK
728
+
729
+ Without `visitorId`, the SDK can keep the id for you. Pass `analyticsConsent` so it knows the visitor's choice: `true` (allowed), `false` (declined), or `undefined` (not answered yet). Once allowed, it keeps a UUID v4 in the first-party cookie `aia_vid` for a year, renewed on use; declined, it removes that cookie. This needs the feature to be enabled for your account, and nothing is stored without `analyticsConsent`.
730
+
731
+ ```tsx
732
+ // Cookiebot, as an example. Return undefined until the visitor answers.
733
+ <AIAutocomplete
734
+ analyticsConsent={() =>
735
+ window.Cookiebot?.hasResponse ? window.Cookiebot.consent.statistics : undefined
736
+ }
737
+ />
738
+ ```
739
+
740
+ Apply a changed choice at once with the handle's `refreshAnalyticsConsent()` (or the hook's), rather than at the next event. `getVisitorId()` on the handle or the hook returns the id the events carry, so you can send it with your own events. It is `undefined` before the first response and whenever there is no id.
741
+
742
+ ## Search id
743
+
744
+ Each search gets its own id, so what happens after it (a results page, a cart, an order) can be tied to the exact search. The SDK makes it: a new one starts with the widget, on `reset()`, and with the shopper's next input after a submit or a product pick. It rides on the SDK's own requests and events once the feature is enabled for your account; until then `getSearchId()` returns `undefined`.
745
+
746
+ Read it where the search is handed off, before the shopper types again:
747
+
748
+ ```ts
749
+ // The Tier 1 handle (ref) and the hook both have getSearchId().
750
+ onSubmit: (result) => {
751
+ const searchId = handle.getSearchId();
752
+ // Carry it to your results page, and send it with the events that follow.
753
+ },
754
+ ```
755
+
756
+ The id of the last search the current tab handed off (a submit or a product pick) is also kept in `sessionStorage` under `aia:last-search`, as `{ id, at }`, where `at` is when it was handed off, in milliseconds since the epoch.
package/dist/index.d.mts CHANGED
@@ -27,6 +27,12 @@ interface AIAutocompleteHandle {
27
27
  * still on the page (a quick view opened, inline results drawn).
28
28
  */
29
29
  endSubmitProgress: () => void;
30
+ /** The search in progress, or `undefined` until the feature is enabled for your account. Read it in your submit or product handler. */
31
+ getSearchId: () => string | undefined;
32
+ /** The visitor id the events carry right now, or `undefined` while there is none. */
33
+ getVisitorId: () => string | undefined;
34
+ /** Reads `analyticsConsent` again now, after the visitor changes their choice. */
35
+ refreshAnalyticsConsent: () => void;
30
36
  }
31
37
  interface AIAutocompleteProps {
32
38
  /**
@@ -83,6 +89,17 @@ interface AIAutocompleteProps {
83
89
  * only once the server has funnel telemetry on.
84
90
  */
85
91
  visitorId?: string | (() => string | undefined);
92
+ /**
93
+ * Whether the visitor allowed analytics: `true`, `false`, or a function
94
+ * returning either, or `undefined` while they have not answered. Once
95
+ * allowed, and while the feature is enabled for your account, a site that
96
+ * passes no `visitorId` gets one kept in the first-party cookie `aia_vid`
97
+ * (a UUID v4, one year, renewed on use). Declined, that cookie is removed.
98
+ * Omit it and the SDK never touches the cookie. Ignored when `visitorId` is
99
+ * passed. A changed boolean applies at once; after a function's answer
100
+ * changes, call `refreshAnalyticsConsent()`.
101
+ */
102
+ analyticsConsent?: boolean | (() => boolean | undefined);
86
103
  columns?: number;
87
104
  /** Where to render unfilled pills. "dropdown" (default) renders them above the options grid; "inline" renders them in the input. */
88
105
  pillPlacement?: "inline" | "dropdown" | "hidden";
@@ -315,6 +332,17 @@ interface UseAIAutocompleteOptions {
315
332
  * only once the server has funnel telemetry on.
316
333
  */
317
334
  visitorId?: string | (() => string | undefined);
335
+ /**
336
+ * Whether the visitor allowed analytics: `true`, `false`, or a function
337
+ * returning either, or `undefined` while they have not answered. Once
338
+ * allowed, and while the feature is enabled for your account, a site that
339
+ * passes no `visitorId` gets one kept in the first-party cookie `aia_vid`
340
+ * (a UUID v4, one year, renewed on use). Declined, that cookie is removed.
341
+ * Omit it and the SDK never touches the cookie. Ignored when `visitorId` is
342
+ * passed. A changed boolean applies at once; after a function's answer
343
+ * changes, call `refreshAnalyticsConsent()`.
344
+ */
345
+ analyticsConsent?: boolean | (() => boolean | undefined);
318
346
  columns?: number;
319
347
  /**
320
348
  * SDK surface identifier — sent as meta.source on both /api/suggest and
@@ -540,6 +568,12 @@ interface UseAIAutocompleteReturn {
540
568
  * still on the page (a quick view opened, inline results drawn).
541
569
  */
542
570
  endSubmitProgress: () => void;
571
+ /** The search in progress, or `undefined` until the feature is enabled for your account. Read it in your submit or product handler. */
572
+ getSearchId: () => string | undefined;
573
+ /** The visitor id the events carry right now, or `undefined` while there is none. */
574
+ getVisitorId: () => string | undefined;
575
+ /** Reads `analyticsConsent` again now, after the visitor changes their choice. */
576
+ refreshAnalyticsConsent: () => void;
543
577
  /**
544
578
  * A submit is in progress: `onSubmit` ran and the page it opens has not
545
579
  * taken over yet. Enter is ignored meanwhile; skip your own button's submit
@@ -864,6 +898,6 @@ declare const AIAutocomplete: react.ForwardRefExoticComponent<AIAutocompleteProp
864
898
 
865
899
  declare function AIAutocompleteDropdown({ suggestions, activeIndex, onSelect, onHighlight, onUnhighlight, isOpen, id, className, pills, onPillClick, showPills, onSkip, showSkipButton, showOptionIcons, showOptionImages, showOptionCounts, skipDisabled, activeSelected, isLoading, skeletonExiting, isInputEmpty, language, products, onProductSelect, onProductAddToCart, onProductFocusChange, productsLayout, productImageFallback, showProductVendor, formatType, dateView, selectedDateIso, selectedDateRange, dateRangeStart, dateReferences, onPreviousMonth, onNextMonth, timeView, multiSelectView, onMultiSelectCommit, onSeeAllResults, seeAllBusy, busyProductId, fullWidth, onTimeChange, onTimeCommit, locationView, isReediting, onLocationQuery, onLocationMove, onLocationCommit, onLocationFocusChange, isFocused, optionsPosition, mode, }: AIAutocompleteDropdownProps): react_jsx_runtime.JSX.Element;
866
900
 
867
- declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, columns, dropdownTrigger, optionsPosition, closeDropdownOnBlur, prependPlaceholder, allOption, showNonTappableOptions, locationSearch, showOptionIcons, showOptionImages, showOptionCounts, showSkipButton, showProducts, submitProgress, productImageFallback, showProductVendor, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
901
+ declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, analyticsConsent, columns, dropdownTrigger, optionsPosition, closeDropdownOnBlur, prependPlaceholder, allOption, showNonTappableOptions, locationSearch, showOptionIcons, showOptionImages, showOptionCounts, showSkipButton, showProducts, submitProgress, productImageFallback, showProductVendor, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
868
902
 
869
903
  export { AIAutocomplete, AIAutocompleteDropdown, type AIAutocompleteDropdownProps, type AIAutocompleteHandle, type AIAutocompleteProps, type UseAIAutocompleteOptions, type UseAIAutocompleteReturn, useAIAutocomplete };
package/dist/index.d.ts CHANGED
@@ -27,6 +27,12 @@ interface AIAutocompleteHandle {
27
27
  * still on the page (a quick view opened, inline results drawn).
28
28
  */
29
29
  endSubmitProgress: () => void;
30
+ /** The search in progress, or `undefined` until the feature is enabled for your account. Read it in your submit or product handler. */
31
+ getSearchId: () => string | undefined;
32
+ /** The visitor id the events carry right now, or `undefined` while there is none. */
33
+ getVisitorId: () => string | undefined;
34
+ /** Reads `analyticsConsent` again now, after the visitor changes their choice. */
35
+ refreshAnalyticsConsent: () => void;
30
36
  }
31
37
  interface AIAutocompleteProps {
32
38
  /**
@@ -83,6 +89,17 @@ interface AIAutocompleteProps {
83
89
  * only once the server has funnel telemetry on.
84
90
  */
85
91
  visitorId?: string | (() => string | undefined);
92
+ /**
93
+ * Whether the visitor allowed analytics: `true`, `false`, or a function
94
+ * returning either, or `undefined` while they have not answered. Once
95
+ * allowed, and while the feature is enabled for your account, a site that
96
+ * passes no `visitorId` gets one kept in the first-party cookie `aia_vid`
97
+ * (a UUID v4, one year, renewed on use). Declined, that cookie is removed.
98
+ * Omit it and the SDK never touches the cookie. Ignored when `visitorId` is
99
+ * passed. A changed boolean applies at once; after a function's answer
100
+ * changes, call `refreshAnalyticsConsent()`.
101
+ */
102
+ analyticsConsent?: boolean | (() => boolean | undefined);
86
103
  columns?: number;
87
104
  /** Where to render unfilled pills. "dropdown" (default) renders them above the options grid; "inline" renders them in the input. */
88
105
  pillPlacement?: "inline" | "dropdown" | "hidden";
@@ -315,6 +332,17 @@ interface UseAIAutocompleteOptions {
315
332
  * only once the server has funnel telemetry on.
316
333
  */
317
334
  visitorId?: string | (() => string | undefined);
335
+ /**
336
+ * Whether the visitor allowed analytics: `true`, `false`, or a function
337
+ * returning either, or `undefined` while they have not answered. Once
338
+ * allowed, and while the feature is enabled for your account, a site that
339
+ * passes no `visitorId` gets one kept in the first-party cookie `aia_vid`
340
+ * (a UUID v4, one year, renewed on use). Declined, that cookie is removed.
341
+ * Omit it and the SDK never touches the cookie. Ignored when `visitorId` is
342
+ * passed. A changed boolean applies at once; after a function's answer
343
+ * changes, call `refreshAnalyticsConsent()`.
344
+ */
345
+ analyticsConsent?: boolean | (() => boolean | undefined);
318
346
  columns?: number;
319
347
  /**
320
348
  * SDK surface identifier — sent as meta.source on both /api/suggest and
@@ -540,6 +568,12 @@ interface UseAIAutocompleteReturn {
540
568
  * still on the page (a quick view opened, inline results drawn).
541
569
  */
542
570
  endSubmitProgress: () => void;
571
+ /** The search in progress, or `undefined` until the feature is enabled for your account. Read it in your submit or product handler. */
572
+ getSearchId: () => string | undefined;
573
+ /** The visitor id the events carry right now, or `undefined` while there is none. */
574
+ getVisitorId: () => string | undefined;
575
+ /** Reads `analyticsConsent` again now, after the visitor changes their choice. */
576
+ refreshAnalyticsConsent: () => void;
543
577
  /**
544
578
  * A submit is in progress: `onSubmit` ran and the page it opens has not
545
579
  * taken over yet. Enter is ignored meanwhile; skip your own button's submit
@@ -864,6 +898,6 @@ declare const AIAutocomplete: react.ForwardRefExoticComponent<AIAutocompleteProp
864
898
 
865
899
  declare function AIAutocompleteDropdown({ suggestions, activeIndex, onSelect, onHighlight, onUnhighlight, isOpen, id, className, pills, onPillClick, showPills, onSkip, showSkipButton, showOptionIcons, showOptionImages, showOptionCounts, skipDisabled, activeSelected, isLoading, skeletonExiting, isInputEmpty, language, products, onProductSelect, onProductAddToCart, onProductFocusChange, productsLayout, productImageFallback, showProductVendor, formatType, dateView, selectedDateIso, selectedDateRange, dateRangeStart, dateReferences, onPreviousMonth, onNextMonth, timeView, multiSelectView, onMultiSelectCommit, onSeeAllResults, seeAllBusy, busyProductId, fullWidth, onTimeChange, onTimeCommit, locationView, isReediting, onLocationQuery, onLocationMove, onLocationCommit, onLocationFocusChange, isFocused, optionsPosition, mode, }: AIAutocompleteDropdownProps): react_jsx_runtime.JSX.Element;
866
900
 
867
- declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, columns, dropdownTrigger, optionsPosition, closeDropdownOnBlur, prependPlaceholder, allOption, showNonTappableOptions, locationSearch, showOptionIcons, showOptionImages, showOptionCounts, showSkipButton, showProducts, submitProgress, productImageFallback, showProductVendor, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
901
+ declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, analyticsConsent, columns, dropdownTrigger, optionsPosition, closeDropdownOnBlur, prependPlaceholder, allOption, showNonTappableOptions, locationSearch, showOptionIcons, showOptionImages, showOptionCounts, showSkipButton, showProducts, submitProgress, productImageFallback, showProductVendor, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
868
902
 
869
903
  export { AIAutocomplete, AIAutocompleteDropdown, type AIAutocompleteDropdownProps, type AIAutocompleteHandle, type AIAutocompleteProps, type UseAIAutocompleteOptions, type UseAIAutocompleteReturn, useAIAutocomplete };