@dotcms/analytics 1.2.0 → 1.2.1-next.2
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/README.md +314 -9
- package/lib/core/dot-analytics.content.js +84 -0
- package/lib/core/plugin/click/dot-analytics.click-tracker.d.ts +108 -0
- package/lib/core/plugin/click/dot-analytics.click-tracker.js +144 -0
- package/lib/core/plugin/click/dot-analytics.click.plugin.d.ts +36 -0
- package/lib/core/plugin/click/dot-analytics.click.plugin.js +27 -0
- package/lib/core/plugin/click/dot-analytics.click.utils.d.ts +12 -0
- package/lib/core/plugin/click/dot-analytics.click.utils.js +55 -0
- package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.d.ts +14 -10
- package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.js +26 -38
- package/lib/core/{shared/dot-content-analytics.activity-tracker.d.ts → plugin/identity/dot-analytics.identity.activity-tracker.d.ts} +2 -17
- package/lib/core/{shared/dot-content-analytics.activity-tracker.js → plugin/identity/dot-analytics.identity.activity-tracker.js} +17 -38
- package/lib/core/plugin/identity/dot-analytics.identity.plugin.d.ts +2 -20
- package/lib/core/plugin/identity/dot-analytics.identity.plugin.js +7 -7
- package/lib/core/plugin/identity/dot-analytics.identity.utils.d.ts +0 -16
- package/lib/core/plugin/impression/dot-analytics.impression-tracker.d.ts +62 -0
- package/lib/core/plugin/impression/dot-analytics.impression-tracker.js +202 -0
- package/lib/core/plugin/impression/dot-analytics.impression.plugin.d.ts +40 -0
- package/lib/core/plugin/impression/dot-analytics.impression.plugin.js +27 -0
- package/lib/core/plugin/impression/dot-analytics.impression.utils.d.ts +26 -0
- package/lib/core/plugin/impression/dot-analytics.impression.utils.js +27 -0
- package/lib/core/plugin/impression/index.d.ts +2 -0
- package/lib/core/plugin/main/dot-analytics.plugin.d.ts +46 -0
- package/lib/core/plugin/main/dot-analytics.plugin.js +129 -0
- package/lib/core/shared/constants/{dot-content-analytics.constants.d.ts → dot-analytics.constants.d.ts} +62 -0
- package/lib/core/shared/constants/dot-analytics.constants.js +53 -0
- package/lib/core/shared/constants/index.d.ts +1 -1
- package/lib/core/shared/dot-analytics.logger.d.ts +85 -0
- package/lib/core/shared/dot-analytics.logger.js +90 -0
- package/lib/core/shared/http/dot-analytics.http.d.ts +9 -0
- package/lib/core/shared/http/dot-analytics.http.js +34 -0
- package/lib/core/shared/models/data.model.d.ts +39 -1
- package/lib/core/shared/models/event.model.d.ts +108 -3
- package/lib/core/shared/models/library.model.d.ts +89 -28
- package/lib/core/shared/models/request.model.d.ts +17 -9
- package/lib/core/shared/queue/dot-analytics.queue.utils.js +47 -40
- package/lib/core/shared/{dot-content-analytics.utils.d.ts → utils/dot-analytics.utils.d.ts} +91 -3
- package/lib/core/shared/utils/dot-analytics.utils.js +200 -0
- package/lib/react/hook/useContentAnalytics.js +17 -11
- package/lib/react/hook/useRouterTracker.js +12 -12
- package/lib/react/internal/utils.js +1 -1
- package/package.json +7 -6
- package/uve/src/internal/events.js +30 -31
- package/uve/src/lib/dom/dom.utils.js +46 -52
- package/lib/core/dot-content-analytics.js +0 -46
- package/lib/core/plugin/dot-analytics.plugin.d.ts +0 -33
- package/lib/core/plugin/dot-analytics.plugin.js +0 -42
- package/lib/core/shared/constants/dot-content-analytics.constants.js +0 -34
- package/lib/core/shared/dot-content-analytics.http.d.ts +0 -17
- package/lib/core/shared/dot-content-analytics.http.js +0 -41
- package/lib/core/shared/dot-content-analytics.utils.js +0 -147
- /package/lib/core/{dot-content-analytics.d.ts → dot-analytics.content.d.ts} +0 -0
|
@@ -1,80 +1,74 @@
|
|
|
1
1
|
import "../../internal/constants.js";
|
|
2
|
-
function
|
|
3
|
-
return t.map((
|
|
4
|
-
const
|
|
5
|
-
|
|
2
|
+
function c(t) {
|
|
3
|
+
return t.map((n) => {
|
|
4
|
+
const e = n.getBoundingClientRect(), o = Array.from(
|
|
5
|
+
n.querySelectorAll('[data-dot-object="contentlet"]')
|
|
6
6
|
);
|
|
7
7
|
return {
|
|
8
|
-
x:
|
|
9
|
-
y:
|
|
10
|
-
width:
|
|
11
|
-
height:
|
|
8
|
+
x: e.x,
|
|
9
|
+
y: e.y,
|
|
10
|
+
width: e.width,
|
|
11
|
+
height: e.height,
|
|
12
12
|
payload: JSON.stringify({
|
|
13
|
-
container:
|
|
13
|
+
container: a(n)
|
|
14
14
|
}),
|
|
15
|
-
contentlets:
|
|
15
|
+
contentlets: d(e, o)
|
|
16
16
|
};
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
const n = o.getBoundingClientRect();
|
|
19
|
+
function d(t, n) {
|
|
20
|
+
return n.map((e) => {
|
|
21
|
+
const o = e.getBoundingClientRect();
|
|
23
22
|
return {
|
|
24
23
|
x: 0,
|
|
25
|
-
y:
|
|
26
|
-
width:
|
|
27
|
-
height:
|
|
24
|
+
y: o.y - t.y,
|
|
25
|
+
width: o.width,
|
|
26
|
+
height: o.height,
|
|
28
27
|
payload: JSON.stringify({
|
|
29
|
-
container:
|
|
28
|
+
container: e.dataset?.dotContainer ? JSON.parse(e.dataset?.dotContainer) : r(e),
|
|
30
29
|
contentlet: {
|
|
31
|
-
identifier:
|
|
32
|
-
title:
|
|
33
|
-
inode:
|
|
34
|
-
contentType:
|
|
30
|
+
identifier: e.dataset?.dotIdentifier,
|
|
31
|
+
title: e.dataset?.dotTitle,
|
|
32
|
+
inode: e.dataset?.dotInode,
|
|
33
|
+
contentType: e.dataset?.dotType
|
|
35
34
|
}
|
|
36
35
|
})
|
|
37
36
|
};
|
|
38
37
|
});
|
|
39
38
|
}
|
|
40
|
-
function
|
|
41
|
-
var a, o, n, d;
|
|
39
|
+
function a(t) {
|
|
42
40
|
return {
|
|
43
|
-
acceptTypes:
|
|
44
|
-
identifier:
|
|
45
|
-
maxContentlets:
|
|
46
|
-
uuid:
|
|
41
|
+
acceptTypes: t.dataset?.dotAcceptTypes || "",
|
|
42
|
+
identifier: t.dataset?.dotIdentifier || "",
|
|
43
|
+
maxContentlets: t.dataset?.maxContentlets || "",
|
|
44
|
+
uuid: t.dataset?.dotUuid || ""
|
|
47
45
|
};
|
|
48
46
|
}
|
|
49
|
-
function
|
|
50
|
-
const
|
|
51
|
-
return
|
|
47
|
+
function r(t) {
|
|
48
|
+
const n = t.closest('[data-dot-object="container"]');
|
|
49
|
+
return n ? a(n) : (console.warn("No container found for the contentlet"), null);
|
|
52
50
|
}
|
|
53
|
-
function
|
|
54
|
-
var o, n, d;
|
|
51
|
+
function i(t) {
|
|
55
52
|
if (!t) return null;
|
|
56
|
-
const
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
const n = t.querySelector('[data-dot-object="empty-content"]');
|
|
54
|
+
return t?.dataset?.dotObject === "contentlet" || // The container inside Headless components have a span with the data-dot-object="container" attribute
|
|
55
|
+
t?.dataset?.dotObject === "container" && n || // The container inside Traditional have no content inside
|
|
56
|
+
t?.dataset?.dotObject === "container" && t.children.length === 0 ? t : i(t?.parentElement);
|
|
60
57
|
}
|
|
61
|
-
function
|
|
62
|
-
const
|
|
58
|
+
function u(t) {
|
|
59
|
+
const n = t.querySelectorAll(
|
|
63
60
|
'[data-dot-object="vtl-file"]'
|
|
64
61
|
);
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
name: (d = o.dataset) == null ? void 0 : d.dotUrl
|
|
70
|
-
};
|
|
71
|
-
}) : null;
|
|
62
|
+
return n.length ? Array.from(n).map((e) => ({
|
|
63
|
+
inode: e.dataset?.dotInode,
|
|
64
|
+
name: e.dataset?.dotUrl
|
|
65
|
+
})) : null;
|
|
72
66
|
}
|
|
73
67
|
export {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
i as findDotCMSElement,
|
|
69
|
+
u as findDotCMSVTLData,
|
|
70
|
+
r as getClosestDotCMSContainerData,
|
|
71
|
+
a as getDotCMSContainerData,
|
|
72
|
+
d as getDotCMSContentletsBound,
|
|
73
|
+
c as getDotCMSPageBounds
|
|
80
74
|
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Analytics as a } from "analytics";
|
|
2
|
-
import { ANALYTICS_WINDOWS_ACTIVE_KEY as r, ANALYTICS_WINDOWS_CLEANUP_KEY as s } from "../../uve/src/internal/constants.js";
|
|
3
|
-
import { dotAnalytics as l } from "./plugin/dot-analytics.plugin.js";
|
|
4
|
-
import { dotAnalyticsEnricherPlugin as c } from "./plugin/enricher/dot-analytics.enricher.plugin.js";
|
|
5
|
-
import { dotAnalyticsIdentityPlugin as p } from "./plugin/identity/dot-analytics.identity.plugin.js";
|
|
6
|
-
import { validateAnalyticsConfig as m } from "./shared/dot-content-analytics.utils.js";
|
|
7
|
-
import { cleanupActivityTracking as u } from "./shared/dot-content-analytics.activity-tracker.js";
|
|
8
|
-
const I = (n) => {
|
|
9
|
-
const o = m(n);
|
|
10
|
-
if (o)
|
|
11
|
-
return console.error(`DotCMS Analytics: Missing ${o.join(" and ")} in configuration`), typeof window < "u" && (window[r] = !1), null;
|
|
12
|
-
const i = a({
|
|
13
|
-
app: "dotAnalytics",
|
|
14
|
-
debug: n.debug,
|
|
15
|
-
plugins: [
|
|
16
|
-
p(n),
|
|
17
|
-
// Inject identity context (user_id, session_id, local_tz)
|
|
18
|
-
c(),
|
|
19
|
-
// Enrich and clean payload with page, device, utm data and custom data
|
|
20
|
-
l(n)
|
|
21
|
-
// Send events to server
|
|
22
|
-
]
|
|
23
|
-
}), e = () => u();
|
|
24
|
-
return typeof window < "u" && (window.addEventListener("beforeunload", e), window[s] = e, window[r] = !0, window.dispatchEvent(new CustomEvent("dotcms:analytics:ready"))), {
|
|
25
|
-
/**
|
|
26
|
-
* Track a page view.
|
|
27
|
-
* Session activity is automatically updated by the identity plugin.
|
|
28
|
-
* @param payload - Optional custom data to include with the page view (any valid JSON object)
|
|
29
|
-
*/
|
|
30
|
-
pageView: (t = {}) => {
|
|
31
|
-
i == null || i.page(t);
|
|
32
|
-
},
|
|
33
|
-
/**
|
|
34
|
-
* Track a custom event.
|
|
35
|
-
* Session activity is automatically updated by the identity plugin.
|
|
36
|
-
* @param eventName - The name of the event to track
|
|
37
|
-
* @param payload - Custom data to include with the event (any valid JSON object)
|
|
38
|
-
*/
|
|
39
|
-
track: (t, d = {}) => {
|
|
40
|
-
i == null || i.track(t, d);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
export {
|
|
45
|
-
I as initializeContentAnalytics
|
|
46
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { DotCMSAnalyticsConfig, DotCMSAnalyticsParams } from '../shared/models';
|
|
2
|
-
/**
|
|
3
|
-
* Analytics plugin for tracking page views and custom events in DotCMS applications.
|
|
4
|
-
* This plugin handles sending analytics data to the DotCMS server, managing initialization,
|
|
5
|
-
* and processing both automatic and manual tracking events.
|
|
6
|
-
* Supports optional queue management for batching events before sending.
|
|
7
|
-
*
|
|
8
|
-
* @param {DotCMSAnalyticsConfig} config - Configuration object containing API key, server URL,
|
|
9
|
-
* debug mode, auto page view settings, and queue config
|
|
10
|
-
* @returns {Object} Plugin object with methods for initialization and event tracking
|
|
11
|
-
*/
|
|
12
|
-
export declare const dotAnalytics: (config: DotCMSAnalyticsConfig) => {
|
|
13
|
-
name: string;
|
|
14
|
-
config: DotCMSAnalyticsConfig;
|
|
15
|
-
/**
|
|
16
|
-
* Initialize the plugin with optional queue management
|
|
17
|
-
*/
|
|
18
|
-
initialize: () => Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Track a page view event
|
|
21
|
-
* The enricher plugin has already built the complete request body
|
|
22
|
-
*/
|
|
23
|
-
page: (params: DotCMSAnalyticsParams) => void;
|
|
24
|
-
/**
|
|
25
|
-
* Track a custom event
|
|
26
|
-
* The enricher plugin has already built the complete request body
|
|
27
|
-
*/
|
|
28
|
-
track: (params: DotCMSAnalyticsParams) => void;
|
|
29
|
-
/**
|
|
30
|
-
* Check if the plugin is loaded
|
|
31
|
-
*/
|
|
32
|
-
loaded: () => boolean;
|
|
33
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { sendAnalyticsEvent as u } from "../shared/dot-content-analytics.http.js";
|
|
2
|
-
import { createAnalyticsQueue as d } from "../shared/queue/dot-analytics.queue.utils.js";
|
|
3
|
-
const v = (t) => {
|
|
4
|
-
let n = !1;
|
|
5
|
-
const i = t.queue !== !1;
|
|
6
|
-
let e = null;
|
|
7
|
-
const o = (r) => {
|
|
8
|
-
const { config: c, payload: l } = r;
|
|
9
|
-
if (!n)
|
|
10
|
-
throw new Error("DotCMS Analytics: Plugin not initialized");
|
|
11
|
-
const a = l.events[0], s = l.context;
|
|
12
|
-
i && e ? e.enqueue(a, s) : u({
|
|
13
|
-
context: s,
|
|
14
|
-
events: [a]
|
|
15
|
-
}, c);
|
|
16
|
-
};
|
|
17
|
-
return {
|
|
18
|
-
name: "dot-analytics",
|
|
19
|
-
config: t,
|
|
20
|
-
/**
|
|
21
|
-
* Initialize the plugin with optional queue management
|
|
22
|
-
*/
|
|
23
|
-
initialize: () => (n = !0, i && (e = d(t), e.initialize()), Promise.resolve()),
|
|
24
|
-
/**
|
|
25
|
-
* Track a page view event
|
|
26
|
-
* The enricher plugin has already built the complete request body
|
|
27
|
-
*/
|
|
28
|
-
page: o,
|
|
29
|
-
/**
|
|
30
|
-
* Track a custom event
|
|
31
|
-
* The enricher plugin has already built the complete request body
|
|
32
|
-
*/
|
|
33
|
-
track: o,
|
|
34
|
-
/**
|
|
35
|
-
* Check if the plugin is loaded
|
|
36
|
-
*/
|
|
37
|
-
loaded: () => n
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
export {
|
|
41
|
-
v as dotAnalytics
|
|
42
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const E = "/api/v1/analytics/content/event", e = {
|
|
2
|
-
PAGEVIEW: "pageview"
|
|
3
|
-
}, n = [
|
|
4
|
-
"utm_source",
|
|
5
|
-
"utm_medium",
|
|
6
|
-
"utm_campaign",
|
|
7
|
-
"utm_term",
|
|
8
|
-
"utm_content"
|
|
9
|
-
], c = 30, s = "dot_analytics_session_id", T = "dot_analytics_user_id", t = 15, _ = 5e3, o = ["click"], S = {
|
|
10
|
-
eventBatchSize: t,
|
|
11
|
-
// Max events per batch - auto-sends when reached
|
|
12
|
-
flushInterval: _
|
|
13
|
-
// Time between flushes - sends whatever is queued
|
|
14
|
-
}, I = [
|
|
15
|
-
"title",
|
|
16
|
-
"url",
|
|
17
|
-
"path",
|
|
18
|
-
"hash",
|
|
19
|
-
"search",
|
|
20
|
-
"width",
|
|
21
|
-
"height",
|
|
22
|
-
"referrer"
|
|
23
|
-
];
|
|
24
|
-
export {
|
|
25
|
-
o as ACTIVITY_EVENTS,
|
|
26
|
-
E as ANALYTICS_ENDPOINT,
|
|
27
|
-
I as ANALYTICS_JS_DEFAULT_PROPERTIES,
|
|
28
|
-
S as DEFAULT_QUEUE_CONFIG,
|
|
29
|
-
c as DEFAULT_SESSION_TIMEOUT_MINUTES,
|
|
30
|
-
e as DotCMSPredefinedEventType,
|
|
31
|
-
n as EXPECTED_UTM_KEYS,
|
|
32
|
-
s as SESSION_STORAGE_KEY,
|
|
33
|
-
T as USER_ID_KEY
|
|
34
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { DotCMSAnalyticsConfig, DotCMSEvent, DotCMSRequestBody } from './models';
|
|
2
|
-
/**
|
|
3
|
-
* Available transport methods for sending analytics events
|
|
4
|
-
*/
|
|
5
|
-
export declare const TRANSPORT_TYPES: {
|
|
6
|
-
readonly FETCH: "fetch";
|
|
7
|
-
readonly BEACON: "beacon";
|
|
8
|
-
};
|
|
9
|
-
export type TransportType = (typeof TRANSPORT_TYPES)[keyof typeof TRANSPORT_TYPES];
|
|
10
|
-
/**
|
|
11
|
-
* Send analytics events to the server
|
|
12
|
-
* @param payload - The event payload data
|
|
13
|
-
* @param config - The analytics configuration
|
|
14
|
-
* @param transportType - Transport method: 'fetch' (default) or 'beacon' (for page unload)
|
|
15
|
-
* @returns A promise that resolves when the request is complete (fetch only)
|
|
16
|
-
*/
|
|
17
|
-
export declare const sendAnalyticsEvent: (payload: DotCMSRequestBody<DotCMSEvent>, config: DotCMSAnalyticsConfig, transportType?: TransportType) => Promise<void>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ANALYTICS_ENDPOINT as l } from "./constants/dot-content-analytics.constants.js";
|
|
2
|
-
const d = async (s, n, o = "fetch") => {
|
|
3
|
-
const a = `${n.server}${l}`, c = JSON.stringify(s);
|
|
4
|
-
if (n.debug && console.warn(
|
|
5
|
-
`DotCMS Analytics: Sending ${s.events.length} event(s) via ${o}`,
|
|
6
|
-
o === "fetch" ? { payload: s } : void 0
|
|
7
|
-
), o === "beacon") {
|
|
8
|
-
if (navigator.sendBeacon) {
|
|
9
|
-
const e = new Blob([c], { type: "application/json" });
|
|
10
|
-
!navigator.sendBeacon(a, e) && n.debug && console.warn("DotCMS Analytics: sendBeacon failed (queue might be full)");
|
|
11
|
-
} else
|
|
12
|
-
return n.debug && console.warn("DotCMS Analytics: sendBeacon not available, using fetch fallback"), d(s, n, "fetch");
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
try {
|
|
16
|
-
const e = await fetch(a, {
|
|
17
|
-
method: "POST",
|
|
18
|
-
headers: { "Content-Type": "application/json" },
|
|
19
|
-
body: c
|
|
20
|
-
});
|
|
21
|
-
if (!e.ok) {
|
|
22
|
-
const i = e.statusText || "Unknown Error", r = `HTTP ${e.status}: ${i}`;
|
|
23
|
-
try {
|
|
24
|
-
const t = await e.json();
|
|
25
|
-
t.message ? console.warn(`DotCMS Analytics: ${t.message} (${r})`) : console.warn(
|
|
26
|
-
`DotCMS Analytics: ${r} - No error message in response`
|
|
27
|
-
);
|
|
28
|
-
} catch (t) {
|
|
29
|
-
console.warn(
|
|
30
|
-
`DotCMS Analytics: ${r} - Failed to parse error response:`,
|
|
31
|
-
t
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
} catch (e) {
|
|
36
|
-
console.error("DotCMS Analytics: Error sending event:", e);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
export {
|
|
40
|
-
d as sendAnalyticsEvent
|
|
41
|
-
};
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { ANALYTICS_JS_DEFAULT_PROPERTIES as f, SESSION_STORAGE_KEY as h, DEFAULT_SESSION_TIMEOUT_MINUTES as w, USER_ID_KEY as l, EXPECTED_UTM_KEYS as _ } from "./constants/dot-content-analytics.constants.js";
|
|
2
|
-
import "../../../uve/src/internal/constants.js";
|
|
3
|
-
function U(t) {
|
|
4
|
-
var n, s;
|
|
5
|
-
const e = [];
|
|
6
|
-
return (n = t.siteAuth) != null && n.trim() || e.push('"siteAuth"'), (s = t.server) != null && s.trim() || e.push('"server"'), e.length > 0 ? e : null;
|
|
7
|
-
}
|
|
8
|
-
let u = null, g = null;
|
|
9
|
-
const d = (t) => {
|
|
10
|
-
const e = Date.now(), n = Math.random().toString(36).substr(2, 9), s = Math.random().toString(36).substr(2, 9);
|
|
11
|
-
return `${t}_${e}_${n}${s}`;
|
|
12
|
-
}, m = {
|
|
13
|
-
getItem: (t) => {
|
|
14
|
-
try {
|
|
15
|
-
return localStorage.getItem(t);
|
|
16
|
-
} catch {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
setItem: (t, e) => {
|
|
21
|
-
try {
|
|
22
|
-
localStorage.setItem(t, e);
|
|
23
|
-
} catch {
|
|
24
|
-
console.warn(`DotCMS Analytics: Could not save ${t} to localStorage`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}, p = () => {
|
|
28
|
-
let t = m.getItem(l);
|
|
29
|
-
return t || (t = d("user"), m.setItem(l, t)), t;
|
|
30
|
-
}, D = (t) => {
|
|
31
|
-
const e = new Date(t), n = /* @__PURE__ */ new Date(), s = new Date(
|
|
32
|
-
e.getUTCFullYear(),
|
|
33
|
-
e.getUTCMonth(),
|
|
34
|
-
e.getUTCDate()
|
|
35
|
-
), o = new Date(n.getUTCFullYear(), n.getUTCMonth(), n.getUTCDate());
|
|
36
|
-
return s.getTime() !== o.getTime();
|
|
37
|
-
}, T = () => {
|
|
38
|
-
const t = Date.now();
|
|
39
|
-
if (typeof window > "u")
|
|
40
|
-
return d("session_fallback");
|
|
41
|
-
try {
|
|
42
|
-
const e = sessionStorage.getItem(h);
|
|
43
|
-
if (e) {
|
|
44
|
-
const { sessionId: o, startTime: r, lastActivity: a } = JSON.parse(e), c = !D(r), i = t - a < w * 60 * 1e3;
|
|
45
|
-
if (c && i)
|
|
46
|
-
return sessionStorage.setItem(
|
|
47
|
-
h,
|
|
48
|
-
JSON.stringify({
|
|
49
|
-
sessionId: o,
|
|
50
|
-
startTime: r,
|
|
51
|
-
lastActivity: t
|
|
52
|
-
})
|
|
53
|
-
), o;
|
|
54
|
-
}
|
|
55
|
-
const n = d("session"), s = {
|
|
56
|
-
sessionId: n,
|
|
57
|
-
startTime: t,
|
|
58
|
-
lastActivity: t
|
|
59
|
-
};
|
|
60
|
-
return sessionStorage.setItem(h, JSON.stringify(s)), n;
|
|
61
|
-
} catch {
|
|
62
|
-
return d("session_fallback");
|
|
63
|
-
}
|
|
64
|
-
}, $ = (t) => {
|
|
65
|
-
const e = T(), n = p(), s = I();
|
|
66
|
-
return t.debug && console.warn("DotCMS Analytics Identity Context:", {
|
|
67
|
-
sessionId: e,
|
|
68
|
-
userId: n
|
|
69
|
-
}), {
|
|
70
|
-
site_auth: t.siteAuth,
|
|
71
|
-
session_id: e,
|
|
72
|
-
user_id: n,
|
|
73
|
-
device: s
|
|
74
|
-
};
|
|
75
|
-
}, S = () => u || (u = {
|
|
76
|
-
user_language: navigator.language,
|
|
77
|
-
doc_encoding: document.characterSet || document.charset,
|
|
78
|
-
screen_resolution: typeof screen < "u" && screen.width && screen.height ? `${screen.width}x${screen.height}` : ""
|
|
79
|
-
}, u), I = () => {
|
|
80
|
-
const t = S(), e = window.innerWidth || document.documentElement.clientWidth || 0, n = window.innerHeight || document.documentElement.clientHeight || 0;
|
|
81
|
-
return {
|
|
82
|
-
screen_resolution: t.screen_resolution ?? "",
|
|
83
|
-
language: t.user_language ?? "",
|
|
84
|
-
viewport_width: String(e),
|
|
85
|
-
viewport_height: String(n)
|
|
86
|
-
};
|
|
87
|
-
}, y = (t) => {
|
|
88
|
-
const e = t.search;
|
|
89
|
-
if (g && g.search === e)
|
|
90
|
-
return g.params;
|
|
91
|
-
const n = new URLSearchParams(e), s = {};
|
|
92
|
-
return _.forEach((o) => {
|
|
93
|
-
const r = n.get(o);
|
|
94
|
-
if (r) {
|
|
95
|
-
const a = o.replace("utm_", "");
|
|
96
|
-
s[a] = r;
|
|
97
|
-
}
|
|
98
|
-
}), g = { search: e, params: s }, s;
|
|
99
|
-
}, E = () => {
|
|
100
|
-
try {
|
|
101
|
-
const t = (/* @__PURE__ */ new Date()).getTimezoneOffset(), e = t > 0 ? "-" : "+", n = Math.abs(t), s = Math.floor(n / 60), o = n % 60;
|
|
102
|
-
return `${e}${s.toString().padStart(2, "0")}:${o.toString().padStart(2, "0")}`;
|
|
103
|
-
} catch {
|
|
104
|
-
return "+00:00";
|
|
105
|
-
}
|
|
106
|
-
}, C = () => {
|
|
107
|
-
try {
|
|
108
|
-
const t = /* @__PURE__ */ new Date(), e = E(), n = t.getFullYear(), s = (t.getMonth() + 1).toString().padStart(2, "0"), o = t.getDate().toString().padStart(2, "0"), r = t.getHours().toString().padStart(2, "0"), a = t.getMinutes().toString().padStart(2, "0"), c = t.getSeconds().toString().padStart(2, "0");
|
|
109
|
-
return `${n}-${s}-${o}T${r}:${a}:${c}${e}`;
|
|
110
|
-
} catch {
|
|
111
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
112
|
-
}
|
|
113
|
-
}, A = (t, e = typeof window < "u" ? window.location : {}) => {
|
|
114
|
-
const n = C(), s = S(), { properties: o } = t, r = {};
|
|
115
|
-
Object.keys(o).forEach((i) => {
|
|
116
|
-
f.includes(i) || (r[i] = o[i]);
|
|
117
|
-
});
|
|
118
|
-
const a = {
|
|
119
|
-
url: e.href,
|
|
120
|
-
doc_encoding: s.doc_encoding,
|
|
121
|
-
doc_hash: e.hash,
|
|
122
|
-
doc_protocol: e.protocol,
|
|
123
|
-
doc_search: e.search,
|
|
124
|
-
doc_host: e.hostname,
|
|
125
|
-
doc_path: e.pathname,
|
|
126
|
-
title: o.title ?? (document == null ? void 0 : document.title)
|
|
127
|
-
}, c = y(e);
|
|
128
|
-
return {
|
|
129
|
-
...t,
|
|
130
|
-
page: a,
|
|
131
|
-
...Object.keys(c).length > 0 && { utm: c },
|
|
132
|
-
// Only include custom if there are user-provided properties
|
|
133
|
-
...Object.keys(r).length > 0 && { custom: r },
|
|
134
|
-
local_time: n
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
export {
|
|
138
|
-
A as enrichPagePayloadOptimized,
|
|
139
|
-
y as extractUTMParameters,
|
|
140
|
-
d as generateSecureId,
|
|
141
|
-
$ as getAnalyticsContext,
|
|
142
|
-
I as getDeviceDataForContext,
|
|
143
|
-
C as getLocalTime,
|
|
144
|
-
T as getSessionId,
|
|
145
|
-
p as getUserId,
|
|
146
|
-
U as validateAnalyticsConfig
|
|
147
|
-
};
|
|
File without changes
|