@magicx-eng/ai-autocomplete-vanilla 0.77.0 → 0.78.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 +2 -0
- package/REFERENCE.md +21 -0
- package/dist/index.d.mts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -713,6 +713,8 @@ const ac = new AIAutocomplete(container, {
|
|
|
713
713
|
|
|
714
714
|
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.
|
|
715
715
|
|
|
716
|
+
Or pass `analyticsConsent` and let the SDK keep one: see [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-vanilla/REFERENCE.md).
|
|
717
|
+
|
|
716
718
|
Submits from Enter and from the built-in submit 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.
|
|
717
719
|
|
|
718
720
|
## Option Overrides
|
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
|
|
|
@@ -724,3 +725,23 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
|
|
|
724
725
|
| `--aia-skeleton-bg` | `rgba(189, 189, 189, 0.083)` | `#1a1b1d` | Fill color of the option and chip image tiles while their picture loads (unless `--aia-option-image-bg` / `--aia-chip-image-bg` are set). |
|
|
725
726
|
| `--aia-chip-remove-opacity` | `0.32` | `0.32` | Opacity of a chip's remove × (`showChipRemove`). The × is for a mouse or a tap and is hidden from assistive technology; from the keyboard, Backspace at the end of a chip removes it. |
|
|
726
727
|
| `--aia-chip-remove-opacity-hover` | `0.7` | `0.7` | Opacity of that × under a hovering pointer (never on touch). |
|
|
728
|
+
|
|
729
|
+
## Visitor id kept by the SDK
|
|
730
|
+
|
|
731
|
+
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`.
|
|
732
|
+
|
|
733
|
+
```ts
|
|
734
|
+
const ac = new AIAutocomplete(el, {
|
|
735
|
+
// Cookiebot, as an example. Return undefined until the visitor answers.
|
|
736
|
+
analyticsConsent: () => {
|
|
737
|
+
const cookiebot = window.Cookiebot;
|
|
738
|
+
return cookiebot?.hasResponse ? cookiebot.consent.statistics : undefined;
|
|
739
|
+
},
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
// Apply a changed choice at once, rather than at the next event.
|
|
743
|
+
window.addEventListener("CookiebotOnAccept", () => ac.refreshAnalyticsConsent());
|
|
744
|
+
window.addEventListener("CookiebotOnDecline", () => ac.refreshAnalyticsConsent());
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
`getVisitorId()` returns the id the instance's 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
|
@@ -264,6 +264,11 @@ interface AutocompleteResponse {
|
|
|
264
264
|
* shows. Absent means one for every response that changes it.
|
|
265
265
|
*/
|
|
266
266
|
visible_impression?: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Set when the SDK may keep its own visitor id for a site that passes no
|
|
269
|
+
* `visitorId` and reports analytics consent. Absent means off.
|
|
270
|
+
*/
|
|
271
|
+
sdk_visitor_id?: boolean;
|
|
267
272
|
/** The request's `schema_version`, echoed back. */
|
|
268
273
|
schema_version?: string;
|
|
269
274
|
};
|
|
@@ -1408,6 +1413,15 @@ interface CoreOptions {
|
|
|
1408
1413
|
* while it is off.
|
|
1409
1414
|
*/
|
|
1410
1415
|
visitorId?: string | (() => string | undefined);
|
|
1416
|
+
/**
|
|
1417
|
+
* Whether the visitor allowed analytics: `true`, `false`, or a function
|
|
1418
|
+
* returning either, or `undefined` while they have not answered. Once
|
|
1419
|
+
* allowed, and while the server has it on, a site that passes no `visitorId`
|
|
1420
|
+
* gets one kept for it in the first-party cookie `aia_vid` (a UUID v4, one
|
|
1421
|
+
* year, renewed on use). Declined, that cookie is removed. Omit it and the
|
|
1422
|
+
* SDK never touches the cookie. Ignored when `visitorId` is passed.
|
|
1423
|
+
*/
|
|
1424
|
+
analyticsConsent?: boolean | (() => boolean | undefined);
|
|
1411
1425
|
columns?: number;
|
|
1412
1426
|
/** Where pills render in "full" mode. Default: "dropdown". Ignored in "dropdown" mode (always in dropdown). */
|
|
1413
1427
|
pillPlacement?: "inline" | "dropdown" | "hidden";
|
|
@@ -1736,6 +1750,8 @@ declare class AIAutocomplete {
|
|
|
1736
1750
|
private lastImpressionKey;
|
|
1737
1751
|
/** The server's `visible_impression`: send an impression only while the dropdown is visible. */
|
|
1738
1752
|
private visibleImpression;
|
|
1753
|
+
/** The server's `sdk_visitor_id`: keep a visitor id for a host that passes none. */
|
|
1754
|
+
private sdkVisitorId;
|
|
1739
1755
|
private destroyed;
|
|
1740
1756
|
/** The location search in flight, so a newer phrase or destroy() can cancel it. */
|
|
1741
1757
|
private locationAbort;
|
|
@@ -1911,6 +1927,18 @@ declare class AIAutocomplete {
|
|
|
1911
1927
|
* own — a button you render — so each submit is counted once.
|
|
1912
1928
|
*/
|
|
1913
1929
|
recordSubmit(result: AutocompleteResult): void;
|
|
1930
|
+
/**
|
|
1931
|
+
* The visitor id this instance's events carry right now, to send with your
|
|
1932
|
+
* own events. Undefined while there is none: before the first response, or
|
|
1933
|
+
* without `visitorId` and without consent.
|
|
1934
|
+
*/
|
|
1935
|
+
getVisitorId(): string | undefined;
|
|
1936
|
+
/**
|
|
1937
|
+
* Reads `analyticsConsent` again now. Call it when the shopper changes their
|
|
1938
|
+
* choice, so a declined one removes the stored visitor id at once rather
|
|
1939
|
+
* than at the next event.
|
|
1940
|
+
*/
|
|
1941
|
+
refreshAnalyticsConsent(): void;
|
|
1914
1942
|
/**
|
|
1915
1943
|
* Ends whatever is in progress, a submit or a product selection, at once:
|
|
1916
1944
|
* call it when the work your handler started is done and the shopper is
|
|
@@ -2115,6 +2143,7 @@ declare class AIAutocomplete {
|
|
|
2115
2143
|
private applyOption;
|
|
2116
2144
|
private startSelectionAnimationTimer;
|
|
2117
2145
|
private resolveVisitorId;
|
|
2146
|
+
private resolveOwnVisitorId;
|
|
2118
2147
|
private resolveSource;
|
|
2119
2148
|
/**
|
|
2120
2149
|
* With `visible_impression`, the dropdown opening is itself an impression of
|
package/dist/index.d.ts
CHANGED
|
@@ -264,6 +264,11 @@ interface AutocompleteResponse {
|
|
|
264
264
|
* shows. Absent means one for every response that changes it.
|
|
265
265
|
*/
|
|
266
266
|
visible_impression?: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Set when the SDK may keep its own visitor id for a site that passes no
|
|
269
|
+
* `visitorId` and reports analytics consent. Absent means off.
|
|
270
|
+
*/
|
|
271
|
+
sdk_visitor_id?: boolean;
|
|
267
272
|
/** The request's `schema_version`, echoed back. */
|
|
268
273
|
schema_version?: string;
|
|
269
274
|
};
|
|
@@ -1408,6 +1413,15 @@ interface CoreOptions {
|
|
|
1408
1413
|
* while it is off.
|
|
1409
1414
|
*/
|
|
1410
1415
|
visitorId?: string | (() => string | undefined);
|
|
1416
|
+
/**
|
|
1417
|
+
* Whether the visitor allowed analytics: `true`, `false`, or a function
|
|
1418
|
+
* returning either, or `undefined` while they have not answered. Once
|
|
1419
|
+
* allowed, and while the server has it on, a site that passes no `visitorId`
|
|
1420
|
+
* gets one kept for it in the first-party cookie `aia_vid` (a UUID v4, one
|
|
1421
|
+
* year, renewed on use). Declined, that cookie is removed. Omit it and the
|
|
1422
|
+
* SDK never touches the cookie. Ignored when `visitorId` is passed.
|
|
1423
|
+
*/
|
|
1424
|
+
analyticsConsent?: boolean | (() => boolean | undefined);
|
|
1411
1425
|
columns?: number;
|
|
1412
1426
|
/** Where pills render in "full" mode. Default: "dropdown". Ignored in "dropdown" mode (always in dropdown). */
|
|
1413
1427
|
pillPlacement?: "inline" | "dropdown" | "hidden";
|
|
@@ -1736,6 +1750,8 @@ declare class AIAutocomplete {
|
|
|
1736
1750
|
private lastImpressionKey;
|
|
1737
1751
|
/** The server's `visible_impression`: send an impression only while the dropdown is visible. */
|
|
1738
1752
|
private visibleImpression;
|
|
1753
|
+
/** The server's `sdk_visitor_id`: keep a visitor id for a host that passes none. */
|
|
1754
|
+
private sdkVisitorId;
|
|
1739
1755
|
private destroyed;
|
|
1740
1756
|
/** The location search in flight, so a newer phrase or destroy() can cancel it. */
|
|
1741
1757
|
private locationAbort;
|
|
@@ -1911,6 +1927,18 @@ declare class AIAutocomplete {
|
|
|
1911
1927
|
* own — a button you render — so each submit is counted once.
|
|
1912
1928
|
*/
|
|
1913
1929
|
recordSubmit(result: AutocompleteResult): void;
|
|
1930
|
+
/**
|
|
1931
|
+
* The visitor id this instance's events carry right now, to send with your
|
|
1932
|
+
* own events. Undefined while there is none: before the first response, or
|
|
1933
|
+
* without `visitorId` and without consent.
|
|
1934
|
+
*/
|
|
1935
|
+
getVisitorId(): string | undefined;
|
|
1936
|
+
/**
|
|
1937
|
+
* Reads `analyticsConsent` again now. Call it when the shopper changes their
|
|
1938
|
+
* choice, so a declined one removes the stored visitor id at once rather
|
|
1939
|
+
* than at the next event.
|
|
1940
|
+
*/
|
|
1941
|
+
refreshAnalyticsConsent(): void;
|
|
1914
1942
|
/**
|
|
1915
1943
|
* Ends whatever is in progress, a submit or a product selection, at once:
|
|
1916
1944
|
* call it when the work your handler started is done and the shopper is
|
|
@@ -2115,6 +2143,7 @@ declare class AIAutocomplete {
|
|
|
2115
2143
|
private applyOption;
|
|
2116
2144
|
private startSelectionAnimationTimer;
|
|
2117
2145
|
private resolveVisitorId;
|
|
2146
|
+
private resolveOwnVisitorId;
|
|
2118
2147
|
private resolveSource;
|
|
2119
2148
|
/**
|
|
2120
2149
|
* With `visible_impression`, the dropdown opening is itself an impression of
|