@nuskin/react-search-sdk 1.0.0-comx-2233.2 → 1.0.0-comx-2233.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.
- package/dist/index.d.mts +139 -10
- package/dist/index.d.ts +139 -10
- package/dist/index.js +202 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +194 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -148,6 +148,8 @@ interface UseSearchSuggestionsResult {
|
|
|
148
148
|
hasMoreResults: boolean;
|
|
149
149
|
/** `true` when the trimmed query is non-empty. */
|
|
150
150
|
hasQuery: boolean;
|
|
151
|
+
/** `true` when the latest suggestions request failed. */
|
|
152
|
+
suggestionFetchFailed: boolean;
|
|
151
153
|
/** Normalised "Did You Mean?" items from the API. */
|
|
152
154
|
didYouMean: DidYouMeanItem[];
|
|
153
155
|
/** `true` while a debounced fetch is in flight. */
|
|
@@ -205,25 +207,25 @@ interface SearchServiceOptions {
|
|
|
205
207
|
*/
|
|
206
208
|
onSuggestionAction?: (option: SuggestionOption) => Promise<boolean> | boolean | undefined;
|
|
207
209
|
}
|
|
208
|
-
/** Public API returned by `createSearchService`.
|
|
210
|
+
/** Public API returned by `createSearchService`. */
|
|
209
211
|
interface SearchService {
|
|
210
212
|
/** Returns fallback placeholder + aria-label copy. */
|
|
211
213
|
getSearchChromeCopy: () => Promise<SearchChromeCopy>;
|
|
212
214
|
/** Fetches typeahead suggestions from the Equinox catalog. */
|
|
213
215
|
fetchSuggestions: (searchTerm: string) => Promise<SuggestionsResponse>;
|
|
214
216
|
/**
|
|
215
|
-
* Records the query in recent searches, then
|
|
216
|
-
*
|
|
217
|
+
* Records the query in recent searches, then returns the option URL or the
|
|
218
|
+
* fallback search-results path for the consuming router to navigate.
|
|
217
219
|
*/
|
|
218
220
|
submitProductSearch: (query: string, option?: SuggestionOption) => string | undefined;
|
|
219
221
|
/**
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
+
* Returns the suggestion's URL if one is resolvable; otherwise submits the
|
|
223
|
+
* suggestion's textual value as a product search.
|
|
222
224
|
*/
|
|
223
225
|
activateSuggestionAction: (option: SuggestionOption) => string | undefined;
|
|
224
226
|
/** Returns the navigable URL for a suggestion option (or `""`). */
|
|
225
227
|
getSuggestionHref: (option: SuggestionOption) => string;
|
|
226
|
-
/**
|
|
228
|
+
/** Returns the search-results page path for `query`. */
|
|
227
229
|
viewMoreResults: (input: {
|
|
228
230
|
query: string;
|
|
229
231
|
}) => string | undefined;
|
|
@@ -237,9 +239,9 @@ interface SearchService {
|
|
|
237
239
|
* SearchApiService — Phase 0 lift-and-shift of
|
|
238
240
|
* `header-mfe/src/services/HeaderSearchService.js`.
|
|
239
241
|
*
|
|
240
|
-
* Behaviour
|
|
241
|
-
* `sessionStorage` key format,
|
|
242
|
-
*
|
|
242
|
+
* Behaviour follows the header search contract for URL formats,
|
|
243
|
+
* `sessionStorage` key format, fetch parameter shape, and fallback values.
|
|
244
|
+
* Navigation side effects are left to the consuming router.
|
|
243
245
|
*
|
|
244
246
|
* Two responsibilities were intentionally moved OUT of the SDK to preserve
|
|
245
247
|
* the SDK-narrow boundary:
|
|
@@ -473,6 +475,133 @@ declare function getSeeMoreResultsPayload(query: string, totalResultsCount: numb
|
|
|
473
475
|
visibleResultsCount: number;
|
|
474
476
|
};
|
|
475
477
|
|
|
478
|
+
/**
|
|
479
|
+
* Types + Window augmentation for the GTM (Google Tag Manager) tracking layer.
|
|
480
|
+
*/
|
|
481
|
+
declare global {
|
|
482
|
+
interface Window {
|
|
483
|
+
dataLayer?: unknown[];
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
type SearchGtmUserStatus = 'guest' | 'logged_in';
|
|
487
|
+
type SearchGtmSearchType = 'semantic search' | 'AI agent';
|
|
488
|
+
/**
|
|
489
|
+
* Context shared by every AI-chat GTM event. Values that are unknown at
|
|
490
|
+
* emit time should be passed as an empty string so the schema stays stable
|
|
491
|
+
* (matches the placeholder shape the data team provided in COMX-3277).
|
|
492
|
+
*/
|
|
493
|
+
interface SearchGtmContext {
|
|
494
|
+
/** Conversation id from ChatService.createConversation, coerced to string. */
|
|
495
|
+
chatId?: string | number;
|
|
496
|
+
/** Page type where the chat was initiated (e.g. `plp`, `pdp`, `home`). */
|
|
497
|
+
pageType?: string;
|
|
498
|
+
/** ISO 3166-1 alpha-2 country code (e.g. `US`, `DE`). */
|
|
499
|
+
countryCode?: string;
|
|
500
|
+
/** Language code (e.g. `en`, `de`). */
|
|
501
|
+
language?: string;
|
|
502
|
+
/**
|
|
503
|
+
* Whether the visitor is a guest or a logged-in user.
|
|
504
|
+
* Falls back to the `IsAuthenticated` localStorage flag written by the
|
|
505
|
+
* storefront `Session` model when not supplied by the host.
|
|
506
|
+
*/
|
|
507
|
+
userStatus?: SearchGtmUserStatus;
|
|
508
|
+
/** Authenticated user id, or empty for guests. */
|
|
509
|
+
userId?: string;
|
|
510
|
+
/**
|
|
511
|
+
* Customer account type (e.g. `Retail Customer`, `Brand Affiliate`).
|
|
512
|
+
* Falls back to the `accountType` localStorage value written by the
|
|
513
|
+
* storefront `Customer` / `MyAccount` flows when not supplied.
|
|
514
|
+
*/
|
|
515
|
+
accountType?: string;
|
|
516
|
+
}
|
|
517
|
+
/** Payload for the Search_Type event (query the user submitted). */
|
|
518
|
+
interface SearchTypeEventInput extends SearchGtmContext {
|
|
519
|
+
/** Type of AI search: `semantic search` or `AI agent`. */
|
|
520
|
+
searchType?: SearchGtmSearchType;
|
|
521
|
+
/** User's raw search query / response text. */
|
|
522
|
+
searchResponse?: string;
|
|
523
|
+
}
|
|
524
|
+
/** Payload for the ProductSearch event (results returned to the user). */
|
|
525
|
+
interface ProductSearchEventInput extends SearchGtmContext {
|
|
526
|
+
searchType?: SearchGtmSearchType;
|
|
527
|
+
/** Number of product results shown to the user. */
|
|
528
|
+
productResults?: number;
|
|
529
|
+
/** Raw products payload to send into Product_results as JSON string. */
|
|
530
|
+
productResultsData?: unknown;
|
|
531
|
+
}
|
|
532
|
+
/** Payload for the Error_popup event. */
|
|
533
|
+
interface ErrorPopupEventInput extends SearchGtmContext {
|
|
534
|
+
searchType?: SearchGtmSearchType;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Extracts `{ countryCode, language }` from a storefront-shaped path
|
|
539
|
+
* (`/{country}/{language}/...`, e.g. `/us/en/product/x`).
|
|
540
|
+
*
|
|
541
|
+
* Reads `window.location.pathname` when called with no argument. Returns `{}`
|
|
542
|
+
* if the first two path segments are not both 2-letter locale codes.
|
|
543
|
+
*/
|
|
544
|
+
declare function getLocaleFromUrl(pathname?: string): {
|
|
545
|
+
countryCode?: string;
|
|
546
|
+
language?: string;
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* GTM constants — event names, storage keys, and enum-like value maps.
|
|
551
|
+
* Types are declared in `./gtmTypes` and imported here only for `satisfies`.
|
|
552
|
+
*/
|
|
553
|
+
declare const SEARCH_GTM_EVENTS: {
|
|
554
|
+
readonly CHAT_ENTRY_POINT: "Begin_chat";
|
|
555
|
+
readonly SEARCH_TYPE: "Search_Type";
|
|
556
|
+
readonly PRODUCT_SEARCH: "ProductSearch";
|
|
557
|
+
readonly ERROR_POPUP: "Error_popup";
|
|
558
|
+
};
|
|
559
|
+
declare const SEARCH_GTM_SEARCH_TYPES: {
|
|
560
|
+
readonly SEMANTIC: "semantic search";
|
|
561
|
+
readonly AI_AGENT: "AI agent";
|
|
562
|
+
};
|
|
563
|
+
declare const SEARCH_GTM_USER_STATUS: {
|
|
564
|
+
readonly GUEST: "guest";
|
|
565
|
+
readonly LOGGED_IN: "logged_in";
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* GTM (Google Tag Manager) dataLayer tracking for the AI Chat Bot.
|
|
570
|
+
*
|
|
571
|
+
* Implements the events specified in COMX-3277:
|
|
572
|
+
* 1. Chatentry_Point - user initiates the AI chat from an entry point
|
|
573
|
+
* 2. Search_Type - user submits a query in the AI chat
|
|
574
|
+
* 3. ProductSearch - AI chat returns product results (fires even on 0)
|
|
575
|
+
* 4. Error_popup - API errors / unhandled exceptions during a session
|
|
576
|
+
*
|
|
577
|
+
* All UI repos (react-search-components, and any host consuming the SDK)
|
|
578
|
+
* should call these helpers instead of touching `window.dataLayer` directly,
|
|
579
|
+
* so that payload shape and error handling stay consistent.
|
|
580
|
+
*
|
|
581
|
+
* Types live in `./gtmTypes`, constants in `./gtmConstants`, and generic
|
|
582
|
+
* helpers in `./commonUtils` / `./storage`.
|
|
583
|
+
*/
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Pushes a raw event object onto `window.dataLayer`.
|
|
587
|
+
*
|
|
588
|
+
* Silently no-ops when `window` is unavailable (SSR) or the dataLayer is
|
|
589
|
+
* missing - GTM tag firing is a best-effort side effect, never a blocker for
|
|
590
|
+
* the search flow.
|
|
591
|
+
*/
|
|
592
|
+
declare function pushGtmEvent(event: Record<string, unknown>): void;
|
|
593
|
+
/** Fires `Begin_chat` when the user initiates the AI chat. */
|
|
594
|
+
declare function trackChatEntryPoint(ctx: SearchGtmContext): void;
|
|
595
|
+
/** Fires `Search_Type` when the user submits a query in the AI chat. */
|
|
596
|
+
declare function trackSearchType(input: SearchTypeEventInput): void;
|
|
597
|
+
/**
|
|
598
|
+
* Fires `ProductSearch` when the AI chat returns results.
|
|
599
|
+
* Must be called even when 0 products are returned.
|
|
600
|
+
*/
|
|
601
|
+
declare function trackProductSearch(input: ProductSearchEventInput): void;
|
|
602
|
+
/** Fires `Error_popup` for API errors and unhandled exceptions during chat. */
|
|
603
|
+
declare function trackErrorPopup(input: ErrorPopupEventInput): void;
|
|
604
|
+
|
|
476
605
|
/**
|
|
477
606
|
* Constants for the search SDK. Ported from
|
|
478
607
|
* `header-mfe/src/utils/search/search.constants.js` — only the values the
|
|
@@ -515,4 +644,4 @@ declare const DEFAULT_AI_CHAT_CONVERSATIONS_URL = "https://admin.tst.nuskin.ai/a
|
|
|
515
644
|
/** Default POST endpoint for sending AI chat messages. */
|
|
516
645
|
declare const DEFAULT_AI_CHAT_MESSAGES_URL = "https://admin.tst.nuskin.ai/api/analytics/v1/embed/messages";
|
|
517
646
|
|
|
518
|
-
export { CATALOG_SUGGESTIONS_PATH, type CatalogSuggestionItem, type ChatMessageResult, type ChatProduct, type ChatService, type ChatServiceOptions, DEBOUNCE_MS, DEFAULT_AI_CHAT_BASE_URL, DEFAULT_AI_CHAT_CONVERSATIONS_URL, DEFAULT_AI_CHAT_MESSAGES_URL, DEFAULT_SEARCH_PATH, DEFAULT_SUGGESTION_PAGE, DEFAULT_SUGGESTION_SIZE, type DidYouMeanItem, type GetMarketConfig, type LocaleParts, type LocationLike, MAX_VISIBLE_SUGGESTIONS, type MarketConfig, type ProductType, RECENT_SEARCHES_DEFAULT_LIMIT, RECENT_SEARCHES_PREFIX, SEARCH_PLACEHOLDER, STOREFRONT_SHOPPING_CONTEXT, type SearchChromeCopy, type SearchHistoryEntry, type SearchHistoryState, type SearchHistoryEntry as SearchHistoryStoreEntry, type SearchService, type SearchServiceOptions, type SuggestionOption, type SuggestionsResponse, TRIGGER_PLACEHOLDER, type UseSearchHistoryResult, type UseSearchSuggestionsOptions, type UseSearchSuggestionsResult, type UseVoiceSearchOptions, type UseVoiceSearchResult, createChatService, createSearchService, getImageFromProperty, getIngredientTerms, getSeeMoreResultsPayload, getVisibleSuggestions, isCartActionDisabled, isSellableProductStatus, isSuggestionDisabled, mapCatalogProductToSuggestion, normalizeDidYouMean, resolveApiGatewayPath, resolveSuggestionImageSrc, useSearchHistory, useSearchHistoryStore, useSearchSuggestions, useVoiceSearch };
|
|
647
|
+
export { CATALOG_SUGGESTIONS_PATH, type CatalogSuggestionItem, type ChatMessageResult, type ChatProduct, type ChatService, type ChatServiceOptions, DEBOUNCE_MS, DEFAULT_AI_CHAT_BASE_URL, DEFAULT_AI_CHAT_CONVERSATIONS_URL, DEFAULT_AI_CHAT_MESSAGES_URL, DEFAULT_SEARCH_PATH, DEFAULT_SUGGESTION_PAGE, DEFAULT_SUGGESTION_SIZE, type DidYouMeanItem, type ErrorPopupEventInput, type GetMarketConfig, type LocaleParts, type LocationLike, MAX_VISIBLE_SUGGESTIONS, type MarketConfig, type ProductSearchEventInput, type ProductType, RECENT_SEARCHES_DEFAULT_LIMIT, RECENT_SEARCHES_PREFIX, SEARCH_GTM_EVENTS, SEARCH_GTM_SEARCH_TYPES, SEARCH_GTM_USER_STATUS, SEARCH_PLACEHOLDER, STOREFRONT_SHOPPING_CONTEXT, type SearchChromeCopy, type SearchGtmContext, type SearchGtmSearchType, type SearchGtmUserStatus, type SearchHistoryEntry, type SearchHistoryState, type SearchHistoryEntry as SearchHistoryStoreEntry, type SearchService, type SearchServiceOptions, type SearchTypeEventInput, type SuggestionOption, type SuggestionsResponse, TRIGGER_PLACEHOLDER, type UseSearchHistoryResult, type UseSearchSuggestionsOptions, type UseSearchSuggestionsResult, type UseVoiceSearchOptions, type UseVoiceSearchResult, createChatService, createSearchService, getImageFromProperty, getIngredientTerms, getLocaleFromUrl, getSeeMoreResultsPayload, getVisibleSuggestions, isCartActionDisabled, isSellableProductStatus, isSuggestionDisabled, mapCatalogProductToSuggestion, normalizeDidYouMean, pushGtmEvent, resolveApiGatewayPath, resolveSuggestionImageSrc, trackChatEntryPoint, trackErrorPopup, trackProductSearch, trackSearchType, useSearchHistory, useSearchHistoryStore, useSearchSuggestions, useVoiceSearch };
|
package/dist/index.d.ts
CHANGED
|
@@ -148,6 +148,8 @@ interface UseSearchSuggestionsResult {
|
|
|
148
148
|
hasMoreResults: boolean;
|
|
149
149
|
/** `true` when the trimmed query is non-empty. */
|
|
150
150
|
hasQuery: boolean;
|
|
151
|
+
/** `true` when the latest suggestions request failed. */
|
|
152
|
+
suggestionFetchFailed: boolean;
|
|
151
153
|
/** Normalised "Did You Mean?" items from the API. */
|
|
152
154
|
didYouMean: DidYouMeanItem[];
|
|
153
155
|
/** `true` while a debounced fetch is in flight. */
|
|
@@ -205,25 +207,25 @@ interface SearchServiceOptions {
|
|
|
205
207
|
*/
|
|
206
208
|
onSuggestionAction?: (option: SuggestionOption) => Promise<boolean> | boolean | undefined;
|
|
207
209
|
}
|
|
208
|
-
/** Public API returned by `createSearchService`.
|
|
210
|
+
/** Public API returned by `createSearchService`. */
|
|
209
211
|
interface SearchService {
|
|
210
212
|
/** Returns fallback placeholder + aria-label copy. */
|
|
211
213
|
getSearchChromeCopy: () => Promise<SearchChromeCopy>;
|
|
212
214
|
/** Fetches typeahead suggestions from the Equinox catalog. */
|
|
213
215
|
fetchSuggestions: (searchTerm: string) => Promise<SuggestionsResponse>;
|
|
214
216
|
/**
|
|
215
|
-
* Records the query in recent searches, then
|
|
216
|
-
*
|
|
217
|
+
* Records the query in recent searches, then returns the option URL or the
|
|
218
|
+
* fallback search-results path for the consuming router to navigate.
|
|
217
219
|
*/
|
|
218
220
|
submitProductSearch: (query: string, option?: SuggestionOption) => string | undefined;
|
|
219
221
|
/**
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
+
* Returns the suggestion's URL if one is resolvable; otherwise submits the
|
|
223
|
+
* suggestion's textual value as a product search.
|
|
222
224
|
*/
|
|
223
225
|
activateSuggestionAction: (option: SuggestionOption) => string | undefined;
|
|
224
226
|
/** Returns the navigable URL for a suggestion option (or `""`). */
|
|
225
227
|
getSuggestionHref: (option: SuggestionOption) => string;
|
|
226
|
-
/**
|
|
228
|
+
/** Returns the search-results page path for `query`. */
|
|
227
229
|
viewMoreResults: (input: {
|
|
228
230
|
query: string;
|
|
229
231
|
}) => string | undefined;
|
|
@@ -237,9 +239,9 @@ interface SearchService {
|
|
|
237
239
|
* SearchApiService — Phase 0 lift-and-shift of
|
|
238
240
|
* `header-mfe/src/services/HeaderSearchService.js`.
|
|
239
241
|
*
|
|
240
|
-
* Behaviour
|
|
241
|
-
* `sessionStorage` key format,
|
|
242
|
-
*
|
|
242
|
+
* Behaviour follows the header search contract for URL formats,
|
|
243
|
+
* `sessionStorage` key format, fetch parameter shape, and fallback values.
|
|
244
|
+
* Navigation side effects are left to the consuming router.
|
|
243
245
|
*
|
|
244
246
|
* Two responsibilities were intentionally moved OUT of the SDK to preserve
|
|
245
247
|
* the SDK-narrow boundary:
|
|
@@ -473,6 +475,133 @@ declare function getSeeMoreResultsPayload(query: string, totalResultsCount: numb
|
|
|
473
475
|
visibleResultsCount: number;
|
|
474
476
|
};
|
|
475
477
|
|
|
478
|
+
/**
|
|
479
|
+
* Types + Window augmentation for the GTM (Google Tag Manager) tracking layer.
|
|
480
|
+
*/
|
|
481
|
+
declare global {
|
|
482
|
+
interface Window {
|
|
483
|
+
dataLayer?: unknown[];
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
type SearchGtmUserStatus = 'guest' | 'logged_in';
|
|
487
|
+
type SearchGtmSearchType = 'semantic search' | 'AI agent';
|
|
488
|
+
/**
|
|
489
|
+
* Context shared by every AI-chat GTM event. Values that are unknown at
|
|
490
|
+
* emit time should be passed as an empty string so the schema stays stable
|
|
491
|
+
* (matches the placeholder shape the data team provided in COMX-3277).
|
|
492
|
+
*/
|
|
493
|
+
interface SearchGtmContext {
|
|
494
|
+
/** Conversation id from ChatService.createConversation, coerced to string. */
|
|
495
|
+
chatId?: string | number;
|
|
496
|
+
/** Page type where the chat was initiated (e.g. `plp`, `pdp`, `home`). */
|
|
497
|
+
pageType?: string;
|
|
498
|
+
/** ISO 3166-1 alpha-2 country code (e.g. `US`, `DE`). */
|
|
499
|
+
countryCode?: string;
|
|
500
|
+
/** Language code (e.g. `en`, `de`). */
|
|
501
|
+
language?: string;
|
|
502
|
+
/**
|
|
503
|
+
* Whether the visitor is a guest or a logged-in user.
|
|
504
|
+
* Falls back to the `IsAuthenticated` localStorage flag written by the
|
|
505
|
+
* storefront `Session` model when not supplied by the host.
|
|
506
|
+
*/
|
|
507
|
+
userStatus?: SearchGtmUserStatus;
|
|
508
|
+
/** Authenticated user id, or empty for guests. */
|
|
509
|
+
userId?: string;
|
|
510
|
+
/**
|
|
511
|
+
* Customer account type (e.g. `Retail Customer`, `Brand Affiliate`).
|
|
512
|
+
* Falls back to the `accountType` localStorage value written by the
|
|
513
|
+
* storefront `Customer` / `MyAccount` flows when not supplied.
|
|
514
|
+
*/
|
|
515
|
+
accountType?: string;
|
|
516
|
+
}
|
|
517
|
+
/** Payload for the Search_Type event (query the user submitted). */
|
|
518
|
+
interface SearchTypeEventInput extends SearchGtmContext {
|
|
519
|
+
/** Type of AI search: `semantic search` or `AI agent`. */
|
|
520
|
+
searchType?: SearchGtmSearchType;
|
|
521
|
+
/** User's raw search query / response text. */
|
|
522
|
+
searchResponse?: string;
|
|
523
|
+
}
|
|
524
|
+
/** Payload for the ProductSearch event (results returned to the user). */
|
|
525
|
+
interface ProductSearchEventInput extends SearchGtmContext {
|
|
526
|
+
searchType?: SearchGtmSearchType;
|
|
527
|
+
/** Number of product results shown to the user. */
|
|
528
|
+
productResults?: number;
|
|
529
|
+
/** Raw products payload to send into Product_results as JSON string. */
|
|
530
|
+
productResultsData?: unknown;
|
|
531
|
+
}
|
|
532
|
+
/** Payload for the Error_popup event. */
|
|
533
|
+
interface ErrorPopupEventInput extends SearchGtmContext {
|
|
534
|
+
searchType?: SearchGtmSearchType;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Extracts `{ countryCode, language }` from a storefront-shaped path
|
|
539
|
+
* (`/{country}/{language}/...`, e.g. `/us/en/product/x`).
|
|
540
|
+
*
|
|
541
|
+
* Reads `window.location.pathname` when called with no argument. Returns `{}`
|
|
542
|
+
* if the first two path segments are not both 2-letter locale codes.
|
|
543
|
+
*/
|
|
544
|
+
declare function getLocaleFromUrl(pathname?: string): {
|
|
545
|
+
countryCode?: string;
|
|
546
|
+
language?: string;
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* GTM constants — event names, storage keys, and enum-like value maps.
|
|
551
|
+
* Types are declared in `./gtmTypes` and imported here only for `satisfies`.
|
|
552
|
+
*/
|
|
553
|
+
declare const SEARCH_GTM_EVENTS: {
|
|
554
|
+
readonly CHAT_ENTRY_POINT: "Begin_chat";
|
|
555
|
+
readonly SEARCH_TYPE: "Search_Type";
|
|
556
|
+
readonly PRODUCT_SEARCH: "ProductSearch";
|
|
557
|
+
readonly ERROR_POPUP: "Error_popup";
|
|
558
|
+
};
|
|
559
|
+
declare const SEARCH_GTM_SEARCH_TYPES: {
|
|
560
|
+
readonly SEMANTIC: "semantic search";
|
|
561
|
+
readonly AI_AGENT: "AI agent";
|
|
562
|
+
};
|
|
563
|
+
declare const SEARCH_GTM_USER_STATUS: {
|
|
564
|
+
readonly GUEST: "guest";
|
|
565
|
+
readonly LOGGED_IN: "logged_in";
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* GTM (Google Tag Manager) dataLayer tracking for the AI Chat Bot.
|
|
570
|
+
*
|
|
571
|
+
* Implements the events specified in COMX-3277:
|
|
572
|
+
* 1. Chatentry_Point - user initiates the AI chat from an entry point
|
|
573
|
+
* 2. Search_Type - user submits a query in the AI chat
|
|
574
|
+
* 3. ProductSearch - AI chat returns product results (fires even on 0)
|
|
575
|
+
* 4. Error_popup - API errors / unhandled exceptions during a session
|
|
576
|
+
*
|
|
577
|
+
* All UI repos (react-search-components, and any host consuming the SDK)
|
|
578
|
+
* should call these helpers instead of touching `window.dataLayer` directly,
|
|
579
|
+
* so that payload shape and error handling stay consistent.
|
|
580
|
+
*
|
|
581
|
+
* Types live in `./gtmTypes`, constants in `./gtmConstants`, and generic
|
|
582
|
+
* helpers in `./commonUtils` / `./storage`.
|
|
583
|
+
*/
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Pushes a raw event object onto `window.dataLayer`.
|
|
587
|
+
*
|
|
588
|
+
* Silently no-ops when `window` is unavailable (SSR) or the dataLayer is
|
|
589
|
+
* missing - GTM tag firing is a best-effort side effect, never a blocker for
|
|
590
|
+
* the search flow.
|
|
591
|
+
*/
|
|
592
|
+
declare function pushGtmEvent(event: Record<string, unknown>): void;
|
|
593
|
+
/** Fires `Begin_chat` when the user initiates the AI chat. */
|
|
594
|
+
declare function trackChatEntryPoint(ctx: SearchGtmContext): void;
|
|
595
|
+
/** Fires `Search_Type` when the user submits a query in the AI chat. */
|
|
596
|
+
declare function trackSearchType(input: SearchTypeEventInput): void;
|
|
597
|
+
/**
|
|
598
|
+
* Fires `ProductSearch` when the AI chat returns results.
|
|
599
|
+
* Must be called even when 0 products are returned.
|
|
600
|
+
*/
|
|
601
|
+
declare function trackProductSearch(input: ProductSearchEventInput): void;
|
|
602
|
+
/** Fires `Error_popup` for API errors and unhandled exceptions during chat. */
|
|
603
|
+
declare function trackErrorPopup(input: ErrorPopupEventInput): void;
|
|
604
|
+
|
|
476
605
|
/**
|
|
477
606
|
* Constants for the search SDK. Ported from
|
|
478
607
|
* `header-mfe/src/utils/search/search.constants.js` — only the values the
|
|
@@ -515,4 +644,4 @@ declare const DEFAULT_AI_CHAT_CONVERSATIONS_URL = "https://admin.tst.nuskin.ai/a
|
|
|
515
644
|
/** Default POST endpoint for sending AI chat messages. */
|
|
516
645
|
declare const DEFAULT_AI_CHAT_MESSAGES_URL = "https://admin.tst.nuskin.ai/api/analytics/v1/embed/messages";
|
|
517
646
|
|
|
518
|
-
export { CATALOG_SUGGESTIONS_PATH, type CatalogSuggestionItem, type ChatMessageResult, type ChatProduct, type ChatService, type ChatServiceOptions, DEBOUNCE_MS, DEFAULT_AI_CHAT_BASE_URL, DEFAULT_AI_CHAT_CONVERSATIONS_URL, DEFAULT_AI_CHAT_MESSAGES_URL, DEFAULT_SEARCH_PATH, DEFAULT_SUGGESTION_PAGE, DEFAULT_SUGGESTION_SIZE, type DidYouMeanItem, type GetMarketConfig, type LocaleParts, type LocationLike, MAX_VISIBLE_SUGGESTIONS, type MarketConfig, type ProductType, RECENT_SEARCHES_DEFAULT_LIMIT, RECENT_SEARCHES_PREFIX, SEARCH_PLACEHOLDER, STOREFRONT_SHOPPING_CONTEXT, type SearchChromeCopy, type SearchHistoryEntry, type SearchHistoryState, type SearchHistoryEntry as SearchHistoryStoreEntry, type SearchService, type SearchServiceOptions, type SuggestionOption, type SuggestionsResponse, TRIGGER_PLACEHOLDER, type UseSearchHistoryResult, type UseSearchSuggestionsOptions, type UseSearchSuggestionsResult, type UseVoiceSearchOptions, type UseVoiceSearchResult, createChatService, createSearchService, getImageFromProperty, getIngredientTerms, getSeeMoreResultsPayload, getVisibleSuggestions, isCartActionDisabled, isSellableProductStatus, isSuggestionDisabled, mapCatalogProductToSuggestion, normalizeDidYouMean, resolveApiGatewayPath, resolveSuggestionImageSrc, useSearchHistory, useSearchHistoryStore, useSearchSuggestions, useVoiceSearch };
|
|
647
|
+
export { CATALOG_SUGGESTIONS_PATH, type CatalogSuggestionItem, type ChatMessageResult, type ChatProduct, type ChatService, type ChatServiceOptions, DEBOUNCE_MS, DEFAULT_AI_CHAT_BASE_URL, DEFAULT_AI_CHAT_CONVERSATIONS_URL, DEFAULT_AI_CHAT_MESSAGES_URL, DEFAULT_SEARCH_PATH, DEFAULT_SUGGESTION_PAGE, DEFAULT_SUGGESTION_SIZE, type DidYouMeanItem, type ErrorPopupEventInput, type GetMarketConfig, type LocaleParts, type LocationLike, MAX_VISIBLE_SUGGESTIONS, type MarketConfig, type ProductSearchEventInput, type ProductType, RECENT_SEARCHES_DEFAULT_LIMIT, RECENT_SEARCHES_PREFIX, SEARCH_GTM_EVENTS, SEARCH_GTM_SEARCH_TYPES, SEARCH_GTM_USER_STATUS, SEARCH_PLACEHOLDER, STOREFRONT_SHOPPING_CONTEXT, type SearchChromeCopy, type SearchGtmContext, type SearchGtmSearchType, type SearchGtmUserStatus, type SearchHistoryEntry, type SearchHistoryState, type SearchHistoryEntry as SearchHistoryStoreEntry, type SearchService, type SearchServiceOptions, type SearchTypeEventInput, type SuggestionOption, type SuggestionsResponse, TRIGGER_PLACEHOLDER, type UseSearchHistoryResult, type UseSearchSuggestionsOptions, type UseSearchSuggestionsResult, type UseVoiceSearchOptions, type UseVoiceSearchResult, createChatService, createSearchService, getImageFromProperty, getIngredientTerms, getLocaleFromUrl, getSeeMoreResultsPayload, getVisibleSuggestions, isCartActionDisabled, isSellableProductStatus, isSuggestionDisabled, mapCatalogProductToSuggestion, normalizeDidYouMean, pushGtmEvent, resolveApiGatewayPath, resolveSuggestionImageSrc, trackChatEntryPoint, trackErrorPopup, trackProductSearch, trackSearchType, useSearchHistory, useSearchHistoryStore, useSearchSuggestions, useVoiceSearch };
|