@magicx-eng/ai-autocomplete-react 0.63.1 → 0.64.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,7 @@ 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)
12
13
 
13
14
  ## Product strip
14
15
 
@@ -721,3 +722,18 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
721
722
  | `--aia-chip-remove-opacity-hover` | `0.7` | `0.7` | Opacity of that × under a hovering pointer (never on touch). |
722
723
 
723
724
  Legacy `--aia-color-*` variables are still supported as fallbacks.
725
+
726
+ ## Visitor id kept by the SDK
727
+
728
+ 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`.
729
+
730
+ ```tsx
731
+ // Cookiebot, as an example. Return undefined until the visitor answers.
732
+ <AIAutocomplete
733
+ analyticsConsent={() =>
734
+ window.Cookiebot?.hasResponse ? window.Cookiebot.consent.statistics : undefined
735
+ }
736
+ />
737
+ ```
738
+
739
+ 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.
package/dist/index.d.mts CHANGED
@@ -27,6 +27,10 @@ interface AIAutocompleteHandle {
27
27
  * still on the page (a quick view opened, inline results drawn).
28
28
  */
29
29
  endSubmitProgress: () => void;
30
+ /** The visitor id the events carry right now, or `undefined` while there is none. */
31
+ getVisitorId: () => string | undefined;
32
+ /** Reads `analyticsConsent` again now, after the visitor changes their choice. */
33
+ refreshAnalyticsConsent: () => void;
30
34
  }
31
35
  interface AIAutocompleteProps {
32
36
  /**
@@ -83,6 +87,17 @@ interface AIAutocompleteProps {
83
87
  * only once the server has funnel telemetry on.
84
88
  */
85
89
  visitorId?: string | (() => string | undefined);
90
+ /**
91
+ * Whether the visitor allowed analytics: `true`, `false`, or a function
92
+ * returning either, or `undefined` while they have not answered. Once
93
+ * allowed, and while the feature is enabled for your account, a site that
94
+ * passes no `visitorId` gets one kept in the first-party cookie `aia_vid`
95
+ * (a UUID v4, one year, renewed on use). Declined, that cookie is removed.
96
+ * Omit it and the SDK never touches the cookie. Ignored when `visitorId` is
97
+ * passed. A changed boolean applies at once; after a function's answer
98
+ * changes, call `refreshAnalyticsConsent()`.
99
+ */
100
+ analyticsConsent?: boolean | (() => boolean | undefined);
86
101
  columns?: number;
87
102
  /** Where to render unfilled pills. "dropdown" (default) renders them above the options grid; "inline" renders them in the input. */
88
103
  pillPlacement?: "inline" | "dropdown" | "hidden";
@@ -315,6 +330,17 @@ interface UseAIAutocompleteOptions {
315
330
  * only once the server has funnel telemetry on.
316
331
  */
317
332
  visitorId?: string | (() => string | undefined);
333
+ /**
334
+ * Whether the visitor allowed analytics: `true`, `false`, or a function
335
+ * returning either, or `undefined` while they have not answered. Once
336
+ * allowed, and while the feature is enabled for your account, a site that
337
+ * passes no `visitorId` gets one kept in the first-party cookie `aia_vid`
338
+ * (a UUID v4, one year, renewed on use). Declined, that cookie is removed.
339
+ * Omit it and the SDK never touches the cookie. Ignored when `visitorId` is
340
+ * passed. A changed boolean applies at once; after a function's answer
341
+ * changes, call `refreshAnalyticsConsent()`.
342
+ */
343
+ analyticsConsent?: boolean | (() => boolean | undefined);
318
344
  columns?: number;
319
345
  /**
320
346
  * SDK surface identifier — sent as meta.source on both /api/suggest and
@@ -540,6 +566,10 @@ interface UseAIAutocompleteReturn {
540
566
  * still on the page (a quick view opened, inline results drawn).
541
567
  */
542
568
  endSubmitProgress: () => void;
569
+ /** The visitor id the events carry right now, or `undefined` while there is none. */
570
+ getVisitorId: () => string | undefined;
571
+ /** Reads `analyticsConsent` again now, after the visitor changes their choice. */
572
+ refreshAnalyticsConsent: () => void;
543
573
  /**
544
574
  * A submit is in progress: `onSubmit` ran and the page it opens has not
545
575
  * taken over yet. Enter is ignored meanwhile; skip your own button's submit
@@ -864,6 +894,6 @@ declare const AIAutocomplete: react.ForwardRefExoticComponent<AIAutocompleteProp
864
894
 
865
895
  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
896
 
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;
897
+ 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
898
 
869
899
  export { AIAutocomplete, AIAutocompleteDropdown, type AIAutocompleteDropdownProps, type AIAutocompleteHandle, type AIAutocompleteProps, type UseAIAutocompleteOptions, type UseAIAutocompleteReturn, useAIAutocomplete };
package/dist/index.d.ts CHANGED
@@ -27,6 +27,10 @@ interface AIAutocompleteHandle {
27
27
  * still on the page (a quick view opened, inline results drawn).
28
28
  */
29
29
  endSubmitProgress: () => void;
30
+ /** The visitor id the events carry right now, or `undefined` while there is none. */
31
+ getVisitorId: () => string | undefined;
32
+ /** Reads `analyticsConsent` again now, after the visitor changes their choice. */
33
+ refreshAnalyticsConsent: () => void;
30
34
  }
31
35
  interface AIAutocompleteProps {
32
36
  /**
@@ -83,6 +87,17 @@ interface AIAutocompleteProps {
83
87
  * only once the server has funnel telemetry on.
84
88
  */
85
89
  visitorId?: string | (() => string | undefined);
90
+ /**
91
+ * Whether the visitor allowed analytics: `true`, `false`, or a function
92
+ * returning either, or `undefined` while they have not answered. Once
93
+ * allowed, and while the feature is enabled for your account, a site that
94
+ * passes no `visitorId` gets one kept in the first-party cookie `aia_vid`
95
+ * (a UUID v4, one year, renewed on use). Declined, that cookie is removed.
96
+ * Omit it and the SDK never touches the cookie. Ignored when `visitorId` is
97
+ * passed. A changed boolean applies at once; after a function's answer
98
+ * changes, call `refreshAnalyticsConsent()`.
99
+ */
100
+ analyticsConsent?: boolean | (() => boolean | undefined);
86
101
  columns?: number;
87
102
  /** Where to render unfilled pills. "dropdown" (default) renders them above the options grid; "inline" renders them in the input. */
88
103
  pillPlacement?: "inline" | "dropdown" | "hidden";
@@ -315,6 +330,17 @@ interface UseAIAutocompleteOptions {
315
330
  * only once the server has funnel telemetry on.
316
331
  */
317
332
  visitorId?: string | (() => string | undefined);
333
+ /**
334
+ * Whether the visitor allowed analytics: `true`, `false`, or a function
335
+ * returning either, or `undefined` while they have not answered. Once
336
+ * allowed, and while the feature is enabled for your account, a site that
337
+ * passes no `visitorId` gets one kept in the first-party cookie `aia_vid`
338
+ * (a UUID v4, one year, renewed on use). Declined, that cookie is removed.
339
+ * Omit it and the SDK never touches the cookie. Ignored when `visitorId` is
340
+ * passed. A changed boolean applies at once; after a function's answer
341
+ * changes, call `refreshAnalyticsConsent()`.
342
+ */
343
+ analyticsConsent?: boolean | (() => boolean | undefined);
318
344
  columns?: number;
319
345
  /**
320
346
  * SDK surface identifier — sent as meta.source on both /api/suggest and
@@ -540,6 +566,10 @@ interface UseAIAutocompleteReturn {
540
566
  * still on the page (a quick view opened, inline results drawn).
541
567
  */
542
568
  endSubmitProgress: () => void;
569
+ /** The visitor id the events carry right now, or `undefined` while there is none. */
570
+ getVisitorId: () => string | undefined;
571
+ /** Reads `analyticsConsent` again now, after the visitor changes their choice. */
572
+ refreshAnalyticsConsent: () => void;
543
573
  /**
544
574
  * A submit is in progress: `onSubmit` ran and the page it opens has not
545
575
  * taken over yet. Enter is ignored meanwhile; skip your own button's submit
@@ -864,6 +894,6 @@ declare const AIAutocomplete: react.ForwardRefExoticComponent<AIAutocompleteProp
864
894
 
865
895
  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
896
 
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;
897
+ 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
898
 
869
899
  export { AIAutocomplete, AIAutocompleteDropdown, type AIAutocompleteDropdownProps, type AIAutocompleteHandle, type AIAutocompleteProps, type UseAIAutocompleteOptions, type UseAIAutocompleteReturn, useAIAutocomplete };