@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.
- package/dist/application/commerce-api.cjs +1 -1
- package/dist/application/commerce-api.js +1 -1
- package/dist/application/models/featureGates.cjs +4 -1
- package/dist/application/models/featureGates.d.cts +4 -1
- package/dist/application/models/featureGates.d.ts +4 -1
- package/dist/application/models/featureGates.js +4 -1
- package/dist/atoms/app/index.d.cts +7 -7
- package/dist/atoms/app/index.d.ts +1 -1
- package/dist/atoms/app/variant.d.cts +6 -6
- package/dist/atoms/app/variant.d.ts +6 -6
- package/dist/atoms/chat/chatState.d.cts +18 -18
- package/dist/atoms/chat/chatState.d.ts +1 -1
- package/dist/atoms/chat/form.d.cts +3 -3
- package/dist/atoms/chat/form.d.ts +2 -2
- package/dist/atoms/chat/index.d.cts +3 -3
- package/dist/atoms/chat/index.d.ts +2 -2
- package/dist/atoms/chat/lastMessage.d.cts +2 -2
- package/dist/atoms/chat/lastMessage.d.ts +2 -2
- package/dist/atoms/chat/messageQueue.d.cts +6 -6
- package/dist/atoms/chat/messageQueue.d.ts +6 -6
- package/dist/atoms/chat/performanceMetrics.d.cts +7 -7
- package/dist/atoms/chat/performanceMetrics.d.ts +6 -6
- package/dist/atoms/chat/renderedWidgetRefs.d.cts +2 -2
- package/dist/atoms/chat/renderedWidgetRefs.d.ts +2 -2
- package/dist/atoms/chat/replies.d.cts +3 -3
- package/dist/atoms/chat/replies.d.ts +3 -3
- package/dist/atoms/chat/suggestions.d.cts +2 -2
- package/dist/atoms/chat/suggestions.d.ts +2 -2
- package/dist/atoms/envive/enviveConfig.d.cts +13 -13
- package/dist/atoms/envive/enviveConfig.d.ts +13 -13
- package/dist/atoms/globalSearch/globalSearch.d.cts +5 -5
- package/dist/atoms/globalSearch/globalSearch.d.ts +5 -5
- package/dist/atoms/org/customerService.d.cts +6 -6
- package/dist/atoms/org/customerService.d.ts +6 -6
- package/dist/atoms/org/graphqlConfig.d.cts +4 -4
- package/dist/atoms/org/graphqlConfig.d.ts +4 -4
- package/dist/atoms/org/newOrgConfigAtom.d.cts +2 -2
- package/dist/atoms/org/newOrgConfigAtom.d.ts +3 -3
- package/dist/atoms/org/orgAnalyticsConfig.d.cts +5 -5
- package/dist/atoms/org/orgAnalyticsConfig.d.ts +6 -6
- package/dist/atoms/search/chatSearch.d.cts +17 -17
- package/dist/atoms/search/chatSearch.d.ts +17 -17
- package/dist/atoms/search/searchAPI.d.cts +13 -13
- package/dist/atoms/search/searchAPI.d.ts +13 -13
- package/dist/atoms/search/utils.d.cts +1 -1
- package/dist/atoms/search/utils.d.ts +1 -1
- package/dist/atoms/widget/chatPreviewLoading.d.cts +2 -2
- package/dist/atoms/widget/chatPreviewLoading.d.ts +2 -2
- package/dist/contexts/hardcopyContext/hardcopyContext.cjs +4 -2
- package/dist/contexts/hardcopyContext/hardcopyContext.js +4 -2
- package/dist/contexts/pageContext/types.d.cts +1 -1
- package/dist/contexts/salesAgentContext/chatAPI.cjs +21 -1
- package/dist/contexts/salesAgentContext/chatAPI.js +21 -1
- package/dist/contexts/systemSettingsContext/systemSettingsContext.d.ts +2 -2
- package/dist/contexts/types.d.cts +1 -1
- package/dist/contexts/types.d.ts +1 -1
- package/dist/contexts/typesV3.d.cts +1 -1
- package/dist/contexts/typesV3.d.ts +1 -1
- package/dist/hooks/ChatToggle/useChatToggle.cjs +47 -17
- package/dist/hooks/ChatToggle/useChatToggle.d.cts +2 -1
- package/dist/hooks/ChatToggle/useChatToggle.d.ts +2 -1
- package/dist/hooks/ChatToggle/useChatToggle.js +48 -18
- package/dist/hooks/GrabAndScroll/useGrabAndScroll.d.ts +2 -2
- package/dist/hooks/ShopifyUrlOperations/useShopifyUrlOperations.d.cts +2 -2
- package/dist/hooks/ShopifyUrlOperations/useShopifyUrlOperations.d.ts +2 -2
- package/dist/hooks/SystemSettingsContext/useSystemSettingsContext.d.ts +2 -2
- package/dist/hooks/WidgetInteraction/index.cjs +3 -0
- package/dist/hooks/WidgetInteraction/index.d.cts +2 -0
- package/dist/hooks/WidgetInteraction/index.d.ts +2 -0
- package/dist/hooks/WidgetInteraction/index.js +3 -0
- package/dist/hooks/WidgetInteraction/types.cjs +47 -0
- package/dist/hooks/WidgetInteraction/types.d.cts +110 -0
- package/dist/hooks/WidgetInteraction/types.d.ts +110 -0
- package/dist/hooks/WidgetInteraction/types.js +44 -0
- package/dist/hooks/WidgetInteraction/useWidgetInteraction.cjs +34 -0
- package/dist/hooks/WidgetInteraction/useWidgetInteraction.d.cts +10 -0
- package/dist/hooks/WidgetInteraction/useWidgetInteraction.d.ts +10 -0
- package/dist/hooks/WidgetInteraction/useWidgetInteraction.js +33 -0
- package/dist/hooks/WidgetInteraction/utils.cjs +34 -0
- package/dist/hooks/WidgetInteraction/utils.d.cts +8 -0
- package/dist/hooks/WidgetInteraction/utils.d.ts +8 -0
- package/dist/hooks/WidgetInteraction/utils.js +34 -0
- package/dist/hooks/utils.d.cts +1 -1
- package/dist/hooks/utils.d.ts +1 -1
- package/dist/types/customerService.cjs +3 -1
- package/dist/types/customerService.d.cts +3 -1
- package/dist/types/customerService.d.ts +3 -1
- package/dist/types/customerService.js +3 -1
- package/package.json +13 -1
- package/src/application/commerce-api.ts +0 -1
- package/src/application/models/featureGates.ts +3 -0
- package/src/contexts/hardcopyContext/hardcopyContext.tsx +2 -0
- package/src/contexts/salesAgentContext/chatAPI.ts +39 -6
- package/src/hooks/ChatToggle/useChatToggle.ts +35 -2
- package/src/hooks/WidgetInteraction/index.ts +1 -0
- package/src/hooks/WidgetInteraction/types.ts +139 -0
- package/src/hooks/WidgetInteraction/useWidgetInteraction.ts +35 -0
- package/src/hooks/WidgetInteraction/utils.ts +44 -0
- 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 {
|
|
5
|
-
|
|
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
|
+
};
|