@envive-ai/react-widgets-v3 0.3.20 → 0.3.22

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.
Files changed (66) hide show
  1. package/dist/hocs/withBaseWidget/types.d.cts +5 -6
  2. package/dist/hocs/withBaseWidget/types.d.ts +5 -6
  3. package/dist/hocs/withBaseWidget/withBaseWidget.cjs +37 -43
  4. package/dist/hocs/withBaseWidget/withBaseWidget.d.ts +2 -2
  5. package/dist/hocs/withBaseWidget/withBaseWidget.js +39 -45
  6. package/dist/packages/widgets/dist/SearchResults/SearchResultsWidget.d.ts +2 -2
  7. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.cts +3 -3
  8. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.ts +3 -3
  9. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.d.cts +3 -3
  10. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.d.ts +3 -3
  11. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.cjs +0 -9
  12. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.d.cts +3 -3
  13. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.d.ts +3 -3
  14. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.js +2 -11
  15. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.cjs +24 -28
  16. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.d.cts +2 -2
  17. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.d.ts +2 -2
  18. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.js +25 -29
  19. package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.d.ts +2 -2
  20. package/dist/widgets/ProductCardWidget/ProductCardWidget.cjs +0 -10
  21. package/dist/widgets/ProductCardWidget/ProductCardWidget.d.cts +2 -2
  22. package/dist/widgets/ProductCardWidget/ProductCardWidget.d.ts +2 -2
  23. package/dist/widgets/ProductCardWidget/ProductCardWidget.js +2 -12
  24. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.cjs +0 -9
  25. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.d.cts +3 -3
  26. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.d.ts +3 -3
  27. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.js +2 -11
  28. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.cjs +0 -9
  29. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.d.cts +2 -2
  30. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.d.ts +2 -2
  31. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.js +2 -11
  32. package/dist/widgets/SocialProofWidget/SocialProofWidget.cjs +0 -9
  33. package/dist/widgets/SocialProofWidget/SocialProofWidget.d.cts +3 -3
  34. package/dist/widgets/SocialProofWidget/SocialProofWidget.d.ts +3 -3
  35. package/dist/widgets/SocialProofWidget/SocialProofWidget.js +2 -11
  36. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.cjs +0 -9
  37. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.d.cts +2 -2
  38. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.d.ts +2 -2
  39. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.js +2 -11
  40. package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.d.cts +2 -2
  41. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.cjs +0 -9
  42. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.d.cts +3 -3
  43. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.d.ts +3 -3
  44. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.js +2 -11
  45. package/dist/widgets/dist/SearchResults/SearchResultsWidget.d.cts +2 -2
  46. package/package.json +1 -1
  47. package/src/hocs/withBaseWidget/__tests__/withBaseWidget.test.tsx +68 -302
  48. package/src/hocs/withBaseWidget/types.ts +6 -6
  49. package/src/hocs/withBaseWidget/withBaseWidget.tsx +46 -61
  50. package/src/widgets/ChatPreviewWidget/ChatPreviewWidget.tsx +1 -13
  51. package/src/widgets/ChatPreviewWidget/__tests__/ChatPreviewWidget.test.tsx +11 -5
  52. package/src/widgets/FloatingChatWidget/FloatingChatWidget.tsx +36 -36
  53. package/src/widgets/FloatingChatWidget/__tests__/FloatingChatWidget.test.tsx +11 -5
  54. package/src/widgets/ProductCardWidget/ProductCardWidget.tsx +1 -13
  55. package/src/widgets/ProductCardWidget/__tests__/ProductCardWidget.test.tsx +12 -8
  56. package/src/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.tsx +1 -12
  57. package/src/widgets/PromptButtonCarouselWithImageWidget/__tests__/PromptButtonCarouselWithImageWidget.test.tsx +19 -8
  58. package/src/widgets/PromptCarouselWidget/PromptCarouselWidget.tsx +1 -12
  59. package/src/widgets/PromptCarouselWidget/__tests__/PromptCarouselWidget.test.tsx +21 -8
  60. package/src/widgets/SocialProofWidget/SocialProofWidget.tsx +1 -12
  61. package/src/widgets/SocialProofWidget/__tests__/SocialProofWidget.test.tsx +19 -8
  62. package/src/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.tsx +1 -12
  63. package/src/widgets/TitledPromptCarouselWidget/__tests__/TitledPromptCarouselWidget.test.tsx +19 -8
  64. package/src/widgets/TypingAnimationWidget/TypingAnimationWidget.tsx +1 -12
  65. package/src/widgets/TypingAnimationWidget/__tests__/TypingAnimationWidget.test.tsx +19 -8
  66. package/src/widgets/__tests__/trackEventCanary.test.ts +1 -1
