@builder.io/sdk-vue 0.0.1-66 → 0.0.1-69
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/package.json +1 -1
- package/vue2/src/blocks/button/button.vue +8 -1
- package/vue2/src/blocks/columns/columns.vue +22 -12
- package/vue2/src/blocks/embed/embed.vue +1 -1
- package/vue2/src/blocks/form/form.vue +2 -2
- package/vue2/src/blocks/image/image.vue +8 -8
- package/vue2/src/components/render-content/render-content.vue +28 -8
- package/vue2/src/functions/track.js +71 -2
- package/vue2/src/helpers/cookie.js +59 -0
- package/vue2/src/helpers/localStorage.js +34 -0
- package/vue2/src/helpers/nullable.js +4 -0
- package/vue2/src/helpers/sessionId.js +26 -0
- package/vue2/src/helpers/time.js +5 -0
- package/vue2/src/helpers/url.js +10 -0
- package/vue2/src/helpers/url.test.js +15 -0
- package/vue2/src/helpers/uuid.js +13 -0
- package/vue2/src/helpers/visitorId.js +33 -0
- package/vue2/src/types/can-track.js +0 -0
- package/vue3/src/blocks/button/button.vue +8 -1
- package/vue3/src/blocks/columns/columns.vue +22 -12
- package/vue3/src/blocks/embed/embed.vue +1 -1
- package/vue3/src/blocks/form/form.vue +2 -2
- package/vue3/src/components/render-content/render-content.vue +28 -11
- package/vue3/src/functions/track.js +71 -2
- package/vue3/src/helpers/cookie.js +59 -0
- package/vue3/src/helpers/localStorage.js +34 -0
- package/vue3/src/helpers/nullable.js +4 -0
- package/vue3/src/helpers/sessionId.js +26 -0
- package/vue3/src/helpers/time.js +5 -0
- package/vue3/src/helpers/url.js +10 -0
- package/vue3/src/helpers/url.test.js +15 -0
- package/vue3/src/helpers/uuid.js +13 -0
- package/vue3/src/helpers/visitorId.js +33 -0
- package/vue3/src/types/can-track.js +0 -0
package/package.json
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
>
|
|
9
9
|
{{ text }}
|
|
10
10
|
</a>
|
|
11
|
-
<
|
|
11
|
+
<button v-bind="attributes" class="button-2fnk003dqad" v-else>
|
|
12
|
+
{{ text }}
|
|
13
|
+
</button>
|
|
12
14
|
</template>
|
|
13
15
|
<script>
|
|
14
16
|
export default {
|
|
@@ -17,3 +19,8 @@ export default {
|
|
|
17
19
|
props: ["attributes", "text", "link", "openLinkInNewTab"],
|
|
18
20
|
};
|
|
19
21
|
</script>
|
|
22
|
+
<style scoped>
|
|
23
|
+
.button-2fnk003dqad {
|
|
24
|
+
all: unset;
|
|
25
|
+
}
|
|
26
|
+
</style>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="builder-columns div-
|
|
2
|
+
<div class="builder-columns div-4wbls88y960" :style="columnsCssVars">
|
|
3
3
|
<div
|
|
4
|
-
class="builder-column div-
|
|
4
|
+
class="builder-column div-4wbls88y960-2"
|
|
5
5
|
v-for="(column, index) in columns"
|
|
6
6
|
:style="{
|
|
7
7
|
width: getColumnCssWidth(index),
|
|
@@ -10,7 +10,11 @@
|
|
|
10
10
|
}"
|
|
11
11
|
:key="index"
|
|
12
12
|
>
|
|
13
|
-
<render-blocks
|
|
13
|
+
<render-blocks
|
|
14
|
+
:blocks="column.blocks"
|
|
15
|
+
:path="`component.options.columns.${index}.blocks`"
|
|
16
|
+
:parent="builderBlock.id"
|
|
17
|
+
></render-blocks>
|
|
14
18
|
</div>
|
|
15
19
|
</div>
|
|
16
20
|
</template>
|
|
@@ -20,7 +24,13 @@ const RenderBlocks = () => import("../../components/render-blocks.vue");
|
|
|
20
24
|
export default {
|
|
21
25
|
name: "builder-columns",
|
|
22
26
|
components: { "render-blocks": RenderBlocks },
|
|
23
|
-
props: [
|
|
27
|
+
props: [
|
|
28
|
+
"space",
|
|
29
|
+
"columns",
|
|
30
|
+
"stackColumnsAt",
|
|
31
|
+
"reverseColumnsWhenStacked",
|
|
32
|
+
"builderBlock",
|
|
33
|
+
],
|
|
24
34
|
|
|
25
35
|
computed: {
|
|
26
36
|
columnsCssVars() {
|
|
@@ -74,32 +84,32 @@ export default {
|
|
|
74
84
|
};
|
|
75
85
|
</script>
|
|
76
86
|
<style scoped>
|
|
77
|
-
.div-
|
|
87
|
+
.div-4wbls88y960 {
|
|
78
88
|
display: flex;
|
|
79
89
|
align-items: stretch;
|
|
80
90
|
line-height: normal;
|
|
81
91
|
}
|
|
82
|
-
@media (max-width:
|
|
83
|
-
.div-
|
|
92
|
+
@media (max-width: 991px) {
|
|
93
|
+
.div-4wbls88y960 {
|
|
84
94
|
flex-direction: var(--flex-dir-tablet);
|
|
85
95
|
}
|
|
86
96
|
}
|
|
87
97
|
@media (max-width: 639px) {
|
|
88
|
-
.div-
|
|
98
|
+
.div-4wbls88y960 {
|
|
89
99
|
flex-direction: var(--flex-dir);
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
|
-
.div-
|
|
102
|
+
.div-4wbls88y960-2 {
|
|
93
103
|
flex-grow: 1;
|
|
94
104
|
}
|
|
95
|
-
@media (max-width:
|
|
96
|
-
.div-
|
|
105
|
+
@media (max-width: 991px) {
|
|
106
|
+
.div-4wbls88y960-2 {
|
|
97
107
|
width: var(--column-width-tablet) !important;
|
|
98
108
|
margin-left: var(--column-margin-left-tablet) !important;
|
|
99
109
|
}
|
|
100
110
|
}
|
|
101
111
|
@media (max-width: 639px) {
|
|
102
|
-
.div-
|
|
112
|
+
.div-4wbls88y960-2 {
|
|
103
113
|
width: var(--column-width) !important;
|
|
104
114
|
margin-left: var(--column-margin-left) !important;
|
|
105
115
|
}
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
></builder-blocks>
|
|
29
29
|
|
|
30
30
|
<pre
|
|
31
|
-
class="builder-form-error-text pre-
|
|
31
|
+
class="builder-form-error-text pre-t43jfuqn6g"
|
|
32
32
|
v-if="submissionState === 'error' && responseData"
|
|
33
33
|
>
|
|
34
34
|
{{ JSON.stringify(responseData, null, 2) }}
|
|
@@ -301,7 +301,7 @@ export default {
|
|
|
301
301
|
};
|
|
302
302
|
</script>
|
|
303
303
|
<style scoped>
|
|
304
|
-
.pre-
|
|
304
|
+
.pre-t43jfuqn6g {
|
|
305
305
|
padding: 10px;
|
|
306
306
|
color: red;
|
|
307
307
|
text-align: center;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="div-
|
|
2
|
+
<div class="div-cvp1sc2nsao">
|
|
3
3
|
<picture>
|
|
4
4
|
<source type="image/webp" v-if="webpSrcSet" :srcset="webpSrcSet" />
|
|
5
5
|
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
_classStringToObject(
|
|
16
16
|
'builder-image' +
|
|
17
17
|
(this.className ? ' ' + this.className : '') +
|
|
18
|
-
' img-
|
|
18
|
+
' img-cvp1sc2nsao'
|
|
19
19
|
)
|
|
20
20
|
"
|
|
21
21
|
:src="image"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
</picture>
|
|
27
27
|
|
|
28
28
|
<div
|
|
29
|
-
class="builder-image-sizer div-
|
|
29
|
+
class="builder-image-sizer div-cvp1sc2nsao-2"
|
|
30
30
|
v-if="aspectRatio && !(fitContent && ((builderBlock && builderBlock.children) && (builderBlock && builderBlock.children).length))"
|
|
31
31
|
:style="{
|
|
32
32
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
|
|
37
37
|
<slot></slot>
|
|
38
38
|
|
|
39
|
-
<div class="div-
|
|
39
|
+
<div class="div-cvp1sc2nsao-3" v-if="!fitContent">
|
|
40
40
|
<slot></slot>
|
|
41
41
|
</div>
|
|
42
42
|
</div>
|
|
@@ -110,10 +110,10 @@ export default {
|
|
|
110
110
|
};
|
|
111
111
|
</script>
|
|
112
112
|
<style scoped>
|
|
113
|
-
.div-
|
|
113
|
+
.div-cvp1sc2nsao {
|
|
114
114
|
position: relative;
|
|
115
115
|
}
|
|
116
|
-
.img-
|
|
116
|
+
.img-cvp1sc2nsao {
|
|
117
117
|
opacity: 1;
|
|
118
118
|
transition: opacity 0.2s ease-in-out;
|
|
119
119
|
position: absolute;
|
|
@@ -122,12 +122,12 @@ export default {
|
|
|
122
122
|
top: 0px;
|
|
123
123
|
left: 0px;
|
|
124
124
|
}
|
|
125
|
-
.div-
|
|
125
|
+
.div-cvp1sc2nsao-2 {
|
|
126
126
|
width: 100%;
|
|
127
127
|
pointer-events: none;
|
|
128
128
|
font-size: 0;
|
|
129
129
|
}
|
|
130
|
-
.div-
|
|
130
|
+
.div-cvp1sc2nsao-3 {
|
|
131
131
|
display: flex;
|
|
132
132
|
flex-direction: column;
|
|
133
133
|
align-items: stretch;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div
|
|
3
3
|
v-if="useContent"
|
|
4
|
-
@click="
|
|
5
|
-
track('click', {
|
|
6
|
-
contentId: useContent.id,
|
|
7
|
-
})
|
|
8
|
-
"
|
|
4
|
+
@click="onClick($event)"
|
|
9
5
|
:builder-content-id="(useContent && useContent.id)"
|
|
10
6
|
>
|
|
11
7
|
<render-content-styles
|
|
@@ -41,9 +37,17 @@ export default {
|
|
|
41
37
|
"render-content-styles": RenderContentStyles,
|
|
42
38
|
"render-blocks": RenderBlocks,
|
|
43
39
|
},
|
|
44
|
-
props: [
|
|
40
|
+
props: [
|
|
41
|
+
"content",
|
|
42
|
+
"data",
|
|
43
|
+
"canTrack",
|
|
44
|
+
"context",
|
|
45
|
+
"customComponents",
|
|
46
|
+
"model",
|
|
47
|
+
"apiKey",
|
|
48
|
+
],
|
|
45
49
|
|
|
46
|
-
data: () => ({ overrideContent: null, update: 0, overrideState: {}
|
|
50
|
+
data: () => ({ overrideContent: null, update: 0, overrideState: {} }),
|
|
47
51
|
|
|
48
52
|
provide() {
|
|
49
53
|
const _this = this;
|
|
@@ -85,8 +89,11 @@ export default {
|
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
if (this.useContent) {
|
|
88
|
-
track(
|
|
92
|
+
track({
|
|
93
|
+
type: "impression",
|
|
94
|
+
canTrack: this.canTrackToUse,
|
|
89
95
|
contentId: this.useContent.id,
|
|
96
|
+
orgId: this.apiKey,
|
|
90
97
|
});
|
|
91
98
|
} // override normal content in preview mode
|
|
92
99
|
|
|
@@ -150,6 +157,9 @@ export default {
|
|
|
150
157
|
};
|
|
151
158
|
return mergedContent;
|
|
152
159
|
},
|
|
160
|
+
canTrackToUse() {
|
|
161
|
+
return this.canTrack || true;
|
|
162
|
+
},
|
|
153
163
|
contentState() {
|
|
154
164
|
return {
|
|
155
165
|
...this.content?.data?.state,
|
|
@@ -244,6 +254,16 @@ export default {
|
|
|
244
254
|
});
|
|
245
255
|
}
|
|
246
256
|
},
|
|
257
|
+
onClick(_event) {
|
|
258
|
+
if (this.useContent) {
|
|
259
|
+
track({
|
|
260
|
+
type: "click",
|
|
261
|
+
canTrack: this.canTrackToUse,
|
|
262
|
+
contentId: this.useContent.id,
|
|
263
|
+
orgId: this.apiKey,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
},
|
|
247
267
|
evalExpression(expression) {
|
|
248
268
|
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
249
269
|
evaluate({
|
|
@@ -1,7 +1,74 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
1
32
|
import { TARGET } from "../constants/target.js";
|
|
33
|
+
import { getSessionId } from "../helpers/sessionId.js";
|
|
34
|
+
import { getVisitorId } from "../helpers/visitorId.js";
|
|
2
35
|
import { isBrowser } from "./is-browser.js";
|
|
3
36
|
import { isEditing } from "./is-editing.js";
|
|
4
|
-
|
|
37
|
+
const getTrackingEventData = ({ canTrack }) => {
|
|
38
|
+
if (!canTrack) {
|
|
39
|
+
return { visitorId: void 0, sessionId: void 0 };
|
|
40
|
+
}
|
|
41
|
+
const sessionId = getSessionId({ canTrack });
|
|
42
|
+
const visitorId = getVisitorId({ canTrack });
|
|
43
|
+
return {
|
|
44
|
+
sessionId,
|
|
45
|
+
visitorId
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const createEvent = (_a) => {
|
|
49
|
+
var _b = _a, {
|
|
50
|
+
type: eventType,
|
|
51
|
+
canTrack,
|
|
52
|
+
orgId,
|
|
53
|
+
contentId
|
|
54
|
+
} = _b, properties = __objRest(_b, [
|
|
55
|
+
"type",
|
|
56
|
+
"canTrack",
|
|
57
|
+
"orgId",
|
|
58
|
+
"contentId"
|
|
59
|
+
]);
|
|
60
|
+
return {
|
|
61
|
+
type: eventType,
|
|
62
|
+
data: __spreadProps(__spreadValues(__spreadValues({}, properties), getTrackingEventData({ canTrack })), {
|
|
63
|
+
ownerId: orgId,
|
|
64
|
+
contentId
|
|
65
|
+
})
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
function track(eventProps) {
|
|
69
|
+
if (!eventProps.canTrack) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
5
72
|
if (isEditing()) {
|
|
6
73
|
return;
|
|
7
74
|
}
|
|
@@ -10,7 +77,9 @@ function track(event, properties) {
|
|
|
10
77
|
}
|
|
11
78
|
return fetch(`https://builder.io/api/v1/track`, {
|
|
12
79
|
method: "POST",
|
|
13
|
-
body: JSON.stringify({
|
|
80
|
+
body: JSON.stringify({
|
|
81
|
+
events: [createEvent(eventProps)]
|
|
82
|
+
}),
|
|
14
83
|
headers: {
|
|
15
84
|
"content-type": "application/json"
|
|
16
85
|
},
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { isBrowser } from "../functions/is-browser";
|
|
2
|
+
import { getTopLevelDomain } from "./url";
|
|
3
|
+
const getCookie = ({
|
|
4
|
+
name,
|
|
5
|
+
canTrack
|
|
6
|
+
}) => {
|
|
7
|
+
var _a;
|
|
8
|
+
try {
|
|
9
|
+
if (!canTrack) {
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
return (_a = document.cookie.split("; ").find((row) => row.startsWith(`${name}=`))) == null ? void 0 : _a.split("=")[1];
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.debug("[COOKIE] GET error: ", err);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).join("; ");
|
|
18
|
+
const SECURE_CONFIG = [
|
|
19
|
+
["secure", ""],
|
|
20
|
+
["SameSite", "None"]
|
|
21
|
+
];
|
|
22
|
+
const createCookieString = ({
|
|
23
|
+
name,
|
|
24
|
+
value,
|
|
25
|
+
expires
|
|
26
|
+
}) => {
|
|
27
|
+
const secure = isBrowser() ? location.protocol === "https:" : true;
|
|
28
|
+
const secureObj = secure ? SECURE_CONFIG : [[]];
|
|
29
|
+
const expiresObj = expires ? [["expires", expires.toUTCString()]] : [[]];
|
|
30
|
+
const cookieValue = [
|
|
31
|
+
[name, value],
|
|
32
|
+
...expiresObj,
|
|
33
|
+
["path", "/"],
|
|
34
|
+
["domain", getTopLevelDomain(window.location.hostname)],
|
|
35
|
+
...secureObj
|
|
36
|
+
];
|
|
37
|
+
const cookie = stringifyCookie(cookieValue);
|
|
38
|
+
return cookie;
|
|
39
|
+
};
|
|
40
|
+
const setCookie = ({
|
|
41
|
+
name,
|
|
42
|
+
value,
|
|
43
|
+
expires,
|
|
44
|
+
canTrack
|
|
45
|
+
}) => {
|
|
46
|
+
try {
|
|
47
|
+
if (!canTrack) {
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
50
|
+
const cookie = createCookieString({ name, value, expires });
|
|
51
|
+
document.cookie = cookie;
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.warn("[COOKIE] SET error: ", err);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
getCookie,
|
|
58
|
+
setCookie
|
|
59
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isBrowser } from "../functions/is-browser";
|
|
2
|
+
const getLocalStorage = () => isBrowser() && typeof localStorage !== "undefined" ? localStorage : void 0;
|
|
3
|
+
const getLocalStorageItem = ({
|
|
4
|
+
key,
|
|
5
|
+
canTrack
|
|
6
|
+
}) => {
|
|
7
|
+
var _a;
|
|
8
|
+
try {
|
|
9
|
+
if (canTrack) {
|
|
10
|
+
return (_a = getLocalStorage()) == null ? void 0 : _a.getItem(key);
|
|
11
|
+
}
|
|
12
|
+
return void 0;
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.debug("[LocalStorage] GET error: ", err);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const setLocalStorageItem = ({
|
|
18
|
+
key,
|
|
19
|
+
canTrack,
|
|
20
|
+
value
|
|
21
|
+
}) => {
|
|
22
|
+
var _a;
|
|
23
|
+
try {
|
|
24
|
+
if (canTrack) {
|
|
25
|
+
(_a = getLocalStorage()) == null ? void 0 : _a.setItem(key, value);
|
|
26
|
+
}
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.debug("[LocalStorage] SET error: ", err);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
getLocalStorageItem,
|
|
33
|
+
setLocalStorageItem
|
|
34
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getCookie, setCookie } from "./cookie";
|
|
2
|
+
import { checkIsDefined } from "./nullable";
|
|
3
|
+
import { uuid } from "./uuid";
|
|
4
|
+
const SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
|
|
5
|
+
const getSessionId = ({ canTrack }) => {
|
|
6
|
+
if (!canTrack) {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
const sessionId = getCookie({ name: SESSION_LOCAL_STORAGE_KEY, canTrack });
|
|
10
|
+
if (checkIsDefined(sessionId)) {
|
|
11
|
+
return sessionId;
|
|
12
|
+
} else {
|
|
13
|
+
const newSessionId = createSessionId();
|
|
14
|
+
setSessionId({ id: newSessionId, canTrack });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const createSessionId = () => uuid();
|
|
18
|
+
const setSessionId = ({
|
|
19
|
+
id,
|
|
20
|
+
canTrack
|
|
21
|
+
}) => setCookie({ name: SESSION_LOCAL_STORAGE_KEY, value: id, canTrack });
|
|
22
|
+
export {
|
|
23
|
+
createSessionId,
|
|
24
|
+
getSessionId,
|
|
25
|
+
setSessionId
|
|
26
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getTopLevelDomain } from "./url.js";
|
|
2
|
+
describe("getTopLevelDomain", () => {
|
|
3
|
+
test("handles root domain", () => {
|
|
4
|
+
const output = getTopLevelDomain("example.com");
|
|
5
|
+
expect(output).toBe("example.com");
|
|
6
|
+
});
|
|
7
|
+
test("handles subdomain", () => {
|
|
8
|
+
const output = getTopLevelDomain("wwww.example.com");
|
|
9
|
+
expect(output).toBe("example.com");
|
|
10
|
+
});
|
|
11
|
+
test("handles subdomain with long suffix", () => {
|
|
12
|
+
const output = getTopLevelDomain("www.example.co.uk");
|
|
13
|
+
expect(output).toBe("example.co.uk");
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function uuidv4() {
|
|
2
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
3
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
4
|
+
return v.toString(16);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
function uuid() {
|
|
8
|
+
return uuidv4().replace(/-/g, "");
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
uuid,
|
|
12
|
+
uuidv4
|
|
13
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getLocalStorageItem, setLocalStorageItem } from "./localStorage";
|
|
2
|
+
import { checkIsDefined } from "./nullable";
|
|
3
|
+
import { uuid } from "./uuid";
|
|
4
|
+
const VISITOR_LOCAL_STORAGE_KEY = "builderVisitorId";
|
|
5
|
+
const getVisitorId = ({ canTrack }) => {
|
|
6
|
+
if (!canTrack) {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
const visitorId = getLocalStorageItem({
|
|
10
|
+
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
11
|
+
canTrack
|
|
12
|
+
});
|
|
13
|
+
if (checkIsDefined(visitorId)) {
|
|
14
|
+
return visitorId;
|
|
15
|
+
} else {
|
|
16
|
+
const newVisitorId = createVisitorId();
|
|
17
|
+
setVisitorId({ id: newVisitorId, canTrack });
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const createVisitorId = () => uuid();
|
|
21
|
+
const setVisitorId = ({
|
|
22
|
+
id,
|
|
23
|
+
canTrack
|
|
24
|
+
}) => setLocalStorageItem({
|
|
25
|
+
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
26
|
+
value: id,
|
|
27
|
+
canTrack
|
|
28
|
+
});
|
|
29
|
+
export {
|
|
30
|
+
createVisitorId,
|
|
31
|
+
getVisitorId,
|
|
32
|
+
setVisitorId
|
|
33
|
+
};
|
|
File without changes
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
</template>
|
|
12
12
|
|
|
13
13
|
<template v-else>
|
|
14
|
-
<
|
|
14
|
+
<button v-bind="attributes" class="button-2oa2wtipkzk">
|
|
15
|
+
{{ text }}
|
|
16
|
+
</button>
|
|
15
17
|
</template>
|
|
16
18
|
</template>
|
|
17
19
|
<script>
|
|
@@ -23,3 +25,8 @@ export default {
|
|
|
23
25
|
props: ["attributes", "text", "link", "openLinkInNewTab"],
|
|
24
26
|
};
|
|
25
27
|
</script>
|
|
28
|
+
<style scoped>
|
|
29
|
+
.button-2oa2wtipkzk {
|
|
30
|
+
all: unset;
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="builder-columns div-
|
|
2
|
+
<div class="builder-columns div-361b1o6wv2k" :style="columnsCssVars">
|
|
3
3
|
<template :key="index" v-for="(column, index) in columns">
|
|
4
4
|
<div
|
|
5
|
-
class="builder-column div-
|
|
5
|
+
class="builder-column div-361b1o6wv2k-2"
|
|
6
6
|
:style="{
|
|
7
7
|
width: getColumnCssWidth(index),
|
|
8
8
|
marginLeft: `${index === 0 ? 0 : getGutterSize()}px`,
|
|
9
9
|
...columnCssVars,
|
|
10
10
|
}"
|
|
11
11
|
>
|
|
12
|
-
<render-blocks
|
|
12
|
+
<render-blocks
|
|
13
|
+
:blocks="column.blocks"
|
|
14
|
+
:path="`component.options.columns.${index}.blocks`"
|
|
15
|
+
:parent="builderBlock.id"
|
|
16
|
+
></render-blocks>
|
|
13
17
|
</div>
|
|
14
18
|
</template>
|
|
15
19
|
</div>
|
|
@@ -22,7 +26,13 @@ const RenderBlocks = () => import("../../components/render-blocks.vue");
|
|
|
22
26
|
export default {
|
|
23
27
|
name: "builder-columns",
|
|
24
28
|
components: { "render-blocks": defineAsyncComponent(RenderBlocks) },
|
|
25
|
-
props: [
|
|
29
|
+
props: [
|
|
30
|
+
"space",
|
|
31
|
+
"columns",
|
|
32
|
+
"stackColumnsAt",
|
|
33
|
+
"reverseColumnsWhenStacked",
|
|
34
|
+
"builderBlock",
|
|
35
|
+
],
|
|
26
36
|
|
|
27
37
|
computed: {
|
|
28
38
|
columnsCssVars() {
|
|
@@ -76,32 +86,32 @@ export default {
|
|
|
76
86
|
};
|
|
77
87
|
</script>
|
|
78
88
|
<style scoped>
|
|
79
|
-
.div-
|
|
89
|
+
.div-361b1o6wv2k {
|
|
80
90
|
display: flex;
|
|
81
91
|
align-items: stretch;
|
|
82
92
|
line-height: normal;
|
|
83
93
|
}
|
|
84
|
-
@media (max-width:
|
|
85
|
-
.div-
|
|
94
|
+
@media (max-width: 991px) {
|
|
95
|
+
.div-361b1o6wv2k {
|
|
86
96
|
flex-direction: var(--flex-dir-tablet);
|
|
87
97
|
}
|
|
88
98
|
}
|
|
89
99
|
@media (max-width: 639px) {
|
|
90
|
-
.div-
|
|
100
|
+
.div-361b1o6wv2k {
|
|
91
101
|
flex-direction: var(--flex-dir);
|
|
92
102
|
}
|
|
93
103
|
}
|
|
94
|
-
.div-
|
|
104
|
+
.div-361b1o6wv2k-2 {
|
|
95
105
|
flex-grow: 1;
|
|
96
106
|
}
|
|
97
|
-
@media (max-width:
|
|
98
|
-
.div-
|
|
107
|
+
@media (max-width: 991px) {
|
|
108
|
+
.div-361b1o6wv2k-2 {
|
|
99
109
|
width: var(--column-width-tablet) !important;
|
|
100
110
|
margin-left: var(--column-margin-left-tablet) !important;
|
|
101
111
|
}
|
|
102
112
|
}
|
|
103
113
|
@media (max-width: 639px) {
|
|
104
|
-
.div-
|
|
114
|
+
.div-361b1o6wv2k-2 {
|
|
105
115
|
width: var(--column-width) !important;
|
|
106
116
|
margin-left: var(--column-margin-left) !important;
|
|
107
117
|
}
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
</template>
|
|
30
30
|
|
|
31
31
|
<template v-if="submissionState === 'error' && responseData">
|
|
32
|
-
<pre class="builder-form-error-text pre-
|
|
32
|
+
<pre class="builder-form-error-text pre-7jvpanrlkn">
|
|
33
33
|
{{ JSON.stringify(responseData, null, 2) }}
|
|
34
34
|
</pre>
|
|
35
35
|
</template>
|
|
@@ -306,7 +306,7 @@ export default {
|
|
|
306
306
|
};
|
|
307
307
|
</script>
|
|
308
308
|
<style scoped>
|
|
309
|
-
.pre-
|
|
309
|
+
.pre-7jvpanrlkn {
|
|
310
310
|
padding: 10px;
|
|
311
311
|
color: red;
|
|
312
312
|
text-align: center;
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<template v-if="useContent">
|
|
3
|
-
<div
|
|
4
|
-
@click="
|
|
5
|
-
track('click', {
|
|
6
|
-
contentId: useContent.id,
|
|
7
|
-
})
|
|
8
|
-
"
|
|
9
|
-
:builder-content-id="(useContent && useContent.id)"
|
|
10
|
-
>
|
|
3
|
+
<div @click="onClick($event)" :builder-content-id="(useContent && useContent.id)">
|
|
11
4
|
<template v-if="shouldRenderContentStyles">
|
|
12
5
|
<render-content-styles
|
|
13
6
|
:cssCode="((useContent && useContent.data) && (useContent && useContent.data).cssCode)"
|
|
@@ -45,9 +38,17 @@ export default {
|
|
|
45
38
|
"render-content-styles": defineAsyncComponent(RenderContentStyles),
|
|
46
39
|
"render-blocks": defineAsyncComponent(RenderBlocks),
|
|
47
40
|
},
|
|
48
|
-
props: [
|
|
41
|
+
props: [
|
|
42
|
+
"content",
|
|
43
|
+
"data",
|
|
44
|
+
"canTrack",
|
|
45
|
+
"context",
|
|
46
|
+
"customComponents",
|
|
47
|
+
"model",
|
|
48
|
+
"apiKey",
|
|
49
|
+
],
|
|
49
50
|
|
|
50
|
-
data: () => ({ overrideContent: null, update: 0, overrideState: {}
|
|
51
|
+
data: () => ({ overrideContent: null, update: 0, overrideState: {} }),
|
|
51
52
|
|
|
52
53
|
provide() {
|
|
53
54
|
const _this = this;
|
|
@@ -89,8 +90,11 @@ export default {
|
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
if (this.useContent) {
|
|
92
|
-
track(
|
|
93
|
+
track({
|
|
94
|
+
type: "impression",
|
|
95
|
+
canTrack: this.canTrackToUse,
|
|
93
96
|
contentId: this.useContent.id,
|
|
97
|
+
orgId: this.apiKey,
|
|
94
98
|
});
|
|
95
99
|
} // override normal content in preview mode
|
|
96
100
|
|
|
@@ -154,6 +158,9 @@ export default {
|
|
|
154
158
|
};
|
|
155
159
|
return mergedContent;
|
|
156
160
|
},
|
|
161
|
+
canTrackToUse() {
|
|
162
|
+
return this.canTrack || true;
|
|
163
|
+
},
|
|
157
164
|
contentState() {
|
|
158
165
|
return {
|
|
159
166
|
...this.content?.data?.state,
|
|
@@ -248,6 +255,16 @@ export default {
|
|
|
248
255
|
});
|
|
249
256
|
}
|
|
250
257
|
},
|
|
258
|
+
onClick(_event) {
|
|
259
|
+
if (this.useContent) {
|
|
260
|
+
track({
|
|
261
|
+
type: "click",
|
|
262
|
+
canTrack: this.canTrackToUse,
|
|
263
|
+
contentId: this.useContent.id,
|
|
264
|
+
orgId: this.apiKey,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
},
|
|
251
268
|
evalExpression(expression) {
|
|
252
269
|
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
253
270
|
evaluate({
|
|
@@ -1,7 +1,74 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
1
32
|
import { TARGET } from "../constants/target.js";
|
|
33
|
+
import { getSessionId } from "../helpers/sessionId.js";
|
|
34
|
+
import { getVisitorId } from "../helpers/visitorId.js";
|
|
2
35
|
import { isBrowser } from "./is-browser.js";
|
|
3
36
|
import { isEditing } from "./is-editing.js";
|
|
4
|
-
|
|
37
|
+
const getTrackingEventData = ({ canTrack }) => {
|
|
38
|
+
if (!canTrack) {
|
|
39
|
+
return { visitorId: void 0, sessionId: void 0 };
|
|
40
|
+
}
|
|
41
|
+
const sessionId = getSessionId({ canTrack });
|
|
42
|
+
const visitorId = getVisitorId({ canTrack });
|
|
43
|
+
return {
|
|
44
|
+
sessionId,
|
|
45
|
+
visitorId
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const createEvent = (_a) => {
|
|
49
|
+
var _b = _a, {
|
|
50
|
+
type: eventType,
|
|
51
|
+
canTrack,
|
|
52
|
+
orgId,
|
|
53
|
+
contentId
|
|
54
|
+
} = _b, properties = __objRest(_b, [
|
|
55
|
+
"type",
|
|
56
|
+
"canTrack",
|
|
57
|
+
"orgId",
|
|
58
|
+
"contentId"
|
|
59
|
+
]);
|
|
60
|
+
return {
|
|
61
|
+
type: eventType,
|
|
62
|
+
data: __spreadProps(__spreadValues(__spreadValues({}, properties), getTrackingEventData({ canTrack })), {
|
|
63
|
+
ownerId: orgId,
|
|
64
|
+
contentId
|
|
65
|
+
})
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
function track(eventProps) {
|
|
69
|
+
if (!eventProps.canTrack) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
5
72
|
if (isEditing()) {
|
|
6
73
|
return;
|
|
7
74
|
}
|
|
@@ -10,7 +77,9 @@ function track(event, properties) {
|
|
|
10
77
|
}
|
|
11
78
|
return fetch(`https://builder.io/api/v1/track`, {
|
|
12
79
|
method: "POST",
|
|
13
|
-
body: JSON.stringify({
|
|
80
|
+
body: JSON.stringify({
|
|
81
|
+
events: [createEvent(eventProps)]
|
|
82
|
+
}),
|
|
14
83
|
headers: {
|
|
15
84
|
"content-type": "application/json"
|
|
16
85
|
},
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { isBrowser } from "../functions/is-browser";
|
|
2
|
+
import { getTopLevelDomain } from "./url";
|
|
3
|
+
const getCookie = ({
|
|
4
|
+
name,
|
|
5
|
+
canTrack
|
|
6
|
+
}) => {
|
|
7
|
+
var _a;
|
|
8
|
+
try {
|
|
9
|
+
if (!canTrack) {
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
return (_a = document.cookie.split("; ").find((row) => row.startsWith(`${name}=`))) == null ? void 0 : _a.split("=")[1];
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.debug("[COOKIE] GET error: ", err);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).join("; ");
|
|
18
|
+
const SECURE_CONFIG = [
|
|
19
|
+
["secure", ""],
|
|
20
|
+
["SameSite", "None"]
|
|
21
|
+
];
|
|
22
|
+
const createCookieString = ({
|
|
23
|
+
name,
|
|
24
|
+
value,
|
|
25
|
+
expires
|
|
26
|
+
}) => {
|
|
27
|
+
const secure = isBrowser() ? location.protocol === "https:" : true;
|
|
28
|
+
const secureObj = secure ? SECURE_CONFIG : [[]];
|
|
29
|
+
const expiresObj = expires ? [["expires", expires.toUTCString()]] : [[]];
|
|
30
|
+
const cookieValue = [
|
|
31
|
+
[name, value],
|
|
32
|
+
...expiresObj,
|
|
33
|
+
["path", "/"],
|
|
34
|
+
["domain", getTopLevelDomain(window.location.hostname)],
|
|
35
|
+
...secureObj
|
|
36
|
+
];
|
|
37
|
+
const cookie = stringifyCookie(cookieValue);
|
|
38
|
+
return cookie;
|
|
39
|
+
};
|
|
40
|
+
const setCookie = ({
|
|
41
|
+
name,
|
|
42
|
+
value,
|
|
43
|
+
expires,
|
|
44
|
+
canTrack
|
|
45
|
+
}) => {
|
|
46
|
+
try {
|
|
47
|
+
if (!canTrack) {
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
50
|
+
const cookie = createCookieString({ name, value, expires });
|
|
51
|
+
document.cookie = cookie;
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.warn("[COOKIE] SET error: ", err);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
getCookie,
|
|
58
|
+
setCookie
|
|
59
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isBrowser } from "../functions/is-browser";
|
|
2
|
+
const getLocalStorage = () => isBrowser() && typeof localStorage !== "undefined" ? localStorage : void 0;
|
|
3
|
+
const getLocalStorageItem = ({
|
|
4
|
+
key,
|
|
5
|
+
canTrack
|
|
6
|
+
}) => {
|
|
7
|
+
var _a;
|
|
8
|
+
try {
|
|
9
|
+
if (canTrack) {
|
|
10
|
+
return (_a = getLocalStorage()) == null ? void 0 : _a.getItem(key);
|
|
11
|
+
}
|
|
12
|
+
return void 0;
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.debug("[LocalStorage] GET error: ", err);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const setLocalStorageItem = ({
|
|
18
|
+
key,
|
|
19
|
+
canTrack,
|
|
20
|
+
value
|
|
21
|
+
}) => {
|
|
22
|
+
var _a;
|
|
23
|
+
try {
|
|
24
|
+
if (canTrack) {
|
|
25
|
+
(_a = getLocalStorage()) == null ? void 0 : _a.setItem(key, value);
|
|
26
|
+
}
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.debug("[LocalStorage] SET error: ", err);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
getLocalStorageItem,
|
|
33
|
+
setLocalStorageItem
|
|
34
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getCookie, setCookie } from "./cookie";
|
|
2
|
+
import { checkIsDefined } from "./nullable";
|
|
3
|
+
import { uuid } from "./uuid";
|
|
4
|
+
const SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
|
|
5
|
+
const getSessionId = ({ canTrack }) => {
|
|
6
|
+
if (!canTrack) {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
const sessionId = getCookie({ name: SESSION_LOCAL_STORAGE_KEY, canTrack });
|
|
10
|
+
if (checkIsDefined(sessionId)) {
|
|
11
|
+
return sessionId;
|
|
12
|
+
} else {
|
|
13
|
+
const newSessionId = createSessionId();
|
|
14
|
+
setSessionId({ id: newSessionId, canTrack });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const createSessionId = () => uuid();
|
|
18
|
+
const setSessionId = ({
|
|
19
|
+
id,
|
|
20
|
+
canTrack
|
|
21
|
+
}) => setCookie({ name: SESSION_LOCAL_STORAGE_KEY, value: id, canTrack });
|
|
22
|
+
export {
|
|
23
|
+
createSessionId,
|
|
24
|
+
getSessionId,
|
|
25
|
+
setSessionId
|
|
26
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getTopLevelDomain } from "./url.js";
|
|
2
|
+
describe("getTopLevelDomain", () => {
|
|
3
|
+
test("handles root domain", () => {
|
|
4
|
+
const output = getTopLevelDomain("example.com");
|
|
5
|
+
expect(output).toBe("example.com");
|
|
6
|
+
});
|
|
7
|
+
test("handles subdomain", () => {
|
|
8
|
+
const output = getTopLevelDomain("wwww.example.com");
|
|
9
|
+
expect(output).toBe("example.com");
|
|
10
|
+
});
|
|
11
|
+
test("handles subdomain with long suffix", () => {
|
|
12
|
+
const output = getTopLevelDomain("www.example.co.uk");
|
|
13
|
+
expect(output).toBe("example.co.uk");
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function uuidv4() {
|
|
2
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
3
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
4
|
+
return v.toString(16);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
function uuid() {
|
|
8
|
+
return uuidv4().replace(/-/g, "");
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
uuid,
|
|
12
|
+
uuidv4
|
|
13
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getLocalStorageItem, setLocalStorageItem } from "./localStorage";
|
|
2
|
+
import { checkIsDefined } from "./nullable";
|
|
3
|
+
import { uuid } from "./uuid";
|
|
4
|
+
const VISITOR_LOCAL_STORAGE_KEY = "builderVisitorId";
|
|
5
|
+
const getVisitorId = ({ canTrack }) => {
|
|
6
|
+
if (!canTrack) {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
const visitorId = getLocalStorageItem({
|
|
10
|
+
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
11
|
+
canTrack
|
|
12
|
+
});
|
|
13
|
+
if (checkIsDefined(visitorId)) {
|
|
14
|
+
return visitorId;
|
|
15
|
+
} else {
|
|
16
|
+
const newVisitorId = createVisitorId();
|
|
17
|
+
setVisitorId({ id: newVisitorId, canTrack });
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const createVisitorId = () => uuid();
|
|
21
|
+
const setVisitorId = ({
|
|
22
|
+
id,
|
|
23
|
+
canTrack
|
|
24
|
+
}) => setLocalStorageItem({
|
|
25
|
+
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
26
|
+
value: id,
|
|
27
|
+
canTrack
|
|
28
|
+
});
|
|
29
|
+
export {
|
|
30
|
+
createVisitorId,
|
|
31
|
+
getVisitorId,
|
|
32
|
+
setVisitorId
|
|
33
|
+
};
|
|
File without changes
|