@hubspot/cms-component-library 0.3.11 → 0.3.13
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/components/componentLibrary/Accordion/AccordionContent/index.module.scss +3 -5
- package/components/componentLibrary/Accordion/AccordionItem/StyleFields.tsx +6 -14
- package/components/componentLibrary/Accordion/AccordionItem/index.module.scss +7 -5
- package/components/componentLibrary/Accordion/AccordionItem/index.tsx +6 -15
- package/components/componentLibrary/Accordion/AccordionItem/types.ts +5 -5
- package/components/componentLibrary/Accordion/AccordionTitle/StyleFields.tsx +1 -1
- package/components/componentLibrary/Accordion/AccordionTitle/index.module.scss +6 -6
- package/components/componentLibrary/Accordion/llm.txt +15 -15
- package/components/componentLibrary/Accordion/stories/Accordion.stories.tsx +3 -3
- package/components/componentLibrary/Accordion/stories/AccordionDecorator.module.scss +38 -0
- package/components/componentLibrary/Accordion/stories/AccordionDecorator.tsx +7 -35
- package/components/componentLibrary/Button/index.module.scss +12 -4
- package/components/componentLibrary/Button/llm.txt +12 -4
- package/components/componentLibrary/Button/stories/ButtonDecorator.module.scss +12 -4
- package/components/componentLibrary/Card/index.module.scss +5 -5
- package/components/componentLibrary/Card/llm.txt +3 -1
- package/components/componentLibrary/Card/stories/CardDecorator.module.scss +12 -4
- package/components/componentLibrary/Form/PlaceholderForm.module.css +74 -0
- package/components/componentLibrary/Form/PlaceholderForm.tsx +31 -0
- package/components/componentLibrary/Form/StyleFields.tsx +2 -1
- package/components/componentLibrary/Form/index.tsx +24 -2
- package/components/componentLibrary/Form/islands/FormIsland.tsx +3 -1
- package/components/componentLibrary/Form/islands/LegacyFormIsland.tsx +10 -3
- package/components/componentLibrary/Form/islands/legacyForm.module.scss +270 -0
- package/components/componentLibrary/Form/islands/v4Form.module.css +59 -57
- package/components/componentLibrary/Form/types.ts +7 -2
- package/components/componentLibrary/Image/index.module.scss +3 -1
- package/components/componentLibrary/Image/llm.txt +3 -1
- package/components/componentLibrary/Image/stories/ImageDecorator.module.scss +3 -1
- package/components/componentLibrary/Text/ContentFields.tsx +1 -0
- package/components/componentLibrary/Text/index.module.scss +40 -1
- package/components/componentLibrary/Text/llm.txt +4 -2
- package/components/componentLibrary/Video/ContentFields.tsx +1 -0
- package/components/componentLibrary/Video/StyleFields.tsx +42 -0
- package/components/componentLibrary/Video/TrackHSVideoAnalytics.tsx +445 -0
- package/components/componentLibrary/Video/hooks/usePageMeta.tsx +25 -0
- package/components/componentLibrary/Video/hooks/useQueryParam.tsx +12 -0
- package/components/componentLibrary/Video/hooks/useUserToken.tsx +56 -0
- package/components/componentLibrary/Video/index.tsx +11 -2
- package/components/componentLibrary/Video/islands/EmbedVideoIsland.tsx +239 -0
- package/components/componentLibrary/Video/islands/HSVideoIsland.tsx +4 -0
- package/components/componentLibrary/Video/islands/index.module.scss +94 -0
- package/components/componentLibrary/Video/types.ts +22 -0
- package/components/componentLibrary/Video/utils/videoAnalytics.ts +146 -0
- package/package.json +1 -1
- package/components/componentLibrary/Form/islands/legacyForm.module.css +0 -251
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { CSSVariables } from '../../utils/types.js';
|
|
3
|
+
import { EmbedVideoIslandProps, EmbedVideoParams } from '../types.js';
|
|
4
|
+
import styles from './index.module.scss';
|
|
5
|
+
|
|
6
|
+
const toPx = (value: number | string | undefined) => {
|
|
7
|
+
if (typeof value === 'number') {
|
|
8
|
+
return `${value.toString()}px`;
|
|
9
|
+
} else if (typeof value === 'string') {
|
|
10
|
+
const parsed = parseFloat(value);
|
|
11
|
+
return isNaN(parsed) ? undefined : `${parsed}px`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return undefined;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const getSizeStyles = (
|
|
18
|
+
embedVideoParams: EmbedVideoParams,
|
|
19
|
+
oembedData: EmbedVideoParams['oembed_response']
|
|
20
|
+
) => {
|
|
21
|
+
const responseWidth = oembedData?.width;
|
|
22
|
+
const responseHeight = oembedData?.height;
|
|
23
|
+
switch (embedVideoParams.size_type) {
|
|
24
|
+
case 'exact':
|
|
25
|
+
return {
|
|
26
|
+
width: toPx(embedVideoParams.width ?? responseWidth),
|
|
27
|
+
height: toPx(embedVideoParams.height ?? responseHeight),
|
|
28
|
+
};
|
|
29
|
+
case 'auto_full_width':
|
|
30
|
+
return {};
|
|
31
|
+
default:
|
|
32
|
+
return {
|
|
33
|
+
maxWidth: toPx(embedVideoParams.max_width ?? responseWidth),
|
|
34
|
+
maxHeight: toPx(embedVideoParams.max_height ?? responseHeight),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const CustomThumbnailPlayIcon = () => (
|
|
40
|
+
<svg viewBox="0 0 135.39 149.4">
|
|
41
|
+
<path
|
|
42
|
+
d="M371.2,398.69l-127.79,71c-1.47.83-2.74.93-3.8.28a3.69,3.69,0,0,1-1.59-3.46V324.88a3.73,3.73,0,0,1,1.59-3.47,3.66,3.66,0,0,1,3.8.29l127.79,71c1.47.84,2.21,1.82,2.21,3S372.67,397.85,371.2,398.69Z"
|
|
43
|
+
transform="translate(-238.02 -321)"
|
|
44
|
+
></path>
|
|
45
|
+
</svg>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const OEmbedContainer = ({
|
|
49
|
+
embedVideoParams,
|
|
50
|
+
oEmbedThumbnail,
|
|
51
|
+
oEmbedPlayButtonColor,
|
|
52
|
+
}: {
|
|
53
|
+
embedVideoParams: EmbedVideoParams;
|
|
54
|
+
oEmbedThumbnail?: { src: string; alt?: string };
|
|
55
|
+
oEmbedPlayButtonColor?: { color?: string };
|
|
56
|
+
}) => {
|
|
57
|
+
const {
|
|
58
|
+
size_type: sizeType,
|
|
59
|
+
oembed_url: oembedUrl,
|
|
60
|
+
oembed_response: oembedResponse,
|
|
61
|
+
supported_oembed_types: supportedOembedTypes,
|
|
62
|
+
} = embedVideoParams;
|
|
63
|
+
|
|
64
|
+
const [oembedData, setOembedData] =
|
|
65
|
+
useState<EmbedVideoParams['oembed_response']>(oembedResponse);
|
|
66
|
+
const [hasPlayed, setHasPlayed] = useState(false);
|
|
67
|
+
const iframeWrapperRef = useRef<HTMLDivElement>(null);
|
|
68
|
+
const iframeRef = useRef<HTMLIFrameElement | null>(null);
|
|
69
|
+
|
|
70
|
+
const isSupportedOEmbedType = supportedOembedTypes.includes(
|
|
71
|
+
oembedData?.type || ''
|
|
72
|
+
);
|
|
73
|
+
const sizeStyles = useMemo(
|
|
74
|
+
() => getSizeStyles(embedVideoParams, oembedData),
|
|
75
|
+
[embedVideoParams, oembedData]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const cssVariables: CSSVariables = {
|
|
79
|
+
...(oEmbedPlayButtonColor?.color && {
|
|
80
|
+
'--hscl-video-playButton-color': oEmbedPlayButtonColor.color,
|
|
81
|
+
}),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (oembedData || !oembedUrl) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const fetchOEmbed = async () => {
|
|
90
|
+
try {
|
|
91
|
+
const query = new URLSearchParams({
|
|
92
|
+
url: oembedUrl,
|
|
93
|
+
autoplay: '0',
|
|
94
|
+
});
|
|
95
|
+
const response = await fetch(`/_hcms/oembed?${query}`);
|
|
96
|
+
if (!response.ok) {
|
|
97
|
+
console.error('Server reached, error retrieving oEmbed response.');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
setOembedData(await response.json());
|
|
101
|
+
} catch {
|
|
102
|
+
console.error(
|
|
103
|
+
'Could not reach the server. Failed to retrieve oEmbed response.'
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
fetchOEmbed();
|
|
108
|
+
}, [oembedUrl]);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!oembedData) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const el = document.createElement('div');
|
|
116
|
+
el.innerHTML = oembedData.html;
|
|
117
|
+
const iframe = el.firstChild as HTMLIFrameElement;
|
|
118
|
+
iframe.setAttribute('class', styles['oembed_container_iframe']);
|
|
119
|
+
iframe.setAttribute('title', oembedData.title || '');
|
|
120
|
+
iframeRef.current = iframe;
|
|
121
|
+
if (!oEmbedThumbnail?.src) {
|
|
122
|
+
// if there is a custom thumbnail, iframe will be appended on click
|
|
123
|
+
iframeWrapperRef.current?.appendChild(iframe);
|
|
124
|
+
Object.assign(iframe.style, sizeStyles);
|
|
125
|
+
}
|
|
126
|
+
}, [oembedData, oEmbedThumbnail?.src]);
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<div
|
|
130
|
+
className={`${styles.oembed_container} ${
|
|
131
|
+
sizeType === 'auto_full_width' ? 'oembed_container--full-size' : ''
|
|
132
|
+
}`}
|
|
133
|
+
style={sizeStyles}
|
|
134
|
+
>
|
|
135
|
+
{oEmbedThumbnail?.src && (
|
|
136
|
+
<button
|
|
137
|
+
className={styles['oembed_custom-thumbnail']}
|
|
138
|
+
style={{
|
|
139
|
+
...sizeStyles,
|
|
140
|
+
backgroundImage: `url(${oEmbedThumbnail.src})`,
|
|
141
|
+
display: hasPlayed ? 'none' : undefined,
|
|
142
|
+
}}
|
|
143
|
+
onClick={() => {
|
|
144
|
+
const iframe = iframeRef.current;
|
|
145
|
+
if (iframe) {
|
|
146
|
+
const iframeSrc = new URL(iframe.src);
|
|
147
|
+
iframeSrc.searchParams.append('autoplay', '1');
|
|
148
|
+
iframe.src = iframeSrc.toString();
|
|
149
|
+
Object.assign(iframe.style, sizeStyles);
|
|
150
|
+
iframeWrapperRef.current?.appendChild(iframe);
|
|
151
|
+
setHasPlayed(true);
|
|
152
|
+
}
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
<span className={styles['oembed-info']}>
|
|
156
|
+
{[
|
|
157
|
+
'Video player',
|
|
158
|
+
oEmbedThumbnail.alt ?? '',
|
|
159
|
+
'Click to play video',
|
|
160
|
+
].join(' - ')}
|
|
161
|
+
</span>
|
|
162
|
+
<div
|
|
163
|
+
className={styles['oembed_custom-thumbnail_icon']}
|
|
164
|
+
style={cssVariables}
|
|
165
|
+
>
|
|
166
|
+
<CustomThumbnailPlayIcon />
|
|
167
|
+
</div>
|
|
168
|
+
</button>
|
|
169
|
+
)}
|
|
170
|
+
{isSupportedOEmbedType && oembedData && (
|
|
171
|
+
<div ref={iframeWrapperRef} className={styles.iframe_wrapper} />
|
|
172
|
+
)}
|
|
173
|
+
</div>
|
|
174
|
+
);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const EmbedHTMLContainer = ({ embedHtml }: { embedHtml: string }) => {
|
|
178
|
+
const embedContainerRef = useRef<HTMLDivElement>(null);
|
|
179
|
+
const iframeWrapperRef = useRef<HTMLDivElement>(null);
|
|
180
|
+
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
const container = embedContainerRef.current;
|
|
183
|
+
const iframe = iframeWrapperRef.current?.querySelector('iframe');
|
|
184
|
+
|
|
185
|
+
if (!container || !iframe) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const maxHeight = iframe.getAttribute('height');
|
|
190
|
+
const maxWidth = iframe.getAttribute('width');
|
|
191
|
+
if (maxHeight !== null) {
|
|
192
|
+
container.style.maxHeight = toPx(maxHeight);
|
|
193
|
+
} else {
|
|
194
|
+
iframe.style.height = '100%';
|
|
195
|
+
}
|
|
196
|
+
if (maxWidth !== null) {
|
|
197
|
+
container.style.maxWidth = toPx(maxWidth);
|
|
198
|
+
} else {
|
|
199
|
+
iframe.style.width = '100%';
|
|
200
|
+
}
|
|
201
|
+
}, []);
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<div ref={embedContainerRef} className={styles.embed_container}>
|
|
205
|
+
<div
|
|
206
|
+
ref={iframeWrapperRef}
|
|
207
|
+
className={styles.iframe_wrapper}
|
|
208
|
+
dangerouslySetInnerHTML={{ __html: embedHtml }}
|
|
209
|
+
/>
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const EmbedVideoIsland = ({
|
|
215
|
+
embedVideoParams,
|
|
216
|
+
oembedThumbnail,
|
|
217
|
+
playButtonColor,
|
|
218
|
+
}: EmbedVideoIslandProps) => {
|
|
219
|
+
if (
|
|
220
|
+
embedVideoParams.source_type === 'oembed' &&
|
|
221
|
+
embedVideoParams.oembed_url
|
|
222
|
+
) {
|
|
223
|
+
return (
|
|
224
|
+
<OEmbedContainer
|
|
225
|
+
embedVideoParams={embedVideoParams}
|
|
226
|
+
oEmbedThumbnail={oembedThumbnail}
|
|
227
|
+
oEmbedPlayButtonColor={playButtonColor}
|
|
228
|
+
/>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (embedVideoParams.source_type === 'html' && embedVideoParams.embed_html) {
|
|
233
|
+
return <EmbedHTMLContainer embedHtml={embedVideoParams.embed_html} />;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return null;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
export default EmbedVideoIsland;
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
VideoPlayerProvider,
|
|
10
10
|
} from '@hubspot/video-player-core';
|
|
11
11
|
|
|
12
|
+
import TrackHSVideoAnalytics from '../TrackHSVideoAnalytics.js';
|
|
12
13
|
import { HSVideoIslandProps } from '../types.js';
|
|
13
14
|
|
|
14
15
|
const HSVideoIsland = ({
|
|
@@ -44,6 +45,9 @@ const HSVideoIsland = ({
|
|
|
44
45
|
playButtonColor={playButtonColor}
|
|
45
46
|
theme="DARK"
|
|
46
47
|
/>
|
|
48
|
+
{resolvedVideo && (
|
|
49
|
+
<TrackHSVideoAnalytics video={resolvedVideo} portalId={portalId} />
|
|
50
|
+
)}
|
|
47
51
|
</TranslationsProvider>
|
|
48
52
|
</VideoPlayerProvider>
|
|
49
53
|
</VideoFetchProvider>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
.oembed_container {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
position: relative;
|
|
4
|
+
width: 100%;
|
|
5
|
+
height: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.oembed_container_iframe {
|
|
9
|
+
height: 100%;
|
|
10
|
+
left: 0;
|
|
11
|
+
margin: 0 auto;
|
|
12
|
+
position: absolute;
|
|
13
|
+
right: 0;
|
|
14
|
+
top: 0;
|
|
15
|
+
width: 100%;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.oembed_custom-thumbnail,
|
|
19
|
+
.oembed_custom-thumbnail:hover,
|
|
20
|
+
.oembed_custom-thumbnail:focus,
|
|
21
|
+
.oembed_custom-thumbnail:active {
|
|
22
|
+
align-items: center;
|
|
23
|
+
appearance: none;
|
|
24
|
+
background-color: transparent;
|
|
25
|
+
background-position: center center;
|
|
26
|
+
background-repeat: no-repeat;
|
|
27
|
+
background-size: cover;
|
|
28
|
+
border-radius: 0;
|
|
29
|
+
border: none;
|
|
30
|
+
display: flex;
|
|
31
|
+
height: 100%;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
left: 0;
|
|
34
|
+
margin: 0;
|
|
35
|
+
padding: 0;
|
|
36
|
+
position: absolute;
|
|
37
|
+
top: 0;
|
|
38
|
+
width: 100%;
|
|
39
|
+
z-index: 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.oembed_custom-thumbnail_icon {
|
|
43
|
+
align-items: center;
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
display: flex;
|
|
46
|
+
justify-content: center;
|
|
47
|
+
width: 100%;
|
|
48
|
+
|
|
49
|
+
svg {
|
|
50
|
+
display: block;
|
|
51
|
+
height: auto;
|
|
52
|
+
width: 12%;
|
|
53
|
+
fill: var(--hscl-video-playButton-color, #ffffff);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* SVGs in IE11 require the max-width to be set to non in order to display scaling properly */
|
|
58
|
+
_:-ms-fullscreen,
|
|
59
|
+
:root .oembed_custom-thumbnail_icon svg {
|
|
60
|
+
max-width: none;
|
|
61
|
+
fill: var(--hscl-video-playButton-color, #ffffff);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.oembed-info {
|
|
65
|
+
height: 1px;
|
|
66
|
+
left: -10000px;
|
|
67
|
+
overflow: hidden;
|
|
68
|
+
position: absolute;
|
|
69
|
+
top: auto;
|
|
70
|
+
width: 1px;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.iframe_wrapper {
|
|
74
|
+
height: 0;
|
|
75
|
+
padding-bottom: 56.25%;
|
|
76
|
+
padding-top: 25px;
|
|
77
|
+
position: relative;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.embed_container {
|
|
81
|
+
display: inline-block;
|
|
82
|
+
height: 100%;
|
|
83
|
+
position: relative;
|
|
84
|
+
width: 100%;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.embed_container iframe {
|
|
88
|
+
left: 0;
|
|
89
|
+
max-height: 100%;
|
|
90
|
+
max-width: 100%;
|
|
91
|
+
position: absolute;
|
|
92
|
+
right: 0;
|
|
93
|
+
top: 0;
|
|
94
|
+
}
|
|
@@ -72,3 +72,25 @@ export type EmbedVideoParams = {
|
|
|
72
72
|
// fields for 'html' source_type
|
|
73
73
|
embed_html?: string;
|
|
74
74
|
};
|
|
75
|
+
|
|
76
|
+
declare global {
|
|
77
|
+
interface Window {
|
|
78
|
+
hsVars?: {
|
|
79
|
+
page_id?: number;
|
|
80
|
+
};
|
|
81
|
+
_hsq?: [string, unknown];
|
|
82
|
+
__hsUserToken?: string;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type PrivacyConsent = {
|
|
87
|
+
categories?: Record<string, boolean>;
|
|
88
|
+
allowed?: boolean;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export type PageMeta = {
|
|
92
|
+
pageUrl: string;
|
|
93
|
+
pageTitle: string;
|
|
94
|
+
pageId: number;
|
|
95
|
+
_hsenc?: string;
|
|
96
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { getHublet, HSEnvironment } from '@hubspot/cms-components';
|
|
2
|
+
import { PageMeta } from '../types.js';
|
|
3
|
+
|
|
4
|
+
type TrackPlayParams = {
|
|
5
|
+
crmObjectId: number;
|
|
6
|
+
sessionId: string;
|
|
7
|
+
contactUtk: string;
|
|
8
|
+
pageMeta: PageMeta;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type RetentionParams = {
|
|
12
|
+
secondsToViews: Record<string, number>;
|
|
13
|
+
endState: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type CompletedPlayParams = {
|
|
17
|
+
secondsViewed: number;
|
|
18
|
+
percentageViewed: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getApiDomain = (env?: HSEnvironment) => {
|
|
22
|
+
const computedEnv = env || 'prod';
|
|
23
|
+
return computedEnv === 'qa' ? 'hubspotqa.com' : 'hubspot.com';
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const getApiOrigin = (env?: HSEnvironment) => {
|
|
27
|
+
const hublet = getHublet();
|
|
28
|
+
const apiSubdomainWithHublet = hublet === 'na1' ? 'api' : `api-${hublet}`;
|
|
29
|
+
return `https://${apiSubdomainWithHublet}.${getApiDomain(env)}`;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const trackPlayEvent = async (
|
|
33
|
+
env: HSEnvironment,
|
|
34
|
+
portalId: number,
|
|
35
|
+
params: TrackPlayParams
|
|
36
|
+
) => {
|
|
37
|
+
const data = {
|
|
38
|
+
...params.pageMeta,
|
|
39
|
+
crmObjectId: params.crmObjectId,
|
|
40
|
+
sessionId: params.sessionId,
|
|
41
|
+
contactUtk: params.contactUtk,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const response = await fetch(
|
|
45
|
+
`${getApiOrigin(
|
|
46
|
+
env
|
|
47
|
+
)}/media-bridge/public/v1/media/played?portalId=${portalId}`,
|
|
48
|
+
{
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: { 'Content-Type': 'application/json' },
|
|
51
|
+
body: JSON.stringify(data),
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
const errorData = {
|
|
57
|
+
status: response.status,
|
|
58
|
+
requestBody: data,
|
|
59
|
+
responseText: await response.text(),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
console.error('Failed to track play event', {
|
|
63
|
+
extra: errorData,
|
|
64
|
+
level: 'warning',
|
|
65
|
+
tags: { status: response.status },
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const trackSecondsViewed = async (
|
|
71
|
+
env: HSEnvironment,
|
|
72
|
+
portalId: number,
|
|
73
|
+
params: TrackPlayParams,
|
|
74
|
+
retentionParams: RetentionParams
|
|
75
|
+
) => {
|
|
76
|
+
let query = `portalId=${portalId}`;
|
|
77
|
+
if (retentionParams.endState) {
|
|
78
|
+
query += `&endState=true`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const data = {
|
|
82
|
+
...params.pageMeta,
|
|
83
|
+
crmObjectId: params.crmObjectId,
|
|
84
|
+
sessionId: params.sessionId,
|
|
85
|
+
contactUtk: params.contactUtk,
|
|
86
|
+
secondsToViews: retentionParams.secondsToViews,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const response = await fetch(
|
|
90
|
+
`${getApiOrigin(env)}/media-bridge/public/v1/media/seconds-viewed?${query}`,
|
|
91
|
+
{
|
|
92
|
+
method: 'POST',
|
|
93
|
+
headers: { 'Content-Type': 'application/json' },
|
|
94
|
+
body: JSON.stringify(data),
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
if (!response.ok) {
|
|
99
|
+
const errorData = {
|
|
100
|
+
status: response.status,
|
|
101
|
+
requestBody: data,
|
|
102
|
+
responseText: await response.text(),
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
console.error('Failed to track seconds viewed', {
|
|
106
|
+
extra: errorData,
|
|
107
|
+
level: 'warning',
|
|
108
|
+
tags: { status: response.status },
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const trackCompletedPlay = async (
|
|
114
|
+
env: HSEnvironment,
|
|
115
|
+
portalId: number,
|
|
116
|
+
params: TrackPlayParams,
|
|
117
|
+
completedPlayParams: CompletedPlayParams
|
|
118
|
+
) => {
|
|
119
|
+
if (!window.navigator || typeof window.navigator.sendBeacon !== 'function') {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
const data = new Blob(
|
|
125
|
+
[
|
|
126
|
+
JSON.stringify({
|
|
127
|
+
crmObjectId: params.crmObjectId,
|
|
128
|
+
sessionId: params.sessionId,
|
|
129
|
+
contactUtk: params.contactUtk,
|
|
130
|
+
...params.pageMeta,
|
|
131
|
+
...completedPlayParams,
|
|
132
|
+
}),
|
|
133
|
+
],
|
|
134
|
+
{ type: 'text/plain' }
|
|
135
|
+
);
|
|
136
|
+
return window.navigator.sendBeacon(
|
|
137
|
+
`${getApiOrigin(
|
|
138
|
+
env
|
|
139
|
+
)}/media-bridge/public/v1/media/completed-play?portalId=${portalId}`,
|
|
140
|
+
data
|
|
141
|
+
);
|
|
142
|
+
} catch (err) {
|
|
143
|
+
console.error('Error tracking final attention span', err);
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
};
|