@@ -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 { ChatPreviewWidget } from '../ChatPreviewWidget';
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/ChatPreview', () => ({
11
11
  ChatPreview: () => <div data-testid="chat-preview-mock">Chat Preview</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,
@@ -100,13 +104,15 @@ describe('ChatPreviewWidget analytics', () => {
100
104
 
101
105
  await waitFor(
102
106
  () => {
103
- expect(mockTrackEvent).toHaveBeenCalledWith({
104
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
105
- eventProps: {
107
+ expect(mockUseTrackComponentVisibleEvent).toHaveBeenCalledWith(
108
+ expect.any(Object),
109
+ {
106
110
  widget_config_id: 'test-config-1',
107
111
  widget_type: WidgetTypeV3.ChatPreviewV3,
108
112
  },
109
- });
113
+ '0px',
114
+ true,
115
+ );
110
116
  },
111
117
  { timeout: 3000 },
112
118
  );
@@ -1,7 +1,6 @@
1
1
  import { ChatElementDisplayLocationV3 } from '@envive-ai/react-hooks/application/models';
2
2
  import {
3
3
  EnviveMetricsEventName,
4
- SpiffyMetricsEventName,
5
4
  useAmplitude,
6
5
  } from '@envive-ai/react-hooks/contexts/amplitudeContext';
7
6
  import { useSalesAgent } from '@envive-ai/react-hooks/contexts/salesAgentContext';
@@ -11,6 +10,7 @@ import {
11
10
  WidgetTypeV3,
12
11
  } from '@envive-ai/react-hooks/contexts/typesV3';
13
12
  import { useChatToggle } from '@envive-ai/react-hooks/hooks/ChatToggle';
13
+ import { useTrackComponentVisibleEvent } from '@envive-ai/react-hooks/hooks/TrackComponentVisibleEvent';
14
14
  import { useWidgetInteraction } from '@envive-ai/react-hooks/hooks/WidgetInteraction';
15
15
  import {
16
16
  Collapse,
@@ -139,21 +139,17 @@ const FloatingChatWidgetHandler = (props: FloatingChatWidgetHandlerProps) => {
139
139
 
140
140
  useAutoPopup({ autoPopupConfig: floatingChat?.autoPopupConfig });
141
141
 
142
- const { trackEvent } = useAmplitude();
143
- const hasTrackedEvent = useRef(false);
144
- // When we add support for initially hidden floating buttons, we will need to update this to handle that case
145
- useEffect(() => {
146
- if (buttonShouldRender && !hasTrackedEvent.current) {
147
- trackEvent({
148
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
149
- eventProps: {
150
- widget_config_id: 'floating-button',
151
- widget_type: WidgetTypeV3.FloatingButtonV3,
152
- },
153
- });
154
- hasTrackedEvent.current = true;
155
- }
156
- }, [trackEvent, buttonShouldRender]);
142
+ const { isReady } = useAmplitude();
143
+ const floatingButtonVisibilityRef = useRef<HTMLDivElement>(null);
144
+ useTrackComponentVisibleEvent(
145
+ floatingButtonVisibilityRef,
146
+ {
147
+ widget_config_id: 'floating-button',
148
+ widget_type: WidgetTypeV3.FloatingButtonV3,
149
+ },
150
+ '0px',
151
+ isReady && buttonShouldRender,
152
+ );
157
153
 
158
154
  return (
159
155
  <CXButtonProvider
@@ -222,24 +218,26 @@ const FloatingChatWidgetHandler = (props: FloatingChatWidgetHandlerProps) => {
222
218
 
223
219
  {/* Render button when preview button only OR when chat is closed */}
224
220
  {buttonShouldRender && (
225
- <FloatingButton
226
- id={FLOATING_BUTTON_ID}
227
- variant={floatingButton?.style as FloatingButtonVariant}
228
- mode={floatingButton?.mode as FloatingButtonMode}
229
- backgroundColor={floatingButton?.backgroundColor as FloatingButtonBackgroundColor}
230
- onClick={
231
- previewButtonOnly
232
- ? () => {}
233
- : () => openChat(ChatElementDisplayLocationV3.FLOATING_BUTTON)
234
- }
235
- onMouseOver={onHover}
236
- customIcon={floatingButton?.iconSVGSrc}
237
- show={floatingButton?.showOption as FloatingButtonShow}
238
- location={floatingButton?.position as FloatingButtonLocation}
239
- hasInteractionHappened={userHasInteractedValue}
240
- ariaLabel="Open chat"
241
- previewMode={!!previewButtonOnly}
242
- />
221
+ <div ref={floatingButtonVisibilityRef}>
222
+ <FloatingButton
223
+ id={FLOATING_BUTTON_ID}
224
+ variant={floatingButton?.style as FloatingButtonVariant}
225
+ mode={floatingButton?.mode as FloatingButtonMode}
226
+ backgroundColor={floatingButton?.backgroundColor as FloatingButtonBackgroundColor}
227
+ onClick={
228
+ previewButtonOnly
229
+ ? () => {}
230
+ : () => openChat(ChatElementDisplayLocationV3.FLOATING_BUTTON)
231
+ }
232
+ onMouseOver={onHover}
233
+ customIcon={floatingButton?.iconSVGSrc}
234
+ show={floatingButton?.showOption as FloatingButtonShow}
235
+ location={floatingButton?.position as FloatingButtonLocation}
236
+ hasInteractionHappened={userHasInteractedValue}
237
+ ariaLabel="Open chat"
238
+ previewMode={!!previewButtonOnly}
239
+ />
240
+ </div>
243
241
  )}
244
242
  </>
245
243
  )}
@@ -247,8 +245,10 @@ const FloatingChatWidgetHandler = (props: FloatingChatWidgetHandlerProps) => {
247
245
  );
248
246
  };
249
247
 
250
- const FloatingChatWidgetWithBaseWidget =
251
- withBaseWidget<FloatingChatWidgetHandlerProps>(FloatingChatWidgetHandler);
248
+ const FloatingChatWidgetWithBaseWidget = withBaseWidget<FloatingChatWidgetHandlerProps>(
249
+ FloatingChatWidgetHandler,
250
+ { deferLoading: false },
251
+ );
252
252
 
253
253
  export interface FloatingChatWidgetProps {
254
254
  previewButtonOnly?: boolean;
@@ -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(mockTrackEvent).toHaveBeenCalledWith({
109
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
110
- eventProps: {
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,7 +1,6 @@
1
1
  import { ChatElementDisplayLocationV3 } from '@envive-ai/react-hooks/application/models';
2
2
  import {
3
3
  EnviveMetricsEventName,
4
- SpiffyMetricsEventName,
5
4
  useAmplitude,
6
5
  } from '@envive-ai/react-hooks/contexts/amplitudeContext';
7
6
  import { useSalesAgent } from '@envive-ai/react-hooks/contexts/salesAgentContext';
@@ -16,7 +15,7 @@ import { ProductCard } from '@envive-ai/react-toolkit-v3/ProductCard';
16
15
  import { PromptButtonVariant } from '@envive-ai/react-toolkit-v3/PromptButton/types';
17
16
  import { usePromptCarouselAnalytics } from '@envive-ai/react-toolkit-v3/PromptCarousel';
18
17
  import { Theme } from '@envive-ai/react-toolkit-v3/Tokens';
19
- import { useCallback, useEffect } from 'react';
18
+ import { useCallback } from 'react';
20
19
  import { BaseWidgetProps, withBaseWidget } from '../../hocs/withBaseWidget';
21
20
  import { RawValues, getStringIdForText } from '../utils/functions';
22
21
 
@@ -72,17 +71,6 @@ const ProductCardWidgetHandler = (props: BaseWidgetProps) => {
72
71
  return getStringIdForText(rawValues, text);
73
72
  });
74
73
 
75
- const { widgetConfigId } = props;
76
- useEffect(() => {
77
- trackEvent({
78
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
79
- eventProps: {
80
- widget_config_id: widgetConfigId,
81
- widget_type: WidgetTypeV3.ProductCardV3,
82
- },
83
- });
84
- }, [trackEvent, widgetConfigId]);
85
-
86
74
  const handleSelect = useCallback(
87
75
  (text: string) => {
88
76
  const rawValues = (hardcopyContent as { rawValues?: RawValues } | undefined)?.rawValues;
@@ -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(mockTrackEvent).toHaveBeenCalledWith({
110
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
111
- eventProps: {
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
  );
@@ -13,7 +13,6 @@ import { variantInfoAtom } from '@envive-ai/react-hooks/atoms/app';
13
13
  import { lastAssistantMessageAtom } from '@envive-ai/react-hooks/atoms/chat';
14
14
  import {
15
15
  EnviveMetricsEventName,
16
- SpiffyMetricsEventName,
17
16
  useAmplitude,
18
17
  } from '@envive-ai/react-hooks/contexts/amplitudeContext';
19
18
  import { useWidgetInteraction } from '@envive-ai/react-hooks/hooks/WidgetInteraction';
@@ -28,7 +27,7 @@ import {
28
27
  import { usePromptCarouselAnalytics } from '@envive-ai/react-toolkit-v3/PromptCarousel';
29
28
  import { Theme } from '@envive-ai/react-toolkit-v3/Tokens';
30
29
  import { useAtomValue } from 'jotai';
31
- import { useCallback, useEffect, useMemo } from 'react';
30
+ import { useCallback, useMemo } from 'react';
32
31
  import { BaseWidgetProps } from '../../hocs/withBaseWidget/types';
33
32
  import { withBaseWidget } from '../../hocs/withBaseWidget/withBaseWidget';
34
33
  import { RawValues, getRecentProductImageUrls, getStringIdForText } from '../utils/functions';
@@ -65,16 +64,6 @@ const PromptButtonCarouselWithImageWidgetHandler = (props: BaseWidgetProps) => {
65
64
 
66
65
  const { trackEvent } = useAmplitude();
67
66
 
68
- useEffect(() => {
69
- trackEvent({
70
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
71
- eventProps: {
72
- widget_config_id: widgetConfigId,
73
- widget_type: WidgetTypeV3.PromptButtonCarouselWithImageV3,
74
- },
75
- });
76
- }, [trackEvent, widgetConfigId]);
77
-
78
67
  const handlePromptButtonClick = useCallback(
79
68
  (text: string) => {
80
69
  const rawValues = (hardcopyContent as { rawValues?: RawValues } | undefined)?.rawValues;
@@ -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(mockTrackEvent).toHaveBeenCalledWith({
145
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
146
- eventProps: {
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,7 +1,6 @@
1
1
  import { ChatElementDisplayLocationV3 } from '@envive-ai/react-hooks/application/models';
2
2
  import {
3
3
  EnviveMetricsEventName,
4
- SpiffyMetricsEventName,
5
4
  useAmplitude,
6
5
  } from '@envive-ai/react-hooks/contexts/amplitudeContext';
7
6
  import { useSalesAgent } from '@envive-ai/react-hooks/contexts/salesAgentContext';
@@ -10,7 +9,7 @@ import {
10
9
  WidgetTypeV3,
11
10
  } from '@envive-ai/react-hooks/contexts/typesV3';
12
11
  import { PromptButtonVariant } from '@envive-ai/react-toolkit-v3/PromptButton/types';
13
- import { useCallback, useEffect } from 'react';
12
+ import { useCallback } from 'react';
14
13
 
15
14
  import { useChatToggle } from '@envive-ai/react-hooks/hooks/ChatToggle';
16
15
  import { WidgetInteractionComponent } from '@envive-ai/react-hooks/hooks/WidgetInteraction/types';
@@ -65,16 +64,6 @@ const PromptCarouselWidgetHandler = (props: BaseWidgetProps) => {
65
64
 
66
65
  const { trackEvent } = useAmplitude();
67
66
 
68
- useEffect(() => {
69
- trackEvent({
70
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
71
- eventProps: {
72
- widget_config_id: widgetConfigId,
73
- widget_type: WidgetTypeV3.PromptCarouselV3,
74
- },
75
- });
76
- }, [trackEvent, widgetConfigId]);
77
-
78
67
  const handleButtonClick = useCallback(
79
68
  (text: string) => {
80
69
  const rawValues = (hardcopyContent as { rawValues?: RawValues } | undefined)?.rawValues;
@@ -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(mockTrackEvent).toHaveBeenCalledWith({
116
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
117
- eventProps: {
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,4 +1,4 @@
1
- import { useCallback, useEffect, useMemo } from 'react';
1
+ import { useCallback, useMemo } from 'react';
2
2
  import { SocialProofWidgetV3Config, WidgetTypeV3 } from '@envive-ai/react-hooks/contexts/typesV3';
3
3
  import { useAtomValue, useSetAtom } from 'jotai';
4
4
  import { useSalesAgent } from '@envive-ai/react-hooks/contexts/salesAgentContext';
@@ -18,7 +18,6 @@ import {
18
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
23
  import { useWidgetInteraction } from '@envive-ai/react-hooks/hooks/WidgetInteraction';
@@ -108,16 +107,6 @@ const SocialProofWidgetHandler = (props: BaseWidgetProps) => {
108
107
 
109
108
  const { trackEvent } = useAmplitude();
110
109
 
111
- useEffect(() => {
112
- trackEvent({
113
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
114
- eventProps: {
115
- widget_config_id: widgetConfigId,
116
- widget_type: WidgetTypeV3.SocialProofV3,
117
- },
118
- });
119
- }, [trackEvent, widgetConfigId]);
120
-
121
110
  const handlePrimaryButtonClick = useCallback(
122
111
  (text: string) => {
123
112
  const rawValues = (hardcopyContent as { rawValues?: RawValues } | undefined)?.rawValues;
@@ -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 { SocialProofWidget } from '../SocialProofWidget';
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/SocialProof', async importOriginal => {
14
12
  const actual = await importOriginal();
@@ -52,6 +50,17 @@ vi.mock('@envive-ai/react-hooks/contexts/amplitudeContext', () => ({
52
50
  },
53
51
  }));
54
52
 
53
+ vi.mock('@envive-ai/react-hooks/hooks/TrackComponentVisibleEvent', () => ({
54
+ useTrackComponentVisibleEvent: (...args: unknown[]) => mockUseTrackComponentVisibleEvent(...args),
55
+ }));
56
+
57
+ vi.mock('@envive-ai/react-hooks/hooks/WidgetInteraction', () => ({
58
+ useWidgetInteraction: () => ({
59
+ trackWidgetInteraction: vi.fn(),
60
+ getInteractionId: vi.fn(),
61
+ }),
62
+ }));
63
+
55
64
  vi.mock('@envive-ai/react-hooks/contexts/hardcopyContext', () => ({
56
65
  useHardcopy: () => ({
57
66
  getHardcopy: mockGetHardcopy,
@@ -146,13 +155,15 @@ describe('SocialProofWidget analytics', () => {
146
155
 
147
156
  await waitFor(
148
157
  () => {
149
- expect(mockTrackEvent).toHaveBeenCalledWith({
150
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
151
- eventProps: {
158
+ expect(mockUseTrackComponentVisibleEvent).toHaveBeenCalledWith(
159
+ expect.any(Object),
160
+ {
152
161
  widget_config_id: 'test-config-1',
153
162
  widget_type: WidgetTypeV3.SocialProofV3,
154
163
  },
155
- });
164
+ '0px',
165
+ true,
166
+ );
156
167
  },
157
168
  { timeout: 3000 },
158
169
  );
@@ -1,7 +1,6 @@
1
1
  import { ChatElementDisplayLocationV3 } from '@envive-ai/react-hooks/application/models';
2
2
  import {
3
3
  EnviveMetricsEventName,
4
- SpiffyMetricsEventName,
5
4
  useAmplitude,
6
5
  } from '@envive-ai/react-hooks/contexts/amplitudeContext';
7
6
  import { useSalesAgent } from '@envive-ai/react-hooks/contexts/salesAgentContext';
@@ -10,7 +9,7 @@ import {
10
9
  WidgetTypeV3,
11
10
  } from '@envive-ai/react-hooks/contexts/typesV3';
12
11
  import { PromptButtonVariant } from '@envive-ai/react-toolkit-v3/PromptButton/types';
13
- import { useCallback, useEffect } from 'react';
12
+ import { useCallback } from 'react';
14
13
 
15
14
  import { useChatToggle } from '@envive-ai/react-hooks/hooks/ChatToggle';
16
15
  import { WidgetInteractionComponent } from '@envive-ai/react-hooks/hooks/WidgetInteraction/types';
@@ -65,16 +64,6 @@ const TitledPromptCarouselWidgetHandler = (props: BaseWidgetProps) => {
65
64
 
66
65
  const { trackEvent } = useAmplitude();
67
66
 
68
- useEffect(() => {
69
- trackEvent({
70
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
71
- eventProps: {
72
- widget_config_id: widgetConfigId,
73
- widget_type: WidgetTypeV3.TitledPromptCarouselV3,
74
- },
75
- });
76
- }, [trackEvent, widgetConfigId]);
77
-
78
67
  const handleButtonClick = useCallback(
79
68
  (text: string) => {
80
69
  const rawValues = (hardcopyContent as { rawValues?: RawValues } | undefined)?.rawValues;
@@ -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 { TitledPromptCarouselWidget } from '../TitledPromptCarouselWidget';
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/TitledPromptCarousel', () => ({
14
12
  TitledPromptCarousel: ({
@@ -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,
@@ -112,13 +121,15 @@ describe('TitledPromptCarouselWidget analytics', () => {
112
121
 
113
122
  await waitFor(
114
123
  () => {
115
- expect(mockTrackEvent).toHaveBeenCalledWith({
116
- eventName: SpiffyMetricsEventName.ChatComponentVisible,
117
- eventProps: {
124
+ expect(mockUseTrackComponentVisibleEvent).toHaveBeenCalledWith(
125
+ expect.any(Object),
126
+ {
118
127
  widget_config_id: 'test-config-1',
119
128
  widget_type: WidgetTypeV3.TitledPromptCarouselV3,
120
129
  },
121
- });
130
+ '0px',
131
+ true,
132
+ );
122
133
  },
123
134
  { timeout: 3000 },
124
135
  );