@envive-ai/react-hooks 0.3.13 → 0.3.15-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/application/commerce-api.cjs +1 -1
  2. package/dist/application/commerce-api.js +1 -1
  3. package/dist/application/models/featureGates.cjs +4 -1
  4. package/dist/application/models/featureGates.d.cts +4 -1
  5. package/dist/application/models/featureGates.d.ts +4 -1
  6. package/dist/application/models/featureGates.js +4 -1
  7. package/dist/atoms/app/index.d.cts +7 -7
  8. package/dist/atoms/app/index.d.ts +1 -1
  9. package/dist/atoms/app/variant.d.cts +6 -6
  10. package/dist/atoms/app/variant.d.ts +6 -6
  11. package/dist/atoms/chat/chatState.d.cts +18 -18
  12. package/dist/atoms/chat/chatState.d.ts +1 -1
  13. package/dist/atoms/chat/form.d.cts +3 -3
  14. package/dist/atoms/chat/form.d.ts +2 -2
  15. package/dist/atoms/chat/index.d.cts +3 -3
  16. package/dist/atoms/chat/index.d.ts +2 -2
  17. package/dist/atoms/chat/lastMessage.d.cts +2 -2
  18. package/dist/atoms/chat/lastMessage.d.ts +2 -2
  19. package/dist/atoms/chat/messageQueue.d.cts +6 -6
  20. package/dist/atoms/chat/messageQueue.d.ts +6 -6
  21. package/dist/atoms/chat/performanceMetrics.d.cts +7 -7
  22. package/dist/atoms/chat/performanceMetrics.d.ts +6 -6
  23. package/dist/atoms/chat/renderedWidgetRefs.d.cts +2 -2
  24. package/dist/atoms/chat/renderedWidgetRefs.d.ts +2 -2
  25. package/dist/atoms/chat/replies.d.cts +3 -3
  26. package/dist/atoms/chat/replies.d.ts +3 -3
  27. package/dist/atoms/chat/suggestions.d.cts +2 -2
  28. package/dist/atoms/chat/suggestions.d.ts +2 -2
  29. package/dist/atoms/envive/enviveConfig.d.cts +13 -13
  30. package/dist/atoms/envive/enviveConfig.d.ts +13 -13
  31. package/dist/atoms/globalSearch/globalSearch.d.cts +5 -5
  32. package/dist/atoms/globalSearch/globalSearch.d.ts +5 -5
  33. package/dist/atoms/org/customerService.d.cts +6 -6
  34. package/dist/atoms/org/customerService.d.ts +6 -6
  35. package/dist/atoms/org/graphqlConfig.d.cts +4 -4
  36. package/dist/atoms/org/graphqlConfig.d.ts +4 -4
  37. package/dist/atoms/org/newOrgConfigAtom.d.cts +2 -2
  38. package/dist/atoms/org/newOrgConfigAtom.d.ts +3 -3
  39. package/dist/atoms/org/orgAnalyticsConfig.d.cts +5 -5
  40. package/dist/atoms/org/orgAnalyticsConfig.d.ts +6 -6
  41. package/dist/atoms/search/chatSearch.d.cts +17 -17
  42. package/dist/atoms/search/chatSearch.d.ts +17 -17
  43. package/dist/atoms/search/searchAPI.d.cts +13 -13
  44. package/dist/atoms/search/searchAPI.d.ts +13 -13
  45. package/dist/atoms/search/utils.d.cts +1 -1
  46. package/dist/atoms/search/utils.d.ts +1 -1
  47. package/dist/atoms/widget/chatPreviewLoading.d.cts +2 -2
  48. package/dist/atoms/widget/chatPreviewLoading.d.ts +2 -2
  49. package/dist/contexts/hardcopyContext/hardcopyContext.cjs +4 -2
  50. package/dist/contexts/hardcopyContext/hardcopyContext.js +4 -2
  51. package/dist/contexts/pageContext/types.d.cts +1 -1
  52. package/dist/contexts/salesAgentContext/chatAPI.cjs +21 -1
  53. package/dist/contexts/salesAgentContext/chatAPI.js +21 -1
  54. package/dist/contexts/systemSettingsContext/systemSettingsContext.d.ts +2 -2
  55. package/dist/contexts/types.d.cts +1 -1
  56. package/dist/contexts/types.d.ts +1 -1
  57. package/dist/contexts/typesV3.d.cts +1 -1
  58. package/dist/contexts/typesV3.d.ts +1 -1
  59. package/dist/hooks/ChatToggle/useChatToggle.cjs +47 -17
  60. package/dist/hooks/ChatToggle/useChatToggle.d.cts +2 -1
  61. package/dist/hooks/ChatToggle/useChatToggle.d.ts +2 -1
  62. package/dist/hooks/ChatToggle/useChatToggle.js +48 -18
  63. package/dist/hooks/GrabAndScroll/useGrabAndScroll.d.ts +2 -2
  64. package/dist/hooks/ShopifyUrlOperations/useShopifyUrlOperations.d.cts +2 -2
  65. package/dist/hooks/ShopifyUrlOperations/useShopifyUrlOperations.d.ts +2 -2
  66. package/dist/hooks/SystemSettingsContext/useSystemSettingsContext.d.ts +2 -2
  67. package/dist/hooks/WidgetInteraction/index.cjs +3 -0
  68. package/dist/hooks/WidgetInteraction/index.d.cts +2 -0
  69. package/dist/hooks/WidgetInteraction/index.d.ts +2 -0
  70. package/dist/hooks/WidgetInteraction/index.js +3 -0
  71. package/dist/hooks/WidgetInteraction/types.cjs +47 -0
  72. package/dist/hooks/WidgetInteraction/types.d.cts +110 -0
  73. package/dist/hooks/WidgetInteraction/types.d.ts +110 -0
  74. package/dist/hooks/WidgetInteraction/types.js +44 -0
  75. package/dist/hooks/WidgetInteraction/useWidgetInteraction.cjs +34 -0
  76. package/dist/hooks/WidgetInteraction/useWidgetInteraction.d.cts +10 -0
  77. package/dist/hooks/WidgetInteraction/useWidgetInteraction.d.ts +10 -0
  78. package/dist/hooks/WidgetInteraction/useWidgetInteraction.js +33 -0
  79. package/dist/hooks/WidgetInteraction/utils.cjs +34 -0
  80. package/dist/hooks/WidgetInteraction/utils.d.cts +8 -0
  81. package/dist/hooks/WidgetInteraction/utils.d.ts +8 -0
  82. package/dist/hooks/WidgetInteraction/utils.js +34 -0
  83. package/dist/hooks/utils.d.cts +1 -1
  84. package/dist/hooks/utils.d.ts +1 -1
  85. package/dist/types/customerService.cjs +3 -1
  86. package/dist/types/customerService.d.cts +3 -1
  87. package/dist/types/customerService.d.ts +3 -1
  88. package/dist/types/customerService.js +3 -1
  89. package/package.json +13 -1
  90. package/src/application/commerce-api.ts +0 -1
  91. package/src/application/models/featureGates.ts +3 -0
  92. package/src/contexts/hardcopyContext/hardcopyContext.tsx +2 -0
  93. package/src/contexts/salesAgentContext/chatAPI.ts +39 -6
  94. package/src/hooks/ChatToggle/useChatToggle.ts +35 -2
  95. package/src/hooks/WidgetInteraction/index.ts +1 -0
  96. package/src/hooks/WidgetInteraction/types.ts +139 -0
  97. package/src/hooks/WidgetInteraction/useWidgetInteraction.ts +35 -0
  98. package/src/hooks/WidgetInteraction/utils.ts +44 -0
  99. package/src/types/customerService.ts +2 -0
@@ -1,16 +1,30 @@
1
1
  import { useAtomValue, useSetAtom } from 'jotai';
2
2
  import { ChatElementDisplayLocationV3 } from 'src/application/models';
3
3
  import { chatAtom, chatOnToggleAtom } from 'src/atoms/chat';
4
- import { useAmplitude } from 'src/contexts/amplitudeContext/amplitudeContext';
5
- import { SpiffyMetricsEventName } from 'src/services/amplitudeService/amplitudeService';
4
+ import {
5
+ EnviveMetricsEventName,
6
+ SpiffyMetricsEventName,
7
+ useAmplitude,
8
+ } from 'src/contexts/amplitudeContext/amplitudeContext';
9
+ import { useWidgetInteraction } from '../WidgetInteraction';
10
+ import { WidgetInteractionComponent, WidgetInteractionType } from '../WidgetInteraction/types';
6
11
 
7
12
  export const useChatToggle = () => {
8
13
  const onToggle = useSetAtom(chatOnToggleAtom);
9
14
  const { isOpen } = useAtomValue(chatAtom);
10
15
  const { trackEvent } = useAmplitude();
16
+ const { trackWidgetInteraction } = useWidgetInteraction();
11
17
 
12
18
  const toggle = (triggerLocation: ChatElementDisplayLocationV3, triggerId?: string) => {
13
19
  if (!isOpen) {
20
+ trackWidgetInteraction({
21
+ eventName: EnviveMetricsEventName.WidgetInteraction,
22
+ trigger: {
23
+ widget: WidgetInteractionComponent.FLOATING_BUTTON,
24
+ widget_interaction: WidgetInteractionType.WIDGET_CLICKED,
25
+ },
26
+ });
27
+
14
28
  trackEvent({
15
29
  eventName: SpiffyMetricsEventName.ChatComponentExpanded,
16
30
  eventProps: {
@@ -21,6 +35,14 @@ export const useChatToggle = () => {
21
35
  },
22
36
  });
23
37
  } else {
38
+ trackWidgetInteraction({
39
+ eventName: EnviveMetricsEventName.WidgetInteraction,
40
+ trigger: {
41
+ widget: WidgetInteractionComponent.FLOATING_BUTTON,
42
+ widget_interaction: WidgetInteractionType.WIDGET_COLLAPSED,
43
+ },
44
+ });
45
+
24
46
  trackEvent({
25
47
  eventName: SpiffyMetricsEventName.ChatComponentCollapsed,
26
48
  eventProps: {
@@ -47,10 +69,21 @@ export const useChatToggle = () => {
47
69
  }
48
70
  };
49
71
 
72
+ const onHover = () => {
73
+ trackWidgetInteraction({
74
+ eventName: EnviveMetricsEventName.WidgetInteraction,
75
+ trigger: {
76
+ widget: WidgetInteractionComponent.FLOATING_BUTTON,
77
+ widget_interaction: WidgetInteractionType.WIDGET_HOVERED,
78
+ },
79
+ });
80
+ };
81
+
50
82
  return {
51
83
  toggle,
52
84
  isOpen,
53
85
  openChat,
54
86
  closeChat,
87
+ onHover,
55
88
  };
56
89
  };
@@ -0,0 +1 @@
1
+ export * from './useWidgetInteraction';
@@ -0,0 +1,139 @@
1
+ import { EnviveMetricsEventName, SpiffyMetricsEventName } from '../../contexts/amplitudeContext';
2
+
3
+ export interface WidgetInteractionContext {
4
+ page_type: WidgetInteractionPageType;
5
+ page_id: string;
6
+ }
7
+
8
+ interface WidgetInteractionTrigger {
9
+ interaction_id?: string;
10
+ widget: WidgetInteractionComponent;
11
+ widget_interaction: WidgetInteractionType;
12
+ widget_interaction_data?: WidgetInteractionData | null;
13
+ }
14
+
15
+ export interface InternalWidgetInteraction {
16
+ eventName: SpiffyMetricsEventName | EnviveMetricsEventName;
17
+ context: WidgetInteractionContext;
18
+ trigger: WidgetInteractionTrigger;
19
+ }
20
+
21
+ export interface WidgetInteraction {
22
+ eventName: InternalWidgetInteraction['eventName'];
23
+ trigger: InternalWidgetInteraction['trigger'];
24
+ }
25
+
26
+ export enum WidgetInteractionPageType {
27
+ PDP = 'pdp',
28
+ PLP = 'plp',
29
+ HOMEPAGE = 'homepage',
30
+ SEARCH = 'search',
31
+ OTHER = 'other',
32
+ FULL_PAGE = 'full_page',
33
+ }
34
+
35
+ export enum WidgetInteractionComponent {
36
+ EMBEDDED_WIDGET = 'embedded_widget',
37
+ SUGGESTION_BAR = 'suggestion_bar',
38
+ FLOATING_BUTTON = 'floating_button',
39
+ SOCIAL_PROOF = 'social_proof',
40
+ CHAT_PREVIEW = 'chat_preview',
41
+ FLOATING_CHAT = 'floating_chat',
42
+ SINGLE_IMAGE_PROMPT = 'single_image_prompt',
43
+ IMAGE_PROMPT_CARD = 'image_prompt_card',
44
+ POST_INTERACTION_COMPARISON = 'post_interaction_comparison',
45
+ POST_INTERACTION_EMBEDDED = 'post_interaction_embedded',
46
+ }
47
+
48
+ export enum WidgetInteractionType {
49
+ QUERY_INPUT_CLICKED = 'query_input_clicked',
50
+ SUGGESTION_CLICKED = 'suggestion_clicked',
51
+ WIDGET_CLICKED = 'widget_clicked',
52
+ WIDGET_HOVERED = 'widget_hovered',
53
+ WIDGET_EXPANDED = 'widget_expanded',
54
+ WIDGET_COLLAPSED = 'widget_collapsed',
55
+ SUGGESTION_SCROLLED = 'suggestion_scrolled',
56
+ LINK_CLICKED = 'link_clicked',
57
+ PRODUCT_CARD_CLICKED = 'product_card_clicked',
58
+ TEXT_LINK_CLICKED = 'text_link_clicked',
59
+ ARTICLE_LINK_CLICKED = 'article_link_clicked',
60
+ REVIEW_CARD_CLICKED = 'review_card_clicked',
61
+ MESSAGE_SUBMITTED = 'message_submitted',
62
+ MANUAL_SCROLL_TO_BOTTOM = 'manual_scroll_to_bottom',
63
+ }
64
+
65
+ export type URL = {
66
+ url: string;
67
+ };
68
+
69
+ export type Product = {
70
+ product_id: string;
71
+ };
72
+
73
+ export type Review = {
74
+ review_id: string;
75
+ };
76
+
77
+ export type Suggestion = {
78
+ suggestion_id: string;
79
+ };
80
+
81
+ export type Request = {
82
+ request_text: string;
83
+ };
84
+
85
+ export type Collapse = {
86
+ collapse_source: 'close_button' | 'swipe' | 'body_click';
87
+ };
88
+
89
+ export type SuggestionScrolled = {
90
+ suggestion_scrolled: Suggestion;
91
+ };
92
+
93
+ export type SuggestionClicked = {
94
+ suggestion_clicked: Suggestion;
95
+ };
96
+
97
+ export type SuggestionHovered = {
98
+ suggestion_hovered: Suggestion;
99
+ };
100
+
101
+ export type LinkClicked = {
102
+ link_clicked: URL;
103
+ };
104
+
105
+ export type WidgetCollapsed = {
106
+ widget_collapsed: Collapse;
107
+ };
108
+
109
+ export type TextLinkClicked = {
110
+ text_link_clicked: URL;
111
+ };
112
+
113
+ export type ArticleLinkClicked = {
114
+ article_link_clicked: URL;
115
+ };
116
+
117
+ export type ProductCardClicked = {
118
+ product_card_clicked: Product;
119
+ };
120
+
121
+ export type ReviewCardClicked = {
122
+ review_card_clicked: Review;
123
+ };
124
+
125
+ export type MessageSubmitted = {
126
+ message_submitted: Request;
127
+ };
128
+
129
+ export type WidgetInteractionData =
130
+ | SuggestionScrolled
131
+ | SuggestionClicked
132
+ | SuggestionHovered
133
+ | LinkClicked
134
+ | WidgetCollapsed
135
+ | TextLinkClicked
136
+ | ArticleLinkClicked
137
+ | ProductCardClicked
138
+ | ReviewCardClicked
139
+ | MessageSubmitted;
@@ -0,0 +1,35 @@
1
+ import { useAtomValue } from 'jotai';
2
+ import { pageVariantInfoAtom } from 'src/atoms/app';
3
+ import { useAmplitude } from 'src/contexts/amplitudeContext';
4
+ import { PageVariantInfo } from 'src/contexts/pageContext/types';
5
+ import { v4 as uuid } from 'uuid';
6
+ import { InternalWidgetInteraction, WidgetInteraction } from './types';
7
+ import { extractPageContext } from './utils';
8
+
9
+ export const useWidgetInteraction = () => {
10
+ const { trackEvent } = useAmplitude();
11
+ const variantInfo = useAtomValue(pageVariantInfoAtom);
12
+
13
+ const trackWidgetInteraction = (props: WidgetInteraction) => {
14
+ if (props.trigger) {
15
+ props.trigger.interaction_id = props.trigger.interaction_id || getInteractionId();
16
+ }
17
+
18
+ const eventProps = {
19
+ ...props,
20
+ context: extractPageContext(variantInfo as PageVariantInfo),
21
+ } as InternalWidgetInteraction;
22
+
23
+ trackEvent({
24
+ eventName: props.eventName,
25
+ eventProps: { ...eventProps },
26
+ });
27
+ };
28
+
29
+ const getInteractionId = () => uuid();
30
+
31
+ return {
32
+ trackWidgetInteraction,
33
+ getInteractionId,
34
+ };
35
+ };
@@ -0,0 +1,44 @@
1
+ import { VariantTypeEnum } from 'src/application/models';
2
+ import {
3
+ FullPageSalesAgentVariantInfo,
4
+ HomeVariantInfo,
5
+ OtherVariantInfo,
6
+ PageVariantInfo,
7
+ PDPPageVariantInfo,
8
+ PLPPageVariantInfo,
9
+ } from '../../contexts/pageContext/types';
10
+ import { WidgetInteractionContext, WidgetInteractionPageType } from './types';
11
+
12
+ export const extractPageContext = (
13
+ pageVariant: PageVariantInfo,
14
+ ): WidgetInteractionContext | null => {
15
+ switch (pageVariant.variantType) {
16
+ case VariantTypeEnum.Pdp:
17
+ return {
18
+ page_id: (pageVariant as PDPPageVariantInfo).productId,
19
+ page_type: WidgetInteractionPageType.PDP,
20
+ };
21
+ case VariantTypeEnum.Plp:
22
+ return {
23
+ page_id: (pageVariant as PLPPageVariantInfo).plpId,
24
+ page_type: WidgetInteractionPageType.PLP,
25
+ };
26
+ case VariantTypeEnum.Home:
27
+ return {
28
+ page_id: (pageVariant as HomeVariantInfo).url,
29
+ page_type: WidgetInteractionPageType.HOMEPAGE,
30
+ };
31
+ case VariantTypeEnum.Other:
32
+ return {
33
+ page_id: (pageVariant as OtherVariantInfo).url,
34
+ page_type: WidgetInteractionPageType.OTHER,
35
+ };
36
+ case VariantTypeEnum.FullPageSalesAgent:
37
+ return {
38
+ page_id: (pageVariant as FullPageSalesAgentVariantInfo).url,
39
+ page_type: WidgetInteractionPageType.FULL_PAGE,
40
+ };
41
+ }
42
+
43
+ return null;
44
+ };
@@ -11,6 +11,8 @@ export enum CustomerServiceType {
11
11
  gladly = 'gladly',
12
12
  richpanel = 'richpanel',
13
13
  zendesk = 'zendesk',
14
+ helpscout = 'helpscout',
15
+ talkdesk = 'talkdesk',
14
16
  eightByEight = '8x8',
15
17
  unsupported = 'unsupported',
16
18
  }