@envive-ai/react-widgets-v3 0.3.14 → 0.3.15-alpha.2
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/debug/chatEmbed.cjs +1 -1
- package/dist/debug/chatEmbed.js +1 -1
- package/dist/debug/reportIssue.cjs +1 -1
- package/dist/debug/reportIssue.js +1 -1
- package/dist/hocs/withBaseWidget/types.d.cts +7 -8
- package/dist/hocs/withBaseWidget/types.d.ts +8 -8
- package/dist/hocs/withBaseWidget/withBaseWidget.cjs +37 -43
- package/dist/hocs/withBaseWidget/withBaseWidget.d.cts +2 -2
- package/dist/hocs/withBaseWidget/withBaseWidget.d.ts +2 -2
- package/dist/hocs/withBaseWidget/withBaseWidget.js +39 -45
- package/dist/hooks/dist/application/models/api/widgetText.d.cts +8 -0
- package/dist/hooks/dist/contexts/hardcopyContext/hardcopyContext.d.cts +12 -0
- package/dist/hooks/dist/contexts/types.d.cts +38 -0
- package/dist/hooks/dist/contexts/typesV3.d.cts +230 -0
- package/dist/hooks/dist/types/customerService.d.cts +21 -0
- package/dist/node_modules/@spiffy-ai/commerce-api-client/dist/models/WidgetType.cjs +1 -0
- package/dist/packages/hooks/dist/application/models/api/orgConfigResults.d.ts +2 -0
- package/dist/packages/hooks/dist/application/models/api/userEvent.d.ts +1 -0
- package/dist/packages/hooks/dist/application/models/api/widgetText.d.ts +8 -0
- package/dist/packages/hooks/dist/application/models/frontendConfig.d.ts +1 -0
- package/dist/packages/hooks/dist/contexts/hardcopyContext/hardcopyContext.d.ts +15 -0
- package/dist/packages/hooks/dist/contexts/hardcopyContext/index.d.ts +1 -0
- package/dist/packages/hooks/dist/contexts/types.d.ts +44 -0
- package/dist/packages/hooks/dist/contexts/typesV3.d.ts +230 -0
- package/dist/packages/hooks/dist/types/customerService.d.ts +21 -0
- package/dist/packages/hooks/dist/types/custservice-types.d.ts +1 -0
- package/dist/packages/icons/dist/IconCloseVariant.cjs +5 -6
- package/dist/packages/icons/dist/IconCloseVariant.js +4 -6
- package/dist/packages/widgets/dist/SearchResults/SearchResults.d.ts +4 -3
- package/dist/packages/widgets/dist/SearchResults/SearchResultsWidget.d.ts +2 -2
- package/dist/packages/widgets/dist/SearchZeroState/SearchZeroStateWidget.d.ts +2 -2
- package/dist/packages/widgets/dist/SearchZeroState/index.d.ts +2 -1
- package/dist/packages/widgets/dist/SearchZeroState/types.d.ts +2 -2
- package/dist/packages/widgets/dist/SuggestionBar/SuggestionBar.d.ts +3 -3
- package/dist/packages/widgets/dist/SuggestionButtonContainer/index.d.ts +2 -0
- package/dist/packages/widgets/dist/SuggestionButtonContainer/types.d.ts +3 -2
- package/dist/packages/widgets/dist/packages/hooks/dist/application/models/api/response.d.ts +14 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/application/models/api/search.d.ts +15 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/application/models/utilityTypes/camelCase.d.ts +73 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/application/models/utilityTypes/camelCasedPropertiesDeep.d.ts +61 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/application/models/utilityTypes/internal.d.ts +25 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/application/models/utilityTypes/splitWords.d.ts +35 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/application/models/utilityTypes/trim.d.ts +32 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/application/models/utilityTypes/unknownArray.d.ts +32 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/application/models/variantInfo/pageVisitInfo.d.ts +1 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/application/models/variantInfo/variantInfo.d.ts +2 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/atoms/search/searchAPI.d.ts +15 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/contexts/hardcopyContext/hardcopyContext.d.ts +1 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/contexts/types.d.ts +64 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/hooks/Search/useSearch.d.ts +60 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/hooks/utils.d.ts +13 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/types/OrgInfo.d.ts +1 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/types/index.d.ts +1 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/types/search-filter-types.d.ts +28 -0
- package/dist/packages/widgets/dist/packages/hooks/dist/types/test-types.d.ts +10 -0
- package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.cjs +35 -4
- package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.cts +3 -3
- package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.ts +3 -3
- package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.js +35 -4
- package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.d.cts +3 -3
- package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.d.ts +3 -3
- package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.cjs +33 -12
- package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.d.cts +3 -3
- package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.d.ts +3 -3
- package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.js +35 -14
- package/dist/widgets/FloatingChatWidget/FloatingChatOverlay.cjs +44 -23
- package/dist/widgets/FloatingChatWidget/FloatingChatOverlay.js +44 -23
- package/dist/widgets/FloatingChatWidget/FloatingChatWidget.cjs +62 -38
- package/dist/widgets/FloatingChatWidget/FloatingChatWidget.d.cts +5 -3
- package/dist/widgets/FloatingChatWidget/FloatingChatWidget.d.ts +5 -3
- package/dist/widgets/FloatingChatWidget/FloatingChatWidget.js +63 -39
- package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.d.cts +2 -2
- package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.d.ts +2 -2
- package/dist/widgets/ProductCardWidget/ProductCardWidget.cjs +24 -12
- package/dist/widgets/ProductCardWidget/ProductCardWidget.d.cts +2 -2
- package/dist/widgets/ProductCardWidget/ProductCardWidget.d.ts +2 -2
- package/dist/widgets/ProductCardWidget/ProductCardWidget.js +26 -14
- package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.cjs +22 -12
- package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.d.cts +3 -3
- package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.d.ts +3 -3
- package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.js +24 -14
- package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.cjs +14 -11
- package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.d.cts +2 -2
- package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.d.ts +2 -2
- package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.js +18 -15
- package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.cjs +1 -1
- package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.d.ts +2 -2
- package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.js +1 -1
- package/dist/widgets/SocialProofWidget/SocialProofWidget.cjs +53 -15
- package/dist/widgets/SocialProofWidget/SocialProofWidget.d.cts +3 -3
- package/dist/widgets/SocialProofWidget/SocialProofWidget.d.ts +3 -3
- package/dist/widgets/SocialProofWidget/SocialProofWidget.js +56 -18
- package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.cjs +10 -10
- package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.d.cts +2 -2
- package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.d.ts +2 -2
- package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.js +13 -13
- package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.cjs +1 -1
- package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.d.cts +2 -2
- package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.d.ts +2 -2
- package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.js +1 -1
- package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.cjs +23 -11
- package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.d.cts +3 -3
- package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.d.ts +3 -3
- package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.js +26 -14
- package/dist/widgets/dist/SearchResults/SearchResults.d.cts +4 -3
- package/dist/widgets/dist/SearchResults/SearchResultsWidget.d.cts +2 -2
- package/dist/widgets/dist/SearchZeroState/SearchZeroStateWidget.d.cts +2 -2
- package/dist/widgets/dist/SearchZeroState/types.d.cts +2 -2
- package/dist/widgets/dist/SuggestionBar/SuggestionBar.d.cts +3 -3
- package/dist/widgets/dist/SuggestionButtonContainer/types.d.cts +3 -2
- package/dist/widgets/dist/packages/hooks/dist/application/models/api/response.d.cts +14 -0
- package/dist/widgets/dist/packages/hooks/dist/application/models/api/search.d.cts +15 -0
- package/dist/widgets/dist/packages/hooks/dist/application/models/utilityTypes/camelCase.d.cts +73 -0
- package/dist/widgets/dist/packages/hooks/dist/application/models/utilityTypes/camelCasedPropertiesDeep.d.cts +61 -0
- package/dist/widgets/dist/packages/hooks/dist/application/models/utilityTypes/internal.d.cts +25 -0
- package/dist/widgets/dist/packages/hooks/dist/application/models/utilityTypes/splitWords.d.cts +35 -0
- package/dist/widgets/dist/packages/hooks/dist/application/models/utilityTypes/trim.d.cts +32 -0
- package/dist/widgets/dist/packages/hooks/dist/application/models/utilityTypes/unknownArray.d.cts +32 -0
- package/dist/widgets/dist/packages/hooks/dist/atoms/search/searchAPI.d.cts +14 -0
- package/dist/widgets/dist/packages/hooks/dist/contexts/types.d.cts +61 -0
- package/dist/widgets/dist/packages/hooks/dist/hooks/Search/useSearch.d.cts +60 -0
- package/dist/widgets/dist/packages/hooks/dist/hooks/utils.d.cts +12 -0
- package/dist/widgets/dist/packages/hooks/dist/types/search-filter-types.d.cts +28 -0
- package/dist/widgets/dist/packages/hooks/dist/types/test-types.d.cts +10 -0
- package/dist/widgets/hooks/useGetWidgetStatus.cjs +1 -1
- package/dist/widgets/hooks/useGetWidgetStatus.js +1 -1
- package/dist/widgets/utils/functions.cjs +0 -14
- package/dist/widgets/utils/functions.js +1 -14
- package/dist/widgets-v2/SearchZeroState/index.d.cts +2 -1
- package/dist/widgets-v2/SearchZeroState/index.d.ts +2 -1
- package/dist/widgets-v2/SuggestionButtonContainer/index.d.ts +1 -0
- package/package.json +4 -4
- package/src/hocs/withBaseWidget/__tests__/withBaseWidget.test.tsx +68 -302
- package/src/hocs/withBaseWidget/types.ts +6 -6
- package/src/hocs/withBaseWidget/withBaseWidget.tsx +46 -61
- package/src/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.tsx +59 -8
- package/src/widgets/ChatPreviewWidget/ChatPreviewWidget.tsx +54 -18
- package/src/widgets/ChatPreviewWidget/__tests__/ChatPreviewWidget.test.tsx +11 -5
- package/src/widgets/FloatingChatWidget/FloatingChatOverlay.tsx +48 -19
- package/src/widgets/FloatingChatWidget/FloatingChatWidget.tsx +100 -52
- package/src/widgets/FloatingChatWidget/__tests__/FloatingChatWidget.test.tsx +11 -5
- package/src/widgets/ProductCardWidget/ProductCardWidget.tsx +37 -16
- package/src/widgets/ProductCardWidget/__tests__/ProductCardWidget.test.tsx +12 -8
- package/src/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.tsx +38 -19
- package/src/widgets/PromptButtonCarouselWithImageWidget/__tests__/PromptButtonCarouselWithImageWidget.test.tsx +19 -8
- package/src/widgets/PromptCarouselWidget/PromptCarouselWidget.tsx +32 -19
- package/src/widgets/PromptCarouselWidget/__tests__/PromptCarouselWidget.test.tsx +21 -8
- package/src/widgets/SocialProofWidget/SocialProofWidget.tsx +77 -18
- package/src/widgets/SocialProofWidget/__tests__/SocialProofWidget.test.tsx +19 -8
- package/src/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.tsx +23 -19
- package/src/widgets/TitledPromptCarouselWidget/__tests__/TitledPromptCarouselWidget.test.tsx +19 -8
- package/src/widgets/TypingAnimationWidget/TypingAnimationWidget.tsx +45 -21
- package/src/widgets/TypingAnimationWidget/__tests__/TypingAnimationWidget.test.tsx +19 -8
- package/src/widgets/__tests__/trackEventCanary.test.ts +1 -1
- package/dist/packages/icons/dist/_virtual/rolldown_runtime.cjs +0 -27
- package/dist/packages/icons/dist/_virtual/rolldown_runtime.js +0 -25
- package/dist/packages/icons/dist/node_modules/react/cjs/react-jsx-runtime.development.cjs +0 -696
- package/dist/packages/icons/dist/node_modules/react/cjs/react-jsx-runtime.development.js +0 -696
- package/dist/packages/icons/dist/node_modules/react/cjs/react-jsx-runtime.production.min.cjs +0 -43
- package/dist/packages/icons/dist/node_modules/react/cjs/react-jsx-runtime.production.min.js +0 -43
- package/dist/packages/icons/dist/node_modules/react/cjs/react.development.cjs +0 -1528
- package/dist/packages/icons/dist/node_modules/react/cjs/react.development.js +0 -1528
- package/dist/packages/icons/dist/node_modules/react/cjs/react.production.min.cjs +0 -329
- package/dist/packages/icons/dist/node_modules/react/cjs/react.production.min.js +0 -329
- package/dist/packages/icons/dist/node_modules/react/index.cjs +0 -13
- package/dist/packages/icons/dist/node_modules/react/index.js +0 -13
- package/dist/packages/icons/dist/node_modules/react/jsx-runtime.cjs +0 -13
- package/dist/packages/icons/dist/node_modules/react/jsx-runtime.js +0 -13
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { render, waitFor } from '@testing-library/react';
|
|
2
|
-
import { SpiffyMetricsEventName } from '@envive-ai/react-hooks/contexts/amplitudeContext';
|
|
3
2
|
import { WidgetTypeV3 } from '@envive-ai/react-hooks/contexts/typesV3';
|
|
4
3
|
import { UserEvent, UserEventCategory } from '@spiffy-ai/commerce-api-client';
|
|
5
4
|
import { FloatingChatWidget } from '../FloatingChatWidget';
|
|
6
5
|
|
|
7
6
|
const mockTrackEvent = vi.fn();
|
|
8
7
|
const mockGetHardcopy = vi.fn();
|
|
8
|
+
const mockUseTrackComponentVisibleEvent = vi.fn();
|
|
9
9
|
|
|
10
10
|
vi.mock('@envive-ai/react-toolkit-v3/FloatingButton', () => ({
|
|
11
11
|
FloatingButton: () => <div data-testid="floating-button">Floating Button</div>,
|
|
@@ -22,6 +22,10 @@ vi.mock('@envive-ai/react-hooks/contexts/amplitudeContext', () => ({
|
|
|
22
22
|
},
|
|
23
23
|
}));
|
|
24
24
|
|
|
25
|
+
vi.mock('@envive-ai/react-hooks/hooks/TrackComponentVisibleEvent', () => ({
|
|
26
|
+
useTrackComponentVisibleEvent: (...args: unknown[]) => mockUseTrackComponentVisibleEvent(...args),
|
|
27
|
+
}));
|
|
28
|
+
|
|
25
29
|
vi.mock('@envive-ai/react-hooks/contexts/hardcopyContext', () => ({
|
|
26
30
|
useHardcopy: () => ({
|
|
27
31
|
getHardcopy: mockGetHardcopy,
|
|
@@ -105,13 +109,15 @@ describe('FloatingChatWidget analytics', () => {
|
|
|
105
109
|
|
|
106
110
|
await waitFor(
|
|
107
111
|
() => {
|
|
108
|
-
expect(
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
expect(mockUseTrackComponentVisibleEvent).toHaveBeenCalledWith(
|
|
113
|
+
expect.any(Object),
|
|
114
|
+
{
|
|
111
115
|
widget_config_id: 'floating-button',
|
|
112
116
|
widget_type: WidgetTypeV3.FloatingButtonV3,
|
|
113
117
|
},
|
|
114
|
-
|
|
118
|
+
'0px',
|
|
119
|
+
true,
|
|
120
|
+
);
|
|
115
121
|
},
|
|
116
122
|
{ timeout: 3000 },
|
|
117
123
|
);
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PromptButtonVariant } from '@envive-ai/react-toolkit-v3/PromptButton/types';
|
|
3
|
-
import { useCallback, useEffect } from 'react';
|
|
1
|
+
import { ChatElementDisplayLocationV3 } from '@envive-ai/react-hooks/application/models';
|
|
4
2
|
import {
|
|
5
3
|
EnviveMetricsEventName,
|
|
6
|
-
SpiffyMetricsEventName,
|
|
7
4
|
useAmplitude,
|
|
8
5
|
} from '@envive-ai/react-hooks/contexts/amplitudeContext';
|
|
9
|
-
import { ChatElementDisplayLocationV3 } from '@envive-ai/react-hooks/application/models';
|
|
10
6
|
import { useSalesAgent } from '@envive-ai/react-hooks/contexts/salesAgentContext';
|
|
7
|
+
import { ProductCardWidgetV3Config, WidgetTypeV3 } from '@envive-ai/react-hooks/contexts/typesV3';
|
|
11
8
|
import { useChatToggle } from '@envive-ai/react-hooks/hooks/ChatToggle';
|
|
9
|
+
import { useWidgetInteraction } from '@envive-ai/react-hooks/hooks/WidgetInteraction';
|
|
10
|
+
import {
|
|
11
|
+
WidgetInteractionComponent,
|
|
12
|
+
WidgetInteractionType,
|
|
13
|
+
} from '@envive-ai/react-hooks/hooks/WidgetInteraction/types';
|
|
12
14
|
import { ProductCard } from '@envive-ai/react-toolkit-v3/ProductCard';
|
|
15
|
+
import { PromptButtonVariant } from '@envive-ai/react-toolkit-v3/PromptButton/types';
|
|
16
|
+
import { usePromptCarouselAnalytics } from '@envive-ai/react-toolkit-v3/PromptCarousel';
|
|
13
17
|
import { Theme } from '@envive-ai/react-toolkit-v3/Tokens';
|
|
18
|
+
import { useCallback } from 'react';
|
|
14
19
|
import { BaseWidgetProps, withBaseWidget } from '../../hocs/withBaseWidget';
|
|
15
20
|
import { RawValues, getStringIdForText } from '../utils/functions';
|
|
16
21
|
|
|
@@ -52,17 +57,19 @@ const ProductCardWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
52
57
|
const imageSrc = productCardWidgetConfig?.imageSrc || '';
|
|
53
58
|
|
|
54
59
|
const { trackEvent } = useAmplitude();
|
|
55
|
-
|
|
56
|
-
const {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
const { trackWidgetInteraction } = useWidgetInteraction();
|
|
61
|
+
const {
|
|
62
|
+
onClick: onSuggestionClick,
|
|
63
|
+
onDrag,
|
|
64
|
+
onHover,
|
|
65
|
+
onMouseDown,
|
|
66
|
+
onMouseUp,
|
|
67
|
+
onTouchStart,
|
|
68
|
+
onTouchEnd,
|
|
69
|
+
} = usePromptCarouselAnalytics(WidgetInteractionComponent.IMAGE_PROMPT_CARD, text => {
|
|
70
|
+
const rawValues = (hardcopyContent as { rawValues?: RawValues } | undefined)?.rawValues;
|
|
71
|
+
return getStringIdForText(rawValues, text);
|
|
72
|
+
});
|
|
66
73
|
|
|
67
74
|
const handleSelect = useCallback(
|
|
68
75
|
(text: string) => {
|
|
@@ -82,12 +89,20 @@ const ProductCardWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
82
89
|
displayLocation: ChatElementDisplayLocationV3.PRODUCT_CARD_PROMPT_BUTTON,
|
|
83
90
|
});
|
|
84
91
|
openChat(ChatElementDisplayLocationV3.PRODUCT_CARD_PROMPT_BUTTON);
|
|
92
|
+
onSuggestionClick(text);
|
|
85
93
|
},
|
|
86
94
|
[hardcopyContent, onTypedMessageSubmitted, openChat, trackEvent],
|
|
87
95
|
);
|
|
88
96
|
|
|
89
97
|
const handleInputClick = useCallback(() => {
|
|
90
98
|
openChat(ChatElementDisplayLocationV3.PRODUCT_CARD_TEXT_FIELD);
|
|
99
|
+
trackWidgetInteraction({
|
|
100
|
+
eventName: EnviveMetricsEventName.WidgetInteraction,
|
|
101
|
+
trigger: {
|
|
102
|
+
widget: WidgetInteractionComponent.IMAGE_PROMPT_CARD,
|
|
103
|
+
widget_interaction: WidgetInteractionType.QUERY_INPUT_CLICKED,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
91
106
|
}, [openChat]);
|
|
92
107
|
|
|
93
108
|
return (
|
|
@@ -105,6 +120,12 @@ const ProductCardWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
105
120
|
textTypingDuration={800}
|
|
106
121
|
textTransition={2000}
|
|
107
122
|
onSelect={handleSelect}
|
|
123
|
+
onDrag={onDrag}
|
|
124
|
+
onHover={onHover}
|
|
125
|
+
onMouseDown={onMouseDown}
|
|
126
|
+
onMouseUp={onMouseUp}
|
|
127
|
+
onTouchStart={onTouchStart}
|
|
128
|
+
onTouchEnd={onTouchEnd}
|
|
108
129
|
onInputClick={handleInputClick}
|
|
109
130
|
/>
|
|
110
131
|
);
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
-
import {
|
|
3
|
-
EnviveMetricsEventName,
|
|
4
|
-
SpiffyMetricsEventName,
|
|
5
|
-
} from '@envive-ai/react-hooks/contexts/amplitudeContext';
|
|
2
|
+
import { EnviveMetricsEventName } from '@envive-ai/react-hooks/contexts/amplitudeContext';
|
|
6
3
|
import { WidgetTypeV3 } from '@envive-ai/react-hooks/contexts/typesV3';
|
|
7
4
|
import { UserEvent, UserEventCategory } from '@spiffy-ai/commerce-api-client';
|
|
8
5
|
import { ProductCardWidget } from '../ProductCardWidget';
|
|
9
6
|
|
|
10
7
|
const mockTrackEvent = vi.fn();
|
|
11
8
|
const mockGetHardcopy = vi.fn();
|
|
9
|
+
const mockUseTrackComponentVisibleEvent = vi.fn();
|
|
12
10
|
|
|
13
11
|
vi.mock('@envive-ai/react-toolkit-v3/ProductCard', () => ({
|
|
14
12
|
ProductCard: ({ prompts, onSelect }: { prompts: string[]; onSelect: (text: string) => void }) => (
|
|
@@ -40,6 +38,10 @@ vi.mock('@envive-ai/react-hooks/contexts/amplitudeContext', () => ({
|
|
|
40
38
|
},
|
|
41
39
|
}));
|
|
42
40
|
|
|
41
|
+
vi.mock('@envive-ai/react-hooks/hooks/TrackComponentVisibleEvent', () => ({
|
|
42
|
+
useTrackComponentVisibleEvent: (...args: unknown[]) => mockUseTrackComponentVisibleEvent(...args),
|
|
43
|
+
}));
|
|
44
|
+
|
|
43
45
|
vi.mock('@envive-ai/react-hooks/contexts/hardcopyContext', () => ({
|
|
44
46
|
useHardcopy: () => ({
|
|
45
47
|
getHardcopy: mockGetHardcopy,
|
|
@@ -106,13 +108,15 @@ describe('ProductCardWidget analytics', () => {
|
|
|
106
108
|
|
|
107
109
|
await waitFor(
|
|
108
110
|
() => {
|
|
109
|
-
expect(
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
expect(mockUseTrackComponentVisibleEvent).toHaveBeenCalledWith(
|
|
112
|
+
expect.any(Object),
|
|
113
|
+
{
|
|
112
114
|
widget_config_id: 'test-config-1',
|
|
113
115
|
widget_type: WidgetTypeV3.ProductCardV3,
|
|
114
116
|
},
|
|
115
|
-
|
|
117
|
+
'0px',
|
|
118
|
+
true,
|
|
119
|
+
);
|
|
116
120
|
},
|
|
117
121
|
{ timeout: 3000 },
|
|
118
122
|
);
|
package/src/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.tsx
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
|
+
import { useSalesAgent } from '@envive-ai/react-hooks/contexts/salesAgentContext';
|
|
1
2
|
import {
|
|
2
3
|
PromptButtonCarouselWithImageWidgetV3Config,
|
|
3
4
|
WidgetTypeV3,
|
|
4
5
|
} from '@envive-ai/react-hooks/contexts/typesV3';
|
|
5
|
-
import { useSalesAgent } from '@envive-ai/react-hooks/contexts/salesAgentContext';
|
|
6
6
|
import { useChatToggle } from '@envive-ai/react-hooks/hooks/ChatToggle';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import {
|
|
9
|
+
ChatElementDisplayLocationV3,
|
|
10
|
+
VariantTypeEnum,
|
|
11
|
+
} from '@envive-ai/react-hooks/application/models';
|
|
12
|
+
import { variantInfoAtom } from '@envive-ai/react-hooks/atoms/app';
|
|
13
|
+
import { lastAssistantMessageAtom } from '@envive-ai/react-hooks/atoms/chat';
|
|
10
14
|
import {
|
|
11
15
|
EnviveMetricsEventName,
|
|
12
|
-
SpiffyMetricsEventName,
|
|
13
16
|
useAmplitude,
|
|
14
17
|
} from '@envive-ai/react-hooks/contexts/amplitudeContext';
|
|
18
|
+
import { useWidgetInteraction } from '@envive-ai/react-hooks/hooks/WidgetInteraction';
|
|
15
19
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from '@envive-ai/react-hooks/
|
|
20
|
+
WidgetInteractionComponent,
|
|
21
|
+
WidgetInteractionType,
|
|
22
|
+
} from '@envive-ai/react-hooks/hooks/WidgetInteraction/types';
|
|
19
23
|
import {
|
|
20
24
|
PromptButtonCarouselWithImage,
|
|
21
25
|
PromptButtonCarouselWithImageProps,
|
|
22
26
|
} from '@envive-ai/react-toolkit-v3/PromptButtonCarouselWithImage';
|
|
23
|
-
import {
|
|
27
|
+
import { usePromptCarouselAnalytics } from '@envive-ai/react-toolkit-v3/PromptCarousel';
|
|
28
|
+
import { Theme } from '@envive-ai/react-toolkit-v3/Tokens';
|
|
24
29
|
import { useAtomValue } from 'jotai';
|
|
25
|
-
import {
|
|
30
|
+
import { useCallback, useMemo } from 'react';
|
|
26
31
|
import { BaseWidgetProps } from '../../hocs/withBaseWidget/types';
|
|
27
32
|
import { withBaseWidget } from '../../hocs/withBaseWidget/withBaseWidget';
|
|
28
33
|
import { RawValues, getRecentProductImageUrls, getStringIdForText } from '../utils/functions';
|
|
@@ -30,6 +35,16 @@ import { RawValues, getRecentProductImageUrls, getStringIdForText } from '../uti
|
|
|
30
35
|
const PromptButtonCarouselWithImageWidgetHandler = (props: BaseWidgetProps) => {
|
|
31
36
|
const { onTypedMessageSubmitted } = useSalesAgent();
|
|
32
37
|
const { openChat } = useChatToggle();
|
|
38
|
+
const { trackWidgetInteraction } = useWidgetInteraction();
|
|
39
|
+
const {
|
|
40
|
+
onClick: onSuggestionClick,
|
|
41
|
+
onDrag,
|
|
42
|
+
onHover,
|
|
43
|
+
onMouseDown,
|
|
44
|
+
onMouseUp,
|
|
45
|
+
onTouchStart,
|
|
46
|
+
onTouchEnd,
|
|
47
|
+
} = usePromptCarouselAnalytics(WidgetInteractionComponent.SINGLE_IMAGE_PROMPT, text => text);
|
|
33
48
|
|
|
34
49
|
const { hardcopyContent, widgetConfig, isLoading, widgetConfigId } = props;
|
|
35
50
|
|
|
@@ -49,16 +64,6 @@ const PromptButtonCarouselWithImageWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
49
64
|
|
|
50
65
|
const { trackEvent } = useAmplitude();
|
|
51
66
|
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
trackEvent({
|
|
54
|
-
eventName: SpiffyMetricsEventName.ChatComponentVisible,
|
|
55
|
-
eventProps: {
|
|
56
|
-
widget_config_id: widgetConfigId,
|
|
57
|
-
widget_type: WidgetTypeV3.PromptButtonCarouselWithImageV3,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}, [trackEvent, widgetConfigId]);
|
|
61
|
-
|
|
62
67
|
const handlePromptButtonClick = useCallback(
|
|
63
68
|
(text: string) => {
|
|
64
69
|
const rawValues = (hardcopyContent as { rawValues?: RawValues } | undefined)?.rawValues;
|
|
@@ -78,12 +83,20 @@ const PromptButtonCarouselWithImageWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
78
83
|
ChatElementDisplayLocationV3.PROMPT_BUTTON_CAROUSEL_WITH_IMAGE_PROMPT_BUTTON,
|
|
79
84
|
});
|
|
80
85
|
openChat(ChatElementDisplayLocationV3.PROMPT_BUTTON_CAROUSEL_WITH_IMAGE_PROMPT_BUTTON);
|
|
86
|
+
onSuggestionClick(text);
|
|
81
87
|
},
|
|
82
88
|
[onTypedMessageSubmitted, openChat],
|
|
83
89
|
);
|
|
84
90
|
|
|
85
91
|
const handleTextFieldClick = useCallback(() => {
|
|
86
92
|
openChat(ChatElementDisplayLocationV3.PROMPT_BUTTON_CAROUSEL_WITH_IMAGE_TEXT_FIELD);
|
|
93
|
+
trackWidgetInteraction({
|
|
94
|
+
eventName: EnviveMetricsEventName.WidgetInteraction,
|
|
95
|
+
trigger: {
|
|
96
|
+
widget: WidgetInteractionComponent.SINGLE_IMAGE_PROMPT,
|
|
97
|
+
widget_interaction: WidgetInteractionType.QUERY_INPUT_CLICKED,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
87
100
|
}, [openChat]);
|
|
88
101
|
|
|
89
102
|
const variantInfo = useAtomValue(variantInfoAtom);
|
|
@@ -120,6 +133,12 @@ const PromptButtonCarouselWithImageWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
120
133
|
textFieldPlaceholder={hardCopyContent?.textFieldPlaceholder}
|
|
121
134
|
hideTextField={promptButtonCarouselWithImageWidgetConfig?.hideTextField}
|
|
122
135
|
handlePromptButtonClick={handlePromptButtonClick}
|
|
136
|
+
handlePromptButtonDrag={onDrag}
|
|
137
|
+
handlePromptButtonHover={onHover}
|
|
138
|
+
handlePromptButtonMouseDown={onMouseDown}
|
|
139
|
+
handlePromptButtonMouseUp={onMouseUp}
|
|
140
|
+
handlePromptButtonTouchStart={onTouchStart}
|
|
141
|
+
handlePromptButtonTouchEnd={onTouchEnd}
|
|
123
142
|
handleTextFieldClick={handleTextFieldClick}
|
|
124
143
|
/>
|
|
125
144
|
);
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
-
import {
|
|
3
|
-
EnviveMetricsEventName,
|
|
4
|
-
SpiffyMetricsEventName,
|
|
5
|
-
} from '@envive-ai/react-hooks/contexts/amplitudeContext';
|
|
2
|
+
import { EnviveMetricsEventName } from '@envive-ai/react-hooks/contexts/amplitudeContext';
|
|
6
3
|
import { WidgetTypeV3 } from '@envive-ai/react-hooks/contexts/typesV3';
|
|
7
4
|
import { UserEvent, UserEventCategory } from '@spiffy-ai/commerce-api-client';
|
|
8
5
|
import { PromptButtonCarouselWithImageWidget } from '../PromptButtonCarouselWithImageWidget';
|
|
9
6
|
|
|
10
7
|
const mockTrackEvent = vi.fn();
|
|
11
8
|
const mockGetHardcopy = vi.fn();
|
|
9
|
+
const mockUseTrackComponentVisibleEvent = vi.fn();
|
|
12
10
|
|
|
13
11
|
vi.mock('@envive-ai/react-toolkit-v3/PromptButtonCarouselWithImage', () => ({
|
|
14
12
|
PromptButtonCarouselWithImage: ({
|
|
@@ -46,6 +44,17 @@ vi.mock('@envive-ai/react-hooks/contexts/amplitudeContext', () => ({
|
|
|
46
44
|
},
|
|
47
45
|
}));
|
|
48
46
|
|
|
47
|
+
vi.mock('@envive-ai/react-hooks/hooks/TrackComponentVisibleEvent', () => ({
|
|
48
|
+
useTrackComponentVisibleEvent: (...args: unknown[]) => mockUseTrackComponentVisibleEvent(...args),
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
vi.mock('@envive-ai/react-hooks/hooks/WidgetInteraction', () => ({
|
|
52
|
+
useWidgetInteraction: () => ({
|
|
53
|
+
trackWidgetInteraction: vi.fn(),
|
|
54
|
+
getInteractionId: vi.fn(),
|
|
55
|
+
}),
|
|
56
|
+
}));
|
|
57
|
+
|
|
49
58
|
vi.mock('@envive-ai/react-hooks/contexts/hardcopyContext', () => ({
|
|
50
59
|
useHardcopy: () => ({
|
|
51
60
|
getHardcopy: mockGetHardcopy,
|
|
@@ -141,13 +150,15 @@ describe('PromptButtonCarouselWithImageWidget analytics', () => {
|
|
|
141
150
|
|
|
142
151
|
await waitFor(
|
|
143
152
|
() => {
|
|
144
|
-
expect(
|
|
145
|
-
|
|
146
|
-
|
|
153
|
+
expect(mockUseTrackComponentVisibleEvent).toHaveBeenCalledWith(
|
|
154
|
+
expect.any(Object),
|
|
155
|
+
{
|
|
147
156
|
widget_config_id: 'test-config-1',
|
|
148
157
|
widget_type: WidgetTypeV3.PromptButtonCarouselWithImageV3,
|
|
149
158
|
},
|
|
150
|
-
|
|
159
|
+
'0px',
|
|
160
|
+
true,
|
|
161
|
+
);
|
|
151
162
|
},
|
|
152
163
|
{ timeout: 3000 },
|
|
153
164
|
);
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PromptCarouselWidgetV3Config,
|
|
3
|
-
WidgetTypeV3,
|
|
4
|
-
} from '@envive-ai/react-hooks/contexts/typesV3';
|
|
5
|
-
import { PromptButtonVariant } from '@envive-ai/react-toolkit-v3/PromptButton/types';
|
|
6
1
|
import { ChatElementDisplayLocationV3 } from '@envive-ai/react-hooks/application/models';
|
|
7
|
-
import { useSalesAgent } from '@envive-ai/react-hooks/contexts/salesAgentContext';
|
|
8
|
-
import { useCallback, useEffect } from 'react';
|
|
9
2
|
import {
|
|
10
3
|
EnviveMetricsEventName,
|
|
11
|
-
SpiffyMetricsEventName,
|
|
12
4
|
useAmplitude,
|
|
13
5
|
} from '@envive-ai/react-hooks/contexts/amplitudeContext';
|
|
6
|
+
import { useSalesAgent } from '@envive-ai/react-hooks/contexts/salesAgentContext';
|
|
7
|
+
import {
|
|
8
|
+
PromptCarouselWidgetV3Config,
|
|
9
|
+
WidgetTypeV3,
|
|
10
|
+
} from '@envive-ai/react-hooks/contexts/typesV3';
|
|
11
|
+
import { PromptButtonVariant } from '@envive-ai/react-toolkit-v3/PromptButton/types';
|
|
12
|
+
import { useCallback } from 'react';
|
|
14
13
|
|
|
15
14
|
import { useChatToggle } from '@envive-ai/react-hooks/hooks/ChatToggle';
|
|
15
|
+
import { WidgetInteractionComponent } from '@envive-ai/react-hooks/hooks/WidgetInteraction/types';
|
|
16
|
+
import {
|
|
17
|
+
PromptCarousel,
|
|
18
|
+
usePromptCarouselAnalytics,
|
|
19
|
+
} from '@envive-ai/react-toolkit-v3/PromptCarousel';
|
|
16
20
|
import { AnimationSpeed } from '@envive-ai/react-toolkit-v3/PromptCarousel/types/types';
|
|
17
21
|
import { Theme } from '@envive-ai/react-toolkit-v3/Tokens';
|
|
18
|
-
import { PromptCarousel } from '@envive-ai/react-toolkit-v3/PromptCarousel';
|
|
19
22
|
import { BaseWidgetProps, withBaseWidget } from '../../hocs/withBaseWidget';
|
|
20
23
|
import { RawValues, getStringIdForText } from '../utils/functions';
|
|
21
24
|
|
|
@@ -33,6 +36,19 @@ const PromptCarouselWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
33
36
|
|
|
34
37
|
const { hardcopyContent, widgetConfig, isLoading, widgetConfigId } = props;
|
|
35
38
|
|
|
39
|
+
const {
|
|
40
|
+
onClick: onSuggestionClick,
|
|
41
|
+
onDrag,
|
|
42
|
+
onHover,
|
|
43
|
+
onMouseDown,
|
|
44
|
+
onMouseUp,
|
|
45
|
+
onTouchStart,
|
|
46
|
+
onTouchEnd,
|
|
47
|
+
} = usePromptCarouselAnalytics(WidgetInteractionComponent.SUGGESTION_BAR, text => {
|
|
48
|
+
const rawValues = (hardcopyContent as { rawValues?: RawValues } | undefined)?.rawValues;
|
|
49
|
+
return getStringIdForText(rawValues, text);
|
|
50
|
+
});
|
|
51
|
+
|
|
36
52
|
const promptButtonTexts = (hardcopyContent?.values?.promptButtonTexts as string[]) || [];
|
|
37
53
|
const buttonTexts = isLoading ? mockButtonTexts : promptButtonTexts;
|
|
38
54
|
|
|
@@ -48,20 +64,11 @@ const PromptCarouselWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
48
64
|
|
|
49
65
|
const { trackEvent } = useAmplitude();
|
|
50
66
|
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
trackEvent({
|
|
53
|
-
eventName: SpiffyMetricsEventName.ChatComponentVisible,
|
|
54
|
-
eventProps: {
|
|
55
|
-
widget_config_id: widgetConfigId,
|
|
56
|
-
widget_type: WidgetTypeV3.PromptCarouselV3,
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
}, [trackEvent, widgetConfigId]);
|
|
60
|
-
|
|
61
67
|
const handleButtonClick = useCallback(
|
|
62
68
|
(text: string) => {
|
|
63
69
|
const rawValues = (hardcopyContent as { rawValues?: RawValues } | undefined)?.rawValues;
|
|
64
70
|
const stringId = getStringIdForText(rawValues, text);
|
|
71
|
+
onSuggestionClick(stringId);
|
|
65
72
|
trackEvent({
|
|
66
73
|
eventName: EnviveMetricsEventName.WidgetTextClicked,
|
|
67
74
|
eventProps: {
|
|
@@ -91,6 +98,12 @@ const PromptCarouselWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
91
98
|
promptCarouselRows={promptCarouselRows}
|
|
92
99
|
animationSpeed={animationSpeed}
|
|
93
100
|
handleButtonClick={handleButtonClick}
|
|
101
|
+
handleButtonHover={onHover}
|
|
102
|
+
handleButtonDrag={onDrag}
|
|
103
|
+
handleButtonMouseUp={onMouseUp}
|
|
104
|
+
handleButtonMouseDown={onMouseDown}
|
|
105
|
+
handleButtonTouchStart={onTouchStart}
|
|
106
|
+
handleButtonTouchEnd={onTouchEnd}
|
|
94
107
|
promptButtonTexts={buttonTexts}
|
|
95
108
|
/>
|
|
96
109
|
);
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
-
import {
|
|
3
|
-
EnviveMetricsEventName,
|
|
4
|
-
SpiffyMetricsEventName,
|
|
5
|
-
} from '@envive-ai/react-hooks/contexts/amplitudeContext';
|
|
2
|
+
import { EnviveMetricsEventName } from '@envive-ai/react-hooks/contexts/amplitudeContext';
|
|
6
3
|
import { WidgetTypeV3 } from '@envive-ai/react-hooks/contexts/typesV3';
|
|
7
4
|
import { UserEvent, UserEventCategory } from '@spiffy-ai/commerce-api-client';
|
|
8
5
|
import { PromptCarouselWidget } from '../PromptCarouselWidget';
|
|
9
6
|
|
|
10
7
|
const mockTrackEvent = vi.fn();
|
|
11
8
|
const mockGetHardcopy = vi.fn();
|
|
9
|
+
const mockUseTrackComponentVisibleEvent = vi.fn();
|
|
12
10
|
|
|
13
11
|
vi.mock('@envive-ai/react-toolkit-v3/PromptCarousel', () => ({
|
|
14
12
|
PromptCarousel: ({
|
|
@@ -30,6 +28,15 @@ vi.mock('@envive-ai/react-toolkit-v3/PromptCarousel', () => ({
|
|
|
30
28
|
))}
|
|
31
29
|
</div>
|
|
32
30
|
),
|
|
31
|
+
usePromptCarouselAnalytics: () => ({
|
|
32
|
+
onClick: vi.fn(),
|
|
33
|
+
onDrag: vi.fn(),
|
|
34
|
+
onHover: vi.fn(),
|
|
35
|
+
onMouseDown: vi.fn(),
|
|
36
|
+
onMouseUp: vi.fn(),
|
|
37
|
+
onTouchStart: vi.fn(),
|
|
38
|
+
onTouchEnd: vi.fn(),
|
|
39
|
+
}),
|
|
33
40
|
}));
|
|
34
41
|
|
|
35
42
|
vi.mock('@envive-ai/react-hooks/contexts/amplitudeContext', () => ({
|
|
@@ -46,6 +53,10 @@ vi.mock('@envive-ai/react-hooks/contexts/amplitudeContext', () => ({
|
|
|
46
53
|
},
|
|
47
54
|
}));
|
|
48
55
|
|
|
56
|
+
vi.mock('@envive-ai/react-hooks/hooks/TrackComponentVisibleEvent', () => ({
|
|
57
|
+
useTrackComponentVisibleEvent: (...args: unknown[]) => mockUseTrackComponentVisibleEvent(...args),
|
|
58
|
+
}));
|
|
59
|
+
|
|
49
60
|
vi.mock('@envive-ai/react-hooks/contexts/hardcopyContext', () => ({
|
|
50
61
|
useHardcopy: () => ({
|
|
51
62
|
getHardcopy: mockGetHardcopy,
|
|
@@ -112,13 +123,15 @@ describe('PromptCarouselWidget analytics', () => {
|
|
|
112
123
|
|
|
113
124
|
await waitFor(
|
|
114
125
|
() => {
|
|
115
|
-
expect(
|
|
116
|
-
|
|
117
|
-
|
|
126
|
+
expect(mockUseTrackComponentVisibleEvent).toHaveBeenCalledWith(
|
|
127
|
+
expect.any(Object),
|
|
128
|
+
{
|
|
118
129
|
widget_config_id: 'test-config-1',
|
|
119
130
|
widget_type: WidgetTypeV3.PromptCarouselV3,
|
|
120
131
|
},
|
|
121
|
-
|
|
132
|
+
'0px',
|
|
133
|
+
true,
|
|
134
|
+
);
|
|
122
135
|
},
|
|
123
136
|
{ timeout: 3000 },
|
|
124
137
|
);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
1
2
|
import { SocialProofWidgetV3Config, WidgetTypeV3 } from '@envive-ai/react-hooks/contexts/typesV3';
|
|
2
3
|
import { useAtomValue, useSetAtom } from 'jotai';
|
|
3
4
|
import { useSalesAgent } from '@envive-ai/react-hooks/contexts/salesAgentContext';
|
|
4
5
|
import { useChatToggle } from '@envive-ai/react-hooks/hooks/ChatToggle';
|
|
5
|
-
import { lastAssistantMessageAtom } from '@envive-ai/react-hooks/atoms/chat';
|
|
6
6
|
import { variantInfoAtom } from '@envive-ai/react-hooks/atoms/app';
|
|
7
7
|
import {
|
|
8
8
|
PageVariant,
|
|
@@ -15,26 +15,41 @@ import {
|
|
|
15
15
|
ChatElementDisplayLocationV3,
|
|
16
16
|
VariantTypeEnum,
|
|
17
17
|
} from '@envive-ai/react-hooks/application/models';
|
|
18
|
-
import {
|
|
18
|
+
import { chatPreviewLoadingDataAtom } from '@envive-ai/react-hooks/atoms/widget';
|
|
19
19
|
import {
|
|
20
20
|
EnviveMetricsEventName,
|
|
21
|
-
SpiffyMetricsEventName,
|
|
22
21
|
useAmplitude,
|
|
23
22
|
} from '@envive-ai/react-hooks/contexts/amplitudeContext';
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
23
|
+
import { useWidgetInteraction } from '@envive-ai/react-hooks/hooks/WidgetInteraction';
|
|
24
|
+
import {
|
|
25
|
+
WidgetInteractionComponent,
|
|
26
|
+
WidgetInteractionType,
|
|
27
|
+
} from '@envive-ai/react-hooks/hooks/WidgetInteraction/types';
|
|
28
|
+
import { useProductImageUrl } from '@envive-ai/react-hooks/hooks/ProductImageUrl';
|
|
26
29
|
import { ChatPreviewLoading } from '@envive-ai/react-toolkit-v3/ChatPreviewLoading';
|
|
30
|
+
import { usePromptCarouselAnalytics } from '@envive-ai/react-toolkit-v3/PromptCarousel';
|
|
31
|
+
import { Theme } from '@envive-ai/react-toolkit-v3/Tokens';
|
|
32
|
+
|
|
27
33
|
import { BaseWidgetProps } from '../../hocs/withBaseWidget/types';
|
|
28
34
|
import { withBaseWidget } from '../../hocs/withBaseWidget/withBaseWidget';
|
|
29
|
-
import { RawValues,
|
|
35
|
+
import { RawValues, getStringIdForText } from '../utils/functions';
|
|
30
36
|
|
|
31
37
|
const SocialProofWidgetHandler = (props: BaseWidgetProps) => {
|
|
32
38
|
const setChatPreviewLoadingData = useSetAtom(chatPreviewLoadingDataAtom);
|
|
33
39
|
|
|
34
40
|
const { onTypedMessageSubmitted } = useSalesAgent();
|
|
35
41
|
const { openChat } = useChatToggle();
|
|
36
|
-
const lastAssistantMessage = useAtomValue(lastAssistantMessageAtom);
|
|
37
42
|
const variantInfo = useAtomValue(variantInfoAtom);
|
|
43
|
+
const { trackWidgetInteraction } = useWidgetInteraction();
|
|
44
|
+
const {
|
|
45
|
+
onClick: onSuggestionClick,
|
|
46
|
+
onHover,
|
|
47
|
+
onDrag,
|
|
48
|
+
onMouseDown,
|
|
49
|
+
onMouseUp,
|
|
50
|
+
onTouchStart,
|
|
51
|
+
onTouchEnd,
|
|
52
|
+
} = usePromptCarouselAnalytics(WidgetInteractionComponent.SOCIAL_PROOF, text => text);
|
|
38
53
|
|
|
39
54
|
const { hardcopyContent, widgetConfig, uiConfig, isLoading, widgetConfigId } = props;
|
|
40
55
|
|
|
@@ -82,7 +97,8 @@ const SocialProofWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
82
97
|
|
|
83
98
|
const hideLogo = uiConfig?.lookAndFeel?.hideWidgetLogo;
|
|
84
99
|
|
|
85
|
-
const
|
|
100
|
+
const productId = variantInfo.variant === VariantTypeEnum.Pdp ? variantInfo.productId : undefined;
|
|
101
|
+
const dynamicImageUrl = useProductImageUrl(productId);
|
|
86
102
|
|
|
87
103
|
const images =
|
|
88
104
|
socialProofWidgetConfig?.kind !== WidgetKind.DYNAMIC
|
|
@@ -91,16 +107,6 @@ const SocialProofWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
91
107
|
|
|
92
108
|
const { trackEvent } = useAmplitude();
|
|
93
109
|
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
trackEvent({
|
|
96
|
-
eventName: SpiffyMetricsEventName.ChatComponentVisible,
|
|
97
|
-
eventProps: {
|
|
98
|
-
widget_config_id: widgetConfigId,
|
|
99
|
-
widget_type: WidgetTypeV3.SocialProofV3,
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
}, [trackEvent, widgetConfigId]);
|
|
103
|
-
|
|
104
110
|
const handlePrimaryButtonClick = useCallback(
|
|
105
111
|
(text: string) => {
|
|
106
112
|
const rawValues = (hardcopyContent as { rawValues?: RawValues } | undefined)?.rawValues;
|
|
@@ -119,24 +125,70 @@ const SocialProofWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
119
125
|
displayLocation: ChatElementDisplayLocationV3.SOCIAL_PROOF_PRIMARY_BUTTON,
|
|
120
126
|
});
|
|
121
127
|
openChat(ChatElementDisplayLocationV3.SOCIAL_PROOF_PRIMARY_BUTTON);
|
|
128
|
+
|
|
129
|
+
trackWidgetInteraction({
|
|
130
|
+
eventName: EnviveMetricsEventName.WidgetInteraction,
|
|
131
|
+
trigger: {
|
|
132
|
+
widget: WidgetInteractionComponent.SOCIAL_PROOF,
|
|
133
|
+
widget_interaction: WidgetInteractionType.SUGGESTION_CLICKED,
|
|
134
|
+
widget_interaction_data: {
|
|
135
|
+
suggestion_clicked: {
|
|
136
|
+
suggestion_id: text,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
});
|
|
122
141
|
},
|
|
123
142
|
[onTypedMessageSubmitted, openChat],
|
|
124
143
|
);
|
|
125
144
|
|
|
145
|
+
const handlePrimaryButtonHover = useCallback((text: string) => {
|
|
146
|
+
trackWidgetInteraction({
|
|
147
|
+
eventName: EnviveMetricsEventName.WidgetInteraction,
|
|
148
|
+
trigger: {
|
|
149
|
+
widget: WidgetInteractionComponent.SOCIAL_PROOF,
|
|
150
|
+
widget_interaction: WidgetInteractionType.WIDGET_HOVERED,
|
|
151
|
+
widget_interaction_data: {
|
|
152
|
+
suggestion_hovered: {
|
|
153
|
+
suggestion_id: text,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
}, []);
|
|
159
|
+
|
|
126
160
|
const handleSecondaryButtonClick = useCallback(
|
|
127
161
|
(text: string) => {
|
|
162
|
+
const rawValues = (hardcopyContent as { rawValues?: RawValues } | undefined)?.rawValues;
|
|
163
|
+
const stringId = getStringIdForText(rawValues, text);
|
|
164
|
+
trackEvent({
|
|
165
|
+
eventName: EnviveMetricsEventName.WidgetTextClicked,
|
|
166
|
+
eventProps: {
|
|
167
|
+
response_id: hardcopyContent?.responseId,
|
|
168
|
+
string_id: stringId,
|
|
169
|
+
text,
|
|
170
|
+
},
|
|
171
|
+
});
|
|
128
172
|
onTypedMessageSubmitted({
|
|
129
173
|
query: text,
|
|
130
174
|
userTyped: false,
|
|
131
175
|
displayLocation: ChatElementDisplayLocationV3.SOCIAL_PROOF_SECONDARY_BUTTON,
|
|
132
176
|
});
|
|
133
177
|
openChat(ChatElementDisplayLocationV3.SOCIAL_PROOF_SECONDARY_BUTTON);
|
|
178
|
+
onSuggestionClick(text);
|
|
134
179
|
},
|
|
135
180
|
[onTypedMessageSubmitted, openChat],
|
|
136
181
|
);
|
|
137
182
|
|
|
138
183
|
const handleTextFieldClick = useCallback(() => {
|
|
139
184
|
openChat(ChatElementDisplayLocationV3.SOCIAL_PROOF_TEXT_FIELD);
|
|
185
|
+
trackWidgetInteraction({
|
|
186
|
+
eventName: EnviveMetricsEventName.WidgetInteraction,
|
|
187
|
+
trigger: {
|
|
188
|
+
widget: WidgetInteractionComponent.SOCIAL_PROOF,
|
|
189
|
+
widget_interaction: WidgetInteractionType.QUERY_INPUT_CLICKED,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
140
192
|
}, [openChat]);
|
|
141
193
|
|
|
142
194
|
if (isLoading) {
|
|
@@ -185,7 +237,14 @@ const SocialProofWidgetHandler = (props: BaseWidgetProps) => {
|
|
|
185
237
|
|
|
186
238
|
const widgetEventProps: SocialProofProps['widgetEventProps'] = {
|
|
187
239
|
handlePrimaryButtonClick,
|
|
240
|
+
handlePrimaryButtonHover,
|
|
188
241
|
handleSecondaryButtonClick,
|
|
242
|
+
handleSecondaryButtonHover: onHover,
|
|
243
|
+
handleSecondaryButtonDrag: onDrag,
|
|
244
|
+
handleSecondaryButtonMouseDown: onMouseDown,
|
|
245
|
+
handleSecondaryButtonMouseUp: onMouseUp,
|
|
246
|
+
handleSecondaryButtonTouchStart: onTouchStart,
|
|
247
|
+
handleSecondaryButtonTouchEnd: onTouchEnd,
|
|
189
248
|
handleTextFieldClick,
|
|
190
249
|
};
|
|
191
250
|
|