@builder.io/sdk-react 0.2.3-4 → 0.2.3
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/sdk/blocks/columns/columns.js +4 -4
- package/dist/sdk/blocks/image/image.js +8 -7
- package/dist/sdk/blocks/symbol/symbol.js +2 -1
- package/dist/sdk/blocks/video/video.js +4 -1
- package/dist/sdk/components/render-block/render-block.js +4 -1
- package/dist/sdk/components/render-content/render-content.js +19 -5
- package/dist/sdk/index.d.ts +1 -0
- package/package.json +4 -1
- package/CHANGELOG.md +0 -25
- package/packages/react/src/blocks/BaseText.tsx +0 -19
- package/packages/react/src/blocks/button/button.tsx +0 -45
- package/packages/react/src/blocks/button/component-info.ts +0 -42
- package/packages/react/src/blocks/columns/columns.tsx +0 -211
- package/packages/react/src/blocks/columns/component-info.ts +0 -254
- package/packages/react/src/blocks/custom-code/component-info.ts +0 -31
- package/packages/react/src/blocks/custom-code/custom-code.tsx +0 -76
- package/packages/react/src/blocks/embed/component-info.ts +0 -55
- package/packages/react/src/blocks/embed/embed.tsx +0 -59
- package/packages/react/src/blocks/embed/helpers.ts +0 -8
- package/packages/react/src/blocks/form/component-info.ts +0 -282
- package/packages/react/src/blocks/form/form.tsx +0 -320
- package/packages/react/src/blocks/fragment/component-info.ts +0 -10
- package/packages/react/src/blocks/fragment/fragment.tsx +0 -14
- package/packages/react/src/blocks/image/component-info.ts +0 -172
- package/packages/react/src/blocks/image/image.helpers.ts +0 -75
- package/packages/react/src/blocks/image/image.tsx +0 -144
- package/packages/react/src/blocks/img/component-info.ts +0 -21
- package/packages/react/src/blocks/img/img.tsx +0 -40
- package/packages/react/src/blocks/input/component-info.ts +0 -78
- package/packages/react/src/blocks/input/input.tsx +0 -33
- package/packages/react/src/blocks/raw-text/component-info.ts +0 -15
- package/packages/react/src/blocks/raw-text/raw-text.tsx +0 -18
- package/packages/react/src/blocks/section/component-info.ts +0 -50
- package/packages/react/src/blocks/section/section.tsx +0 -33
- package/packages/react/src/blocks/select/component-info.ts +0 -61
- package/packages/react/src/blocks/select/select.tsx +0 -35
- package/packages/react/src/blocks/submit-button/component-info.ts +0 -32
- package/packages/react/src/blocks/submit-button/submit-button.tsx +0 -17
- package/packages/react/src/blocks/symbol/component-info.ts +0 -43
- package/packages/react/src/blocks/symbol/symbol.tsx +0 -111
- package/packages/react/src/blocks/text/component-info.ts +0 -24
- package/packages/react/src/blocks/text/text.tsx +0 -20
- package/packages/react/src/blocks/textarea/component-info.ts +0 -48
- package/packages/react/src/blocks/textarea/textarea.tsx +0 -24
- package/packages/react/src/blocks/util.ts +0 -18
- package/packages/react/src/blocks/video/component-info.ts +0 -109
- package/packages/react/src/blocks/video/video.tsx +0 -84
- package/packages/react/src/components/render-block/block-styles.tsx +0 -98
- package/packages/react/src/components/render-block/render-block.helpers.ts +0 -138
- package/packages/react/src/components/render-block/render-block.tsx +0 -216
- package/packages/react/src/components/render-block/render-component.tsx +0 -52
- package/packages/react/src/components/render-block/render-repeated-block.tsx +0 -43
- package/packages/react/src/components/render-block/types.ts +0 -7
- package/packages/react/src/components/render-blocks.tsx +0 -97
- package/packages/react/src/components/render-content/builder-editing.tsx +0 -8
- package/packages/react/src/components/render-content/components/render-styles.helpers.ts +0 -79
- package/packages/react/src/components/render-content/components/render-styles.tsx +0 -45
- package/packages/react/src/components/render-content/index.ts +0 -1
- package/packages/react/src/components/render-content/render-content.helpers.ts +0 -48
- package/packages/react/src/components/render-content/render-content.tsx +0 -410
- package/packages/react/src/components/render-content/render-content.types.ts +0 -33
- package/packages/react/src/components/render-inlined-styles.tsx +0 -36
- package/packages/react/src/constants/builder-registered-components.ts +0 -42
- package/packages/react/src/constants/device-sizes.ts +0 -65
- package/packages/react/src/constants/target.ts +0 -2
- package/packages/react/src/context/builder.context.ts +0 -12
- package/packages/react/src/context/types.ts +0 -26
- package/packages/react/src/functions/camel-to-kebab-case.ts +0 -2
- package/packages/react/src/functions/evaluate.ts +0 -57
- package/packages/react/src/functions/event-handler-name.ts +0 -6
- package/packages/react/src/functions/extract-text-styles.ts +0 -39
- package/packages/react/src/functions/fast-clone.ts +0 -5
- package/packages/react/src/functions/get-block-actions-handler.ts +0 -20
- package/packages/react/src/functions/get-block-actions.ts +0 -25
- package/packages/react/src/functions/get-block-component-options.ts +0 -12
- package/packages/react/src/functions/get-block-properties.ts +0 -75
- package/packages/react/src/functions/get-builder-search-params/fn.test.ts +0 -19
- package/packages/react/src/functions/get-builder-search-params/index.ts +0 -50
- package/packages/react/src/functions/get-content/ab-testing.ts +0 -132
- package/packages/react/src/functions/get-content/generate-content-url.test.ts +0 -95
- package/packages/react/src/functions/get-content/generate-content-url.ts +0 -59
- package/packages/react/src/functions/get-content/index.ts +0 -62
- package/packages/react/src/functions/get-content/types.ts +0 -53
- package/packages/react/src/functions/get-fetch.ts +0 -18
- package/packages/react/src/functions/get-global-this.ts +0 -17
- package/packages/react/src/functions/get-processed-block.test.ts +0 -33
- package/packages/react/src/functions/get-processed-block.ts +0 -54
- package/packages/react/src/functions/get-react-native-block-styles.ts +0 -33
- package/packages/react/src/functions/if-target.ts +0 -20
- package/packages/react/src/functions/is-browser.ts +0 -3
- package/packages/react/src/functions/is-editing.ts +0 -10
- package/packages/react/src/functions/is-iframe.ts +0 -5
- package/packages/react/src/functions/is-previewing.ts +0 -14
- package/packages/react/src/functions/on-change.test.ts +0 -23
- package/packages/react/src/functions/on-change.ts +0 -29
- package/packages/react/src/functions/register-component.ts +0 -50
- package/packages/react/src/functions/register.ts +0 -46
- package/packages/react/src/functions/sanitize-react-native-block-styles.ts +0 -65
- package/packages/react/src/functions/set-editor-settings.ts +0 -16
- package/packages/react/src/functions/set.test.ts +0 -19
- package/packages/react/src/functions/set.ts +0 -26
- package/packages/react/src/functions/track/helpers.ts +0 -67
- package/packages/react/src/functions/track/index.ts +0 -136
- package/packages/react/src/functions/track/interaction.ts +0 -80
- package/packages/react/src/functions/transform-block-properties.ts +0 -3
- package/packages/react/src/functions/transform-block.ts +0 -6
- package/packages/react/src/helpers/ab-tests.ts +0 -22
- package/packages/react/src/helpers/cookie.ts +0 -107
- package/packages/react/src/helpers/css.ts +0 -42
- package/packages/react/src/helpers/flatten.ts +0 -24
- package/packages/react/src/helpers/localStorage.ts +0 -40
- package/packages/react/src/helpers/logger.ts +0 -6
- package/packages/react/src/helpers/nullable.ts +0 -4
- package/packages/react/src/helpers/sessionId.ts +0 -38
- package/packages/react/src/helpers/time.ts +0 -4
- package/packages/react/src/helpers/url.test.ts +0 -23
- package/packages/react/src/helpers/url.ts +0 -16
- package/packages/react/src/helpers/uuid.ts +0 -17
- package/packages/react/src/helpers/visitorId.ts +0 -40
- package/packages/react/src/index-helpers/blocks-exports.ts +0 -10
- package/packages/react/src/index-helpers/top-of-file.ts +0 -4
- package/packages/react/src/index.ts +0 -14
- package/packages/react/src/scripts/init-editing.ts +0 -123
- package/packages/react/src/types/api-version.ts +0 -2
- package/packages/react/src/types/builder-block.ts +0 -69
- package/packages/react/src/types/builder-content.ts +0 -46
- package/packages/react/src/types/can-track.ts +0 -3
- package/packages/react/src/types/components.ts +0 -117
- package/packages/react/src/types/deep-partial.ts +0 -7
- package/packages/react/src/types/element.ts +0 -60
- package/packages/react/src/types/input.ts +0 -125
- package/packages/react/src/types/targets.ts +0 -6
- package/packages/react/src/types/typescript.ts +0 -7
- package/packages/rsc/src/blocks/BaseText.jsx +0 -12
- package/packages/rsc/src/blocks/button/button.jsx +0 -37
- package/packages/rsc/src/blocks/button/component-info.js +0 -40
- package/packages/rsc/src/blocks/columns/columns.jsx +0 -172
- package/packages/rsc/src/blocks/columns/component-info.js +0 -241
- package/packages/rsc/src/blocks/custom-code/component-info.js +0 -30
- package/packages/rsc/src/blocks/custom-code/custom-code.jsx +0 -57
- package/packages/rsc/src/blocks/embed/component-info.js +0 -43
- package/packages/rsc/src/blocks/embed/embed.jsx +0 -45
- package/packages/rsc/src/blocks/embed/helpers.js +0 -9
- package/packages/rsc/src/blocks/form/component-info.js +0 -261
- package/packages/rsc/src/blocks/form/form.jsx +0 -260
- package/packages/rsc/src/blocks/fragment/component-info.js +0 -10
- package/packages/rsc/src/blocks/fragment/fragment.jsx +0 -9
- package/packages/rsc/src/blocks/image/component-info.js +0 -150
- package/packages/rsc/src/blocks/image/image.helpers.js +0 -48
- package/packages/rsc/src/blocks/image/image.jsx +0 -122
- package/packages/rsc/src/blocks/img/component-info.js +0 -19
- package/packages/rsc/src/blocks/img/img.jsx +0 -21
- package/packages/rsc/src/blocks/input/component-info.js +0 -73
- package/packages/rsc/src/blocks/input/input.jsx +0 -23
- package/packages/rsc/src/blocks/raw-text/component-info.js +0 -15
- package/packages/rsc/src/blocks/raw-text/raw-text.jsx +0 -14
- package/packages/rsc/src/blocks/section/component-info.js +0 -48
- package/packages/rsc/src/blocks/section/section.jsx +0 -27
- package/packages/rsc/src/blocks/select/component-info.js +0 -58
- package/packages/rsc/src/blocks/select/select.jsx +0 -24
- package/packages/rsc/src/blocks/submit-button/component-info.js +0 -27
- package/packages/rsc/src/blocks/submit-button/submit-button.jsx +0 -13
- package/packages/rsc/src/blocks/symbol/component-info.js +0 -42
- package/packages/rsc/src/blocks/symbol/symbol.jsx +0 -89
- package/packages/rsc/src/blocks/text/component-info.js +0 -23
- package/packages/rsc/src/blocks/text/text.jsx +0 -17
- package/packages/rsc/src/blocks/textarea/component-info.js +0 -46
- package/packages/rsc/src/blocks/textarea/textarea.jsx +0 -17
- package/packages/rsc/src/blocks/util.js +0 -8
- package/packages/rsc/src/blocks/video/component-info.js +0 -105
- package/packages/rsc/src/blocks/video/video.jsx +0 -63
- package/packages/rsc/src/components/render-block/block-styles.jsx +0 -88
- package/packages/rsc/src/components/render-block/render-block.helpers.js +0 -129
- package/packages/rsc/src/components/render-block/render-block.jsx +0 -201
- package/packages/rsc/src/components/render-block/render-component.jsx +0 -39
- package/packages/rsc/src/components/render-block/render-repeated-block.jsx +0 -27
- package/packages/rsc/src/components/render-block/types.js +0 -0
- package/packages/rsc/src/components/render-blocks.jsx +0 -92
- package/packages/rsc/src/components/render-content/builder-editing.jsx +0 -64
- package/packages/rsc/src/components/render-content/components/render-styles.helpers.js +0 -57
- package/packages/rsc/src/components/render-content/components/render-styles.jsx +0 -39
- package/packages/rsc/src/components/render-content/index.js +0 -4
- package/packages/rsc/src/components/render-content/render-content.helpers.js +0 -48
- package/packages/rsc/src/components/render-content/render-content.jsx +0 -253
- package/packages/rsc/src/components/render-content/render-content.types.js +0 -0
- package/packages/rsc/src/components/render-inlined-styles.jsx +0 -33
- package/packages/rsc/src/constants/builder-registered-components.js +0 -54
- package/packages/rsc/src/constants/device-sizes.js +0 -48
- package/packages/rsc/src/constants/target.js +0 -4
- package/packages/rsc/src/context/builder.context.js +0 -14
- package/packages/rsc/src/context/types.js +0 -0
- package/packages/rsc/src/functions/camel-to-kebab-case.js +0 -4
- package/packages/rsc/src/functions/evaluate.js +0 -6
- package/packages/rsc/src/functions/event-handler-name.js +0 -7
- package/packages/rsc/src/functions/extract-text-styles.js +0 -22
- package/packages/rsc/src/functions/fast-clone.js +0 -4
- package/packages/rsc/src/functions/get-block-actions-handler.js +0 -11
- package/packages/rsc/src/functions/get-block-actions.js +0 -18
- package/packages/rsc/src/functions/get-block-component-options.js +0 -28
- package/packages/rsc/src/functions/get-block-properties.js +0 -53
- package/packages/rsc/src/functions/get-builder-search-params/fn.test.js +0 -13
- package/packages/rsc/src/functions/get-builder-search-params/index.js +0 -38
- package/packages/rsc/src/functions/get-content/ab-testing.js +0 -99
- package/packages/rsc/src/functions/get-content/generate-content-url.js +0 -60
- package/packages/rsc/src/functions/get-content/generate-content-url.test.js +0 -82
- package/packages/rsc/src/functions/get-content/index.js +0 -83
- package/packages/rsc/src/functions/get-content/types.js +0 -0
- package/packages/rsc/src/functions/get-fetch.js +0 -14
- package/packages/rsc/src/functions/get-global-this.js +0 -18
- package/packages/rsc/src/functions/get-processed-block.js +0 -59
- package/packages/rsc/src/functions/get-processed-block.test.js +0 -32
- package/packages/rsc/src/functions/get-react-native-block-styles.js +0 -33
- package/packages/rsc/src/functions/if-target.js +0 -15
- package/packages/rsc/src/functions/is-browser.js +0 -6
- package/packages/rsc/src/functions/is-editing.js +0 -8
- package/packages/rsc/src/functions/is-iframe.js +0 -7
- package/packages/rsc/src/functions/is-previewing.js +0 -14
- package/packages/rsc/src/functions/on-change.js +0 -27
- package/packages/rsc/src/functions/on-change.test.js +0 -19
- package/packages/rsc/src/functions/register-component.js +0 -68
- package/packages/rsc/src/functions/register.js +0 -29
- package/packages/rsc/src/functions/sanitize-react-native-block-styles.js +0 -66
- package/packages/rsc/src/functions/set-editor-settings.js +0 -15
- package/packages/rsc/src/functions/set.js +0 -11
- package/packages/rsc/src/functions/set.test.js +0 -16
- package/packages/rsc/src/functions/track/helpers.js +0 -50
- package/packages/rsc/src/functions/track/index.js +0 -129
- package/packages/rsc/src/functions/track/interaction.js +0 -53
- package/packages/rsc/src/functions/transform-block-properties.js +0 -6
- package/packages/rsc/src/functions/transform-block.js +0 -6
- package/packages/rsc/src/helpers/ab-tests.js +0 -16
- package/packages/rsc/src/helpers/cookie.js +0 -81
- package/packages/rsc/src/helpers/css.js +0 -34
- package/packages/rsc/src/helpers/flatten.js +0 -34
- package/packages/rsc/src/helpers/localStorage.js +0 -35
- package/packages/rsc/src/helpers/logger.js +0 -9
- package/packages/rsc/src/helpers/nullable.js +0 -4
- package/packages/rsc/src/helpers/sessionId.js +0 -52
- package/packages/rsc/src/helpers/time.js +0 -5
- package/packages/rsc/src/helpers/url.js +0 -13
- package/packages/rsc/src/helpers/url.test.js +0 -21
- package/packages/rsc/src/helpers/uuid.js +0 -13
- package/packages/rsc/src/helpers/visitorId.js +0 -34
- package/packages/rsc/src/index-helpers/blocks-exports.js +0 -22
- package/packages/rsc/src/index-helpers/top-of-file.js +0 -2
- package/packages/rsc/src/index.js +0 -13
- package/packages/rsc/src/scripts/init-editing.js +0 -93
- package/packages/rsc/src/types/api-version.js +0 -4
- package/packages/rsc/src/types/builder-block.js +0 -0
- package/packages/rsc/src/types/builder-content.js +0 -0
- package/packages/rsc/src/types/can-track.js +0 -0
- package/packages/rsc/src/types/components.js +0 -0
- package/packages/rsc/src/types/deep-partial.js +0 -0
- package/packages/rsc/src/types/element.js +0 -0
- package/packages/rsc/src/types/input.js +0 -0
- package/packages/rsc/src/types/targets.js +0 -0
- package/packages/rsc/src/types/typescript.js +0 -0
- package/tsconfig.json +0 -28
- package/tsconfig.sdk.json +0 -10
- package/tsconfig.server.json +0 -10
- package/vite.config.ts +0 -91
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { TARGET } from '../../constants/target';
|
|
2
|
-
import type { Nullable } from '../../helpers/nullable';
|
|
3
|
-
import { isBrowser } from '../is-browser';
|
|
4
|
-
|
|
5
|
-
const getLocation = (): Nullable<URL> => {
|
|
6
|
-
if (TARGET === 'reactNative') {
|
|
7
|
-
return null;
|
|
8
|
-
} else if (isBrowser()) {
|
|
9
|
-
const parsedLocation = new URL(location.href);
|
|
10
|
-
|
|
11
|
-
// IE11 bug with parsed path being empty string
|
|
12
|
-
// causes issues with our user targeting
|
|
13
|
-
if (parsedLocation.pathname === '') {
|
|
14
|
-
parsedLocation.pathname = '/';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return parsedLocation;
|
|
18
|
-
} else {
|
|
19
|
-
console.warn('Cannot get location for tracking in non-browser environment');
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const getUserAgent = () =>
|
|
25
|
-
(typeof navigator === 'object' && navigator.userAgent) || '';
|
|
26
|
-
|
|
27
|
-
export const getUserAttributes = () => {
|
|
28
|
-
const userAgent = getUserAgent();
|
|
29
|
-
|
|
30
|
-
const isMobile = {
|
|
31
|
-
Android() {
|
|
32
|
-
return userAgent.match(/Android/i);
|
|
33
|
-
},
|
|
34
|
-
BlackBerry() {
|
|
35
|
-
return userAgent.match(/BlackBerry/i);
|
|
36
|
-
},
|
|
37
|
-
iOS() {
|
|
38
|
-
return userAgent.match(/iPhone|iPod/i);
|
|
39
|
-
},
|
|
40
|
-
Opera() {
|
|
41
|
-
return userAgent.match(/Opera Mini/i);
|
|
42
|
-
},
|
|
43
|
-
Windows() {
|
|
44
|
-
return userAgent.match(/IEMobile/i) || userAgent.match(/WPDesktop/i);
|
|
45
|
-
},
|
|
46
|
-
any() {
|
|
47
|
-
return (
|
|
48
|
-
isMobile.Android() ||
|
|
49
|
-
isMobile.BlackBerry() ||
|
|
50
|
-
isMobile.iOS() ||
|
|
51
|
-
isMobile.Opera() ||
|
|
52
|
-
isMobile.Windows() ||
|
|
53
|
-
TARGET === 'reactNative'
|
|
54
|
-
);
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const isTablet = userAgent.match(/Tablet|iPad/i);
|
|
59
|
-
|
|
60
|
-
const url = getLocation();
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
urlPath: url?.pathname,
|
|
64
|
-
host: url?.host || url?.hostname,
|
|
65
|
-
device: isTablet ? 'tablet' : isMobile.any() ? 'mobile' : 'desktop',
|
|
66
|
-
};
|
|
67
|
-
};
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { TARGET } from '../../constants/target.js';
|
|
2
|
-
import { logger } from '../../helpers/logger.js';
|
|
3
|
-
import { getSessionId } from '../../helpers/sessionId.js';
|
|
4
|
-
import { getVisitorId } from '../../helpers/visitorId.js';
|
|
5
|
-
import type { CanTrack } from '../../types/can-track.js';
|
|
6
|
-
import type { Dictionary } from '../../types/typescript.js';
|
|
7
|
-
import { isBrowser } from '../is-browser.js';
|
|
8
|
-
import { isEditing } from '../is-editing.js';
|
|
9
|
-
import { getUserAttributes } from './helpers.js';
|
|
10
|
-
|
|
11
|
-
interface Event {
|
|
12
|
-
/**
|
|
13
|
-
* The type of your event.
|
|
14
|
-
*
|
|
15
|
-
* Examples: `click`, `conversion`, `pageview`, `impression`
|
|
16
|
-
*/
|
|
17
|
-
type: string;
|
|
18
|
-
data: {
|
|
19
|
-
/**
|
|
20
|
-
* (Optional) The content's ID. Useful if this event pertains to a specific piece of content.
|
|
21
|
-
*/
|
|
22
|
-
contentId?: string;
|
|
23
|
-
/**
|
|
24
|
-
* This is the ID of the space that the content belongs to.
|
|
25
|
-
*/
|
|
26
|
-
ownerId: string;
|
|
27
|
-
/**
|
|
28
|
-
* (Optional) metadata that you want to provide with your event.
|
|
29
|
-
*/
|
|
30
|
-
metadata?: Dictionary<any>;
|
|
31
|
-
/**
|
|
32
|
-
* Session ID of the user. This is provided by the SDK by checking session storage.
|
|
33
|
-
*/
|
|
34
|
-
sessionId: string | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* Visitor ID of the user. This is provided by the SDK by checking cookies.
|
|
37
|
-
*/
|
|
38
|
-
visitorId: string | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* (Optional) If running an A/B test, the ID of the variation that the user is in.
|
|
41
|
-
*/
|
|
42
|
-
variationId?: string;
|
|
43
|
-
[index: string]: any;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
type TrackingData = {
|
|
48
|
-
visitorId: string | undefined;
|
|
49
|
-
sessionId: string | undefined;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const getTrackingEventData = async ({
|
|
53
|
-
canTrack,
|
|
54
|
-
}: CanTrack): Promise<TrackingData> => {
|
|
55
|
-
if (!canTrack) {
|
|
56
|
-
return { visitorId: undefined, sessionId: undefined };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const sessionId = await getSessionId({ canTrack });
|
|
60
|
-
const visitorId = getVisitorId({ canTrack });
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
sessionId,
|
|
64
|
-
visitorId,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
type EventProperties = Pick<Event, 'type'> &
|
|
69
|
-
Pick<Event['data'], 'contentId' | 'variationId' | 'metadata'> & {
|
|
70
|
-
/**
|
|
71
|
-
* Your organization's API key.
|
|
72
|
-
*/
|
|
73
|
-
apiKey: Event['data']['ownerId'];
|
|
74
|
-
/**
|
|
75
|
-
* (Optional) Any additional (non-metadata) properties to add to the event.
|
|
76
|
-
*/
|
|
77
|
-
[index: string]: any;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export type EventProps = EventProperties & CanTrack;
|
|
81
|
-
|
|
82
|
-
const createEvent = async ({
|
|
83
|
-
type: eventType,
|
|
84
|
-
canTrack,
|
|
85
|
-
apiKey,
|
|
86
|
-
metadata,
|
|
87
|
-
...properties
|
|
88
|
-
}: EventProps): Promise<Event> => ({
|
|
89
|
-
type: eventType,
|
|
90
|
-
data: {
|
|
91
|
-
...properties,
|
|
92
|
-
metadata: {
|
|
93
|
-
url: location.href,
|
|
94
|
-
...metadata,
|
|
95
|
-
},
|
|
96
|
-
...(await getTrackingEventData({ canTrack })),
|
|
97
|
-
userAttributes: getUserAttributes(),
|
|
98
|
-
ownerId: apiKey,
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
export async function _track(eventProps: EventProps) {
|
|
103
|
-
if (!eventProps.apiKey) {
|
|
104
|
-
logger.error(
|
|
105
|
-
'Missing API key for track call. Please provide your API key.'
|
|
106
|
-
);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (!eventProps.canTrack) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (isEditing()) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (!(isBrowser() || TARGET === 'reactNative')) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return fetch(`https://builder.io/api/v1/track`, {
|
|
122
|
-
method: 'POST',
|
|
123
|
-
body: JSON.stringify({
|
|
124
|
-
events: [await createEvent(eventProps)],
|
|
125
|
-
}),
|
|
126
|
-
headers: {
|
|
127
|
-
'content-type': 'application/json',
|
|
128
|
-
},
|
|
129
|
-
mode: 'cors',
|
|
130
|
-
}).catch((err) => {
|
|
131
|
-
console.error('Failed to track: ', err);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export const track = (args: EventProperties) =>
|
|
136
|
-
_track({ ...args, canTrack: true });
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
function round(num: number) {
|
|
2
|
-
return Math.round(num * 1000) / 1000;
|
|
3
|
-
}
|
|
4
|
-
const findParentElement = (
|
|
5
|
-
target: HTMLElement,
|
|
6
|
-
callback: (element: HTMLElement) => boolean,
|
|
7
|
-
checkElement = true
|
|
8
|
-
): HTMLElement | null => {
|
|
9
|
-
if (!(target instanceof HTMLElement)) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
let parent: HTMLElement | null = checkElement ? target : target.parentElement;
|
|
13
|
-
do {
|
|
14
|
-
if (!parent) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const matches = callback(parent);
|
|
19
|
-
if (matches) {
|
|
20
|
-
return parent;
|
|
21
|
-
}
|
|
22
|
-
} while ((parent = parent.parentElement));
|
|
23
|
-
|
|
24
|
-
return null;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const findBuilderParent = (target: HTMLElement) =>
|
|
28
|
-
findParentElement(target, (el) => {
|
|
29
|
-
const id = el.getAttribute('builder-id') || el.id;
|
|
30
|
-
return Boolean(id?.indexOf('builder-') === 0);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
type Offset = {
|
|
34
|
-
x: number;
|
|
35
|
-
y: number;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const computeOffset = ({
|
|
39
|
-
event,
|
|
40
|
-
target,
|
|
41
|
-
}: {
|
|
42
|
-
event: MouseEvent;
|
|
43
|
-
target: HTMLElement;
|
|
44
|
-
}): Offset => {
|
|
45
|
-
const targetRect = target.getBoundingClientRect();
|
|
46
|
-
const xOffset = event.clientX - targetRect.left;
|
|
47
|
-
const yOffset = event.clientY - targetRect.top;
|
|
48
|
-
|
|
49
|
-
const xRatio = round(xOffset / targetRect.width);
|
|
50
|
-
const yRatio = round(yOffset / targetRect.height);
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
x: xRatio,
|
|
54
|
-
y: yRatio,
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const getInteractionPropertiesForEvent = (event: MouseEvent) => {
|
|
59
|
-
const target = event.target as HTMLElement | null;
|
|
60
|
-
const targetBuilderElement = target && findBuilderParent(target);
|
|
61
|
-
const builderId =
|
|
62
|
-
targetBuilderElement?.getAttribute('builder-id') ||
|
|
63
|
-
targetBuilderElement?.id;
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
targetBuilderElement: builderId || undefined,
|
|
67
|
-
metadata: {
|
|
68
|
-
targetOffset: target ? computeOffset({ event, target }) : undefined,
|
|
69
|
-
builderTargetOffset: targetBuilderElement
|
|
70
|
-
? computeOffset({ event, target: targetBuilderElement })
|
|
71
|
-
: undefined,
|
|
72
|
-
builderElementIndex:
|
|
73
|
-
targetBuilderElement && builderId
|
|
74
|
-
? ([] as Element[]).slice
|
|
75
|
-
.call(document.getElementsByClassName(builderId))
|
|
76
|
-
.indexOf(targetBuilderElement)
|
|
77
|
-
: undefined,
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { CanTrack } from '../types/can-track.js';
|
|
2
|
-
import { getCookie, setCookie } from './cookie.js';
|
|
3
|
-
|
|
4
|
-
const BUILDER_STORE_PREFIX = 'builderio.variations';
|
|
5
|
-
|
|
6
|
-
const getContentTestKey = (id: string) => `${BUILDER_STORE_PREFIX}.${id}`;
|
|
7
|
-
|
|
8
|
-
export const getContentVariationCookie = ({
|
|
9
|
-
contentId,
|
|
10
|
-
canTrack,
|
|
11
|
-
}: { contentId: string } & CanTrack) =>
|
|
12
|
-
getCookie({ name: getContentTestKey(contentId), canTrack });
|
|
13
|
-
|
|
14
|
-
export const setContentVariationCookie = ({
|
|
15
|
-
contentId,
|
|
16
|
-
canTrack,
|
|
17
|
-
value,
|
|
18
|
-
}: {
|
|
19
|
-
contentId: string;
|
|
20
|
-
value: string;
|
|
21
|
-
} & CanTrack) =>
|
|
22
|
-
setCookie({ name: getContentTestKey(contentId), value, canTrack });
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
-
import type { CanTrack } from '../types/can-track.js';
|
|
3
|
-
import { checkIsDefined } from './nullable.js';
|
|
4
|
-
import { getTopLevelDomain } from './url.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
|
|
8
|
-
*/
|
|
9
|
-
export const getCookie = async ({
|
|
10
|
-
name,
|
|
11
|
-
canTrack,
|
|
12
|
-
}: {
|
|
13
|
-
name: string;
|
|
14
|
-
} & CanTrack): Promise<string | undefined> => {
|
|
15
|
-
try {
|
|
16
|
-
if (!canTrack) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Extracted from MDN docs
|
|
22
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#example_2_get_a_sample_cookie_named_test2
|
|
23
|
-
*/
|
|
24
|
-
return document.cookie
|
|
25
|
-
.split('; ')
|
|
26
|
-
.find((row) => row.startsWith(`${name}=`))
|
|
27
|
-
?.split('=')[1];
|
|
28
|
-
} catch (err) {
|
|
29
|
-
console.debug('[COOKIE] GET error: ', err);
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
type CookieConfiguration = Array<
|
|
35
|
-
| ['expires', string]
|
|
36
|
-
| ['path', '/']
|
|
37
|
-
| ['domain', string]
|
|
38
|
-
| ['secure', '']
|
|
39
|
-
| ['SameSite', 'None']
|
|
40
|
-
| [string, string]
|
|
41
|
-
| []
|
|
42
|
-
>;
|
|
43
|
-
|
|
44
|
-
const stringifyCookie = (cookie: CookieConfiguration): string =>
|
|
45
|
-
cookie
|
|
46
|
-
.map(([key, value]) => (value ? `${key}=${value}` : key))
|
|
47
|
-
.filter(checkIsDefined)
|
|
48
|
-
.join('; ');
|
|
49
|
-
|
|
50
|
-
const SECURE_CONFIG: CookieConfiguration = [
|
|
51
|
-
['secure', ''],
|
|
52
|
-
['SameSite', 'None'],
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
const createCookieString = ({
|
|
56
|
-
name,
|
|
57
|
-
value,
|
|
58
|
-
expires,
|
|
59
|
-
}: {
|
|
60
|
-
name: string;
|
|
61
|
-
value: string;
|
|
62
|
-
expires?: Date;
|
|
63
|
-
}) => {
|
|
64
|
-
const secure = isBrowser() ? location.protocol === 'https:' : true;
|
|
65
|
-
|
|
66
|
-
const secureObj: CookieConfiguration = secure ? SECURE_CONFIG : [[]];
|
|
67
|
-
|
|
68
|
-
// TODO: need to know if secure server side
|
|
69
|
-
const expiresObj: CookieConfiguration = expires
|
|
70
|
-
? [['expires', expires.toUTCString()]]
|
|
71
|
-
: [[]];
|
|
72
|
-
|
|
73
|
-
const cookieValue: CookieConfiguration = [
|
|
74
|
-
[name, value],
|
|
75
|
-
...expiresObj,
|
|
76
|
-
['path', '/'],
|
|
77
|
-
['domain', getTopLevelDomain(window.location.hostname)],
|
|
78
|
-
...secureObj,
|
|
79
|
-
];
|
|
80
|
-
const cookie = stringifyCookie(cookieValue);
|
|
81
|
-
|
|
82
|
-
return cookie;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
|
|
87
|
-
*/
|
|
88
|
-
export const setCookie = async ({
|
|
89
|
-
name,
|
|
90
|
-
value,
|
|
91
|
-
expires,
|
|
92
|
-
canTrack,
|
|
93
|
-
}: {
|
|
94
|
-
name: string;
|
|
95
|
-
value: string;
|
|
96
|
-
expires?: Date;
|
|
97
|
-
} & CanTrack): Promise<void> => {
|
|
98
|
-
try {
|
|
99
|
-
if (!canTrack) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const cookie = createCookieString({ name, value, expires });
|
|
103
|
-
document.cookie = cookie;
|
|
104
|
-
} catch (err) {
|
|
105
|
-
console.warn('[COOKIE] SET error: ', err);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { camelToKebabCase } from '../functions/camel-to-kebab-case.js';
|
|
2
|
-
import { checkIsDefined } from './nullable.js';
|
|
3
|
-
|
|
4
|
-
export const convertStyleMapToCSSArray = (
|
|
5
|
-
style: Partial<CSSStyleDeclaration>
|
|
6
|
-
): string[] => {
|
|
7
|
-
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
8
|
-
if (typeof value === 'string') {
|
|
9
|
-
return `${camelToKebabCase(key)}: ${value};`;
|
|
10
|
-
} else {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
return cssProps.filter(checkIsDefined);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const convertStyleMapToCSS = (
|
|
19
|
-
style: Partial<CSSStyleDeclaration>
|
|
20
|
-
): string => convertStyleMapToCSSArray(style).join('\n');
|
|
21
|
-
|
|
22
|
-
export const createCssClass = ({
|
|
23
|
-
mediaQuery,
|
|
24
|
-
className,
|
|
25
|
-
styles,
|
|
26
|
-
}: {
|
|
27
|
-
mediaQuery?: string;
|
|
28
|
-
className: string;
|
|
29
|
-
styles: Partial<CSSStyleDeclaration>;
|
|
30
|
-
}) => {
|
|
31
|
-
const cssClass = `.${className} {
|
|
32
|
-
${convertStyleMapToCSS(styles)}
|
|
33
|
-
}`;
|
|
34
|
-
|
|
35
|
-
if (mediaQuery) {
|
|
36
|
-
return `${mediaQuery} {
|
|
37
|
-
${cssClass}
|
|
38
|
-
}`;
|
|
39
|
-
} else {
|
|
40
|
-
return cssClass;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert deep object to a flat object with dots
|
|
3
|
-
*
|
|
4
|
-
* { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
|
|
5
|
-
*/
|
|
6
|
-
export function flatten<T extends Record<string, any>>(
|
|
7
|
-
object: T,
|
|
8
|
-
path: string | null = null,
|
|
9
|
-
separator = '.'
|
|
10
|
-
): T {
|
|
11
|
-
return Object.keys(object).reduce((acc: T, key: string): T => {
|
|
12
|
-
const value = object[key];
|
|
13
|
-
const newPath = [path, key].filter(Boolean).join(separator);
|
|
14
|
-
const isObject = [
|
|
15
|
-
typeof value === 'object',
|
|
16
|
-
value !== null,
|
|
17
|
-
!(Array.isArray(value) && value.length === 0),
|
|
18
|
-
].every(Boolean);
|
|
19
|
-
|
|
20
|
-
return isObject
|
|
21
|
-
? { ...acc, ...flatten(value, newPath, separator) }
|
|
22
|
-
: { ...acc, [newPath]: value };
|
|
23
|
-
}, {} as T);
|
|
24
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
-
import type { CanTrack } from '../types/can-track.js';
|
|
3
|
-
import type { Nullable } from './nullable.js';
|
|
4
|
-
|
|
5
|
-
const getLocalStorage = () =>
|
|
6
|
-
isBrowser() && typeof localStorage !== 'undefined' ? localStorage : undefined;
|
|
7
|
-
|
|
8
|
-
export const getLocalStorageItem = ({
|
|
9
|
-
key,
|
|
10
|
-
canTrack,
|
|
11
|
-
}: {
|
|
12
|
-
key: string;
|
|
13
|
-
} & CanTrack): Nullable<string> => {
|
|
14
|
-
try {
|
|
15
|
-
if (canTrack) {
|
|
16
|
-
return getLocalStorage()?.getItem(key);
|
|
17
|
-
}
|
|
18
|
-
return undefined;
|
|
19
|
-
} catch (err) {
|
|
20
|
-
console.debug('[LocalStorage] GET error: ', err);
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const setLocalStorageItem = ({
|
|
26
|
-
key,
|
|
27
|
-
canTrack,
|
|
28
|
-
value,
|
|
29
|
-
}: {
|
|
30
|
-
key: string;
|
|
31
|
-
value: string;
|
|
32
|
-
} & CanTrack) => {
|
|
33
|
-
try {
|
|
34
|
-
if (canTrack) {
|
|
35
|
-
getLocalStorage()?.setItem(key, value);
|
|
36
|
-
}
|
|
37
|
-
} catch (err) {
|
|
38
|
-
console.debug('[LocalStorage] SET error: ', err);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
const MSG_PREFIX = '[Builder.io]: ';
|
|
2
|
-
export const logger = {
|
|
3
|
-
log: (...message: any[]) => console.log(MSG_PREFIX, ...message),
|
|
4
|
-
error: (...message: any[]) => console.error(MSG_PREFIX, ...message),
|
|
5
|
-
warn: (...message: any[]) => console.warn(MSG_PREFIX, ...message),
|
|
6
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { CanTrack } from '../types/can-track.js';
|
|
2
|
-
import { getCookie, setCookie } from './cookie.js';
|
|
3
|
-
import { checkIsDefined } from './nullable.js';
|
|
4
|
-
import { uuid } from './uuid.js';
|
|
5
|
-
|
|
6
|
-
const SESSION_LOCAL_STORAGE_KEY = 'builderSessionId';
|
|
7
|
-
|
|
8
|
-
export const getSessionId = async ({
|
|
9
|
-
canTrack,
|
|
10
|
-
}: CanTrack): Promise<string | undefined> => {
|
|
11
|
-
if (!canTrack) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const sessionId = await getCookie({
|
|
16
|
-
name: SESSION_LOCAL_STORAGE_KEY,
|
|
17
|
-
canTrack,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
if (checkIsDefined(sessionId)) {
|
|
21
|
-
return sessionId;
|
|
22
|
-
} else {
|
|
23
|
-
const newSessionId = createSessionId();
|
|
24
|
-
setSessionId({ id: newSessionId, canTrack });
|
|
25
|
-
|
|
26
|
-
return newSessionId;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const createSessionId = () => uuid();
|
|
31
|
-
|
|
32
|
-
export const setSessionId = ({
|
|
33
|
-
id,
|
|
34
|
-
canTrack,
|
|
35
|
-
}: {
|
|
36
|
-
id: string;
|
|
37
|
-
} & CanTrack) =>
|
|
38
|
-
setCookie({ name: SESSION_LOCAL_STORAGE_KEY, value: id, canTrack });
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { getTopLevelDomain } from './url.js';
|
|
2
|
-
|
|
3
|
-
describe('getTopLevelDomain', () => {
|
|
4
|
-
test('handles root domain', () => {
|
|
5
|
-
const output = getTopLevelDomain('example.com');
|
|
6
|
-
expect(output).toBe('example.com');
|
|
7
|
-
});
|
|
8
|
-
test('handles subdomain', () => {
|
|
9
|
-
const output = getTopLevelDomain('wwww.example.com');
|
|
10
|
-
expect(output).toBe('example.com');
|
|
11
|
-
});
|
|
12
|
-
test('handles subdomain with long suffix', () => {
|
|
13
|
-
const output = getTopLevelDomain('www.example.co.uk');
|
|
14
|
-
expect(output).toBe('example.co.uk');
|
|
15
|
-
});
|
|
16
|
-
test('handles localhost', () => {
|
|
17
|
-
const output = getTopLevelDomain('localhost');
|
|
18
|
-
expect(output).toBe('localhost');
|
|
19
|
-
|
|
20
|
-
const output2 = getTopLevelDomain('127.0.0.1');
|
|
21
|
-
expect(output2).toBe('127.0.0.1');
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Only gets one level up from hostname
|
|
3
|
-
* wwww.example.com -> example.com
|
|
4
|
-
* www.example.co.uk -> example.co.uk
|
|
5
|
-
*/
|
|
6
|
-
export const getTopLevelDomain = (host: string) => {
|
|
7
|
-
if (host === 'localhost' || host === '127.0.0.1') {
|
|
8
|
-
return host;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const parts = host.split('.');
|
|
12
|
-
if (parts.length > 2) {
|
|
13
|
-
return parts.slice(1).join('.');
|
|
14
|
-
}
|
|
15
|
-
return host;
|
|
16
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @credit https://stackoverflow.com/a/2117523
|
|
3
|
-
*/
|
|
4
|
-
export function uuidv4() {
|
|
5
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
6
|
-
const r = (Math.random() * 16) | 0,
|
|
7
|
-
v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
8
|
-
return v.toString(16);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Slightly cleaner and smaller UUIDs
|
|
14
|
-
*/
|
|
15
|
-
export function uuid() {
|
|
16
|
-
return uuidv4().replace(/-/g, '');
|
|
17
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { CanTrack } from '../types/can-track.js';
|
|
2
|
-
import { getLocalStorageItem, setLocalStorageItem } from './localStorage.js';
|
|
3
|
-
import { checkIsDefined } from './nullable.js';
|
|
4
|
-
import { uuid } from './uuid.js';
|
|
5
|
-
|
|
6
|
-
const VISITOR_LOCAL_STORAGE_KEY = 'builderVisitorId';
|
|
7
|
-
|
|
8
|
-
export const getVisitorId = ({ canTrack }: CanTrack): string | undefined => {
|
|
9
|
-
if (!canTrack) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const visitorId = getLocalStorageItem({
|
|
14
|
-
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
15
|
-
canTrack,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
if (checkIsDefined(visitorId)) {
|
|
19
|
-
return visitorId;
|
|
20
|
-
} else {
|
|
21
|
-
const newVisitorId = createVisitorId();
|
|
22
|
-
setVisitorId({ id: newVisitorId, canTrack });
|
|
23
|
-
|
|
24
|
-
return newVisitorId;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const createVisitorId = () => uuid();
|
|
29
|
-
|
|
30
|
-
export const setVisitorId = ({
|
|
31
|
-
id,
|
|
32
|
-
canTrack,
|
|
33
|
-
}: {
|
|
34
|
-
id: string;
|
|
35
|
-
} & CanTrack) =>
|
|
36
|
-
setLocalStorageItem({
|
|
37
|
-
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
38
|
-
value: id,
|
|
39
|
-
canTrack,
|
|
40
|
-
});
|