@dotcms/analytics 1.2.5-next.2 → 1.2.5-next.4
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.
|
@@ -96,8 +96,8 @@ export interface DotCMSEventUtmData {
|
|
|
96
96
|
export type DotCMSEventPageData = Pick<DotCMSBrowserData, 'url' | 'doc_path' | 'doc_hash' | 'doc_search' | 'doc_host' | 'doc_protocol' | 'doc_encoding'> & {
|
|
97
97
|
/** Page title */
|
|
98
98
|
title: string | undefined;
|
|
99
|
-
/**
|
|
100
|
-
|
|
99
|
+
/** Locale identifier (e.g., es-es, en-us) */
|
|
100
|
+
locale_id: string;
|
|
101
101
|
/** Persona identifier */
|
|
102
102
|
persona?: string;
|
|
103
103
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ANALYTICS_JS_DEFAULT_PROPERTIES as
|
|
1
|
+
import { ANALYTICS_JS_DEFAULT_PROPERTIES as T, SESSION_STORAGE_KEY as h, DEFAULT_SESSION_TIMEOUT_MINUTES as p, USER_ID_KEY as f, EXPECTED_UTM_KEYS as I, CONTENTLET_CLASS as m, DEFAULT_IMPRESSION_MUTATION_OBSERVER_DEBOUNCE_MS as D } from "../constants/dot-analytics.constants.js";
|
|
2
2
|
import { DotLogger as y } from "../dot-analytics.logger.js";
|
|
3
3
|
function P(t) {
|
|
4
4
|
const e = [];
|
|
5
5
|
return t.siteAuth?.trim() || e.push('"siteAuth"'), t.server?.trim() || e.push('"server"'), e.length > 0 ? e : null;
|
|
6
6
|
}
|
|
7
|
-
let
|
|
8
|
-
const
|
|
7
|
+
let u = null, l = null;
|
|
8
|
+
const g = (t) => {
|
|
9
9
|
const e = Date.now(), n = Math.random().toString(36).substr(2, 9), s = Math.random().toString(36).substr(2, 9);
|
|
10
10
|
return `${t}_${e}_${n}${s}`;
|
|
11
11
|
}, w = {
|
|
@@ -48,7 +48,7 @@ const l = (t) => {
|
|
|
48
48
|
}, E = () => {
|
|
49
49
|
let t = w.getItem(f);
|
|
50
50
|
if (!t) {
|
|
51
|
-
t =
|
|
51
|
+
t = g("user");
|
|
52
52
|
try {
|
|
53
53
|
w.setItem(f, t);
|
|
54
54
|
} catch {
|
|
@@ -65,14 +65,14 @@ const l = (t) => {
|
|
|
65
65
|
}, v = () => {
|
|
66
66
|
const t = Date.now();
|
|
67
67
|
if (typeof window > "u")
|
|
68
|
-
return
|
|
68
|
+
return g("session_fallback");
|
|
69
69
|
try {
|
|
70
|
-
const e = sessionStorage.getItem(
|
|
70
|
+
const e = sessionStorage.getItem(h);
|
|
71
71
|
if (e) {
|
|
72
|
-
const { sessionId: o, startTime: r, lastActivity: c } = JSON.parse(e), a = !C(r),
|
|
73
|
-
if (a &&
|
|
72
|
+
const { sessionId: o, startTime: r, lastActivity: c } = JSON.parse(e), a = !C(r), d = t - c < p * 60 * 1e3;
|
|
73
|
+
if (a && d)
|
|
74
74
|
return sessionStorage.setItem(
|
|
75
|
-
|
|
75
|
+
h,
|
|
76
76
|
JSON.stringify({
|
|
77
77
|
sessionId: o,
|
|
78
78
|
startTime: r,
|
|
@@ -80,14 +80,14 @@ const l = (t) => {
|
|
|
80
80
|
})
|
|
81
81
|
), o;
|
|
82
82
|
}
|
|
83
|
-
const n =
|
|
83
|
+
const n = g("session"), s = {
|
|
84
84
|
sessionId: n,
|
|
85
85
|
startTime: t,
|
|
86
86
|
lastActivity: t
|
|
87
87
|
};
|
|
88
|
-
return sessionStorage.setItem(
|
|
88
|
+
return sessionStorage.setItem(h, JSON.stringify(s)), n;
|
|
89
89
|
} catch {
|
|
90
|
-
return
|
|
90
|
+
return g("session_fallback");
|
|
91
91
|
}
|
|
92
92
|
}, x = (t) => {
|
|
93
93
|
const e = v(), n = E(), s = A();
|
|
@@ -97,11 +97,11 @@ const l = (t) => {
|
|
|
97
97
|
user_id: n,
|
|
98
98
|
device: s
|
|
99
99
|
};
|
|
100
|
-
}, _ = () =>
|
|
100
|
+
}, _ = () => u || (u = {
|
|
101
101
|
user_language: navigator.language,
|
|
102
102
|
doc_encoding: document.characterSet || document.charset,
|
|
103
103
|
screen_resolution: typeof screen < "u" && screen.width && screen.height ? `${screen.width}x${screen.height}` : ""
|
|
104
|
-
},
|
|
104
|
+
}, u), A = () => {
|
|
105
105
|
const t = _(), e = window.innerWidth || document.documentElement.clientWidth || 0, n = window.innerHeight || document.documentElement.clientHeight || 0;
|
|
106
106
|
return {
|
|
107
107
|
screen_resolution: t.screen_resolution ?? "",
|
|
@@ -111,8 +111,8 @@ const l = (t) => {
|
|
|
111
111
|
};
|
|
112
112
|
}, b = (t) => {
|
|
113
113
|
const e = t.search;
|
|
114
|
-
if (
|
|
115
|
-
return
|
|
114
|
+
if (l && l.search === e)
|
|
115
|
+
return l.params;
|
|
116
116
|
const n = new URLSearchParams(e), s = {};
|
|
117
117
|
return I.forEach((o) => {
|
|
118
118
|
const r = n.get(o);
|
|
@@ -120,7 +120,7 @@ const l = (t) => {
|
|
|
120
120
|
const c = o.replace("utm_", "");
|
|
121
121
|
s[c] = r;
|
|
122
122
|
}
|
|
123
|
-
}),
|
|
123
|
+
}), l = { search: e, params: s }, s;
|
|
124
124
|
}, O = () => {
|
|
125
125
|
try {
|
|
126
126
|
const t = (/* @__PURE__ */ new Date()).getTimezoneOffset(), e = t > 0 ? "-" : "+", n = Math.abs(t), s = Math.floor(n / 60), o = n % 60;
|
|
@@ -138,9 +138,9 @@ const l = (t) => {
|
|
|
138
138
|
}, Y = (t, e = typeof window < "u" ? window.location : {}) => {
|
|
139
139
|
const n = M(), s = _(), { properties: o } = t, r = {};
|
|
140
140
|
Object.keys(o).forEach((i) => {
|
|
141
|
-
|
|
141
|
+
T.includes(i) || (r[i] = o[i]);
|
|
142
142
|
});
|
|
143
|
-
const c = {
|
|
143
|
+
const c = t.context?.device?.language?.toLowerCase() ?? "", a = {
|
|
144
144
|
url: e.href,
|
|
145
145
|
doc_encoding: s.doc_encoding,
|
|
146
146
|
doc_hash: e.hash,
|
|
@@ -148,12 +148,13 @@ const l = (t) => {
|
|
|
148
148
|
doc_search: e.search,
|
|
149
149
|
doc_host: e.hostname,
|
|
150
150
|
doc_path: e.pathname,
|
|
151
|
-
title: o.title ?? document?.title
|
|
152
|
-
|
|
151
|
+
title: o.title ?? document?.title,
|
|
152
|
+
locale_id: c
|
|
153
|
+
}, d = b(e);
|
|
153
154
|
return {
|
|
154
155
|
...t,
|
|
155
|
-
page:
|
|
156
|
-
...Object.keys(
|
|
156
|
+
page: a,
|
|
157
|
+
...Object.keys(d).length > 0 && { utm: d },
|
|
157
158
|
// Only include custom if there are user-provided properties
|
|
158
159
|
...Object.keys(r).length > 0 && { custom: r },
|
|
159
160
|
local_time: n
|
|
@@ -178,16 +179,16 @@ function F(t) {
|
|
|
178
179
|
baseType: t.dataset.dotBasetype || ""
|
|
179
180
|
};
|
|
180
181
|
}
|
|
181
|
-
const z = 100, N = () => typeof window < "u" && typeof document < "u", H = () => Array.from(document.querySelectorAll(`.${
|
|
182
|
+
const z = 100, N = () => typeof window < "u" && typeof document < "u", H = () => Array.from(document.querySelectorAll(`.${m}`)), J = (t, e = D) => {
|
|
182
183
|
const n = L(t, e), s = new MutationObserver((r) => {
|
|
183
184
|
r.some((a) => a.addedNodes.length === 0 && a.removedNodes.length === 0 ? !1 : [
|
|
184
185
|
...Array.from(a.addedNodes),
|
|
185
186
|
...Array.from(a.removedNodes)
|
|
186
|
-
].some((
|
|
187
|
-
if (
|
|
187
|
+
].some((i) => {
|
|
188
|
+
if (i.nodeType !== Node.ELEMENT_NODE)
|
|
188
189
|
return !1;
|
|
189
|
-
const S =
|
|
190
|
-
return S.classList?.contains(
|
|
190
|
+
const S = i;
|
|
191
|
+
return S.classList?.contains(m) ? !0 : S.querySelector?.(`.${m}`) !== null;
|
|
191
192
|
})) && n();
|
|
192
193
|
}), o = document.body || document.documentElement;
|
|
193
194
|
return o ? s.observe(o, {
|
|
@@ -222,7 +223,7 @@ export {
|
|
|
222
223
|
B as extractContentletIdentifier,
|
|
223
224
|
b as extractUTMParameters,
|
|
224
225
|
H as findContentlets,
|
|
225
|
-
|
|
226
|
+
g as generateSecureId,
|
|
226
227
|
x as getAnalyticsContext,
|
|
227
228
|
A as getDeviceDataForContext,
|
|
228
229
|
W as getEnhancedTrackingPlugins,
|