@dotcms/analytics 1.2.0-next.1 → 1.2.0-next.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.
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import { DotCMSAnalyticsConfig, DotCMSEvent, DotCMSRequestBody } from './models';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
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
|
|
3
|
+
* Send analytics events to the server using fetch API
|
|
12
4
|
* @param payload - The event payload data
|
|
13
5
|
* @param config - The analytics configuration
|
|
14
|
-
* @param
|
|
15
|
-
* @returns A promise that resolves when the request is complete
|
|
6
|
+
* @param keepalive - Use keepalive mode for page unload scenarios (default: false)
|
|
7
|
+
* @returns A promise that resolves when the request is complete
|
|
16
8
|
*/
|
|
17
|
-
export declare const sendAnalyticsEvent: (payload: DotCMSRequestBody<DotCMSEvent>, config: DotCMSAnalyticsConfig,
|
|
9
|
+
export declare const sendAnalyticsEvent: (payload: DotCMSRequestBody<DotCMSEvent>, config: DotCMSAnalyticsConfig, keepalive?: boolean) => Promise<void>;
|
|
@@ -1,33 +1,28 @@
|
|
|
1
|
-
import { ANALYTICS_ENDPOINT as
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
`DotCMS Analytics: Sending ${
|
|
6
|
-
|
|
7
|
-
)
|
|
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
|
-
}
|
|
1
|
+
import { ANALYTICS_ENDPOINT as p } from "./constants/dot-content-analytics.constants.js";
|
|
2
|
+
const $ = async (n, r, a = !1) => {
|
|
3
|
+
const c = `${r.server}${p}`, i = JSON.stringify(n);
|
|
4
|
+
r.debug && console.warn(
|
|
5
|
+
`DotCMS Analytics: Sending ${n.events.length} event(s)${a ? " (keepalive)" : ""}`,
|
|
6
|
+
{ payload: n }
|
|
7
|
+
);
|
|
15
8
|
try {
|
|
16
|
-
const e =
|
|
9
|
+
const e = {
|
|
17
10
|
method: "POST",
|
|
18
11
|
headers: { "Content-Type": "application/json" },
|
|
19
|
-
body:
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
body: i
|
|
13
|
+
};
|
|
14
|
+
a && (e.keepalive = !0, e.credentials = "omit");
|
|
15
|
+
const s = await fetch(c, e);
|
|
16
|
+
if (!s.ok) {
|
|
17
|
+
const l = s.statusText || "Unknown Error", o = `HTTP ${s.status}: ${l}`;
|
|
23
18
|
try {
|
|
24
|
-
const t = await
|
|
25
|
-
t.message ? console.warn(`DotCMS Analytics: ${t.message} (${
|
|
26
|
-
`DotCMS Analytics: ${
|
|
19
|
+
const t = await s.json();
|
|
20
|
+
t.message ? console.warn(`DotCMS Analytics: ${t.message} (${o})`) : console.warn(
|
|
21
|
+
`DotCMS Analytics: ${o} - No error message in response`
|
|
27
22
|
);
|
|
28
23
|
} catch (t) {
|
|
29
24
|
console.warn(
|
|
30
|
-
`DotCMS Analytics: ${
|
|
25
|
+
`DotCMS Analytics: ${o} - Failed to parse error response:`,
|
|
31
26
|
t
|
|
32
27
|
);
|
|
33
28
|
}
|
|
@@ -37,5 +32,5 @@ const d = async (s, n, o = "fetch") => {
|
|
|
37
32
|
}
|
|
38
33
|
};
|
|
39
34
|
export {
|
|
40
|
-
|
|
35
|
+
$ as sendAnalyticsEvent
|
|
41
36
|
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import p from "@analytics/queue-utils";
|
|
2
|
-
import { DEFAULT_QUEUE_CONFIG as
|
|
2
|
+
import { DEFAULT_QUEUE_CONFIG as h } from "../constants/dot-content-analytics.constants.js";
|
|
3
3
|
import { sendAnalyticsEvent as y } from "../dot-content-analytics.http.js";
|
|
4
4
|
const z = (n) => {
|
|
5
|
-
let e = null, i = null,
|
|
6
|
-
const
|
|
7
|
-
...
|
|
5
|
+
let e = null, i = null, l = !1;
|
|
6
|
+
const o = {
|
|
7
|
+
...h,
|
|
8
8
|
...typeof n.queue == "object" ? n.queue : {}
|
|
9
|
-
},
|
|
9
|
+
}, c = (t) => {
|
|
10
10
|
if (!i) return;
|
|
11
11
|
n.debug && console.log(`DotCMS Analytics Queue: Sending batch of ${t.length} event(s)`, {
|
|
12
12
|
events: t,
|
|
13
|
-
|
|
14
|
-
}), y({ context: i, events: t }, n,
|
|
13
|
+
keepalive: l
|
|
14
|
+
}), y({ context: i, events: t }, n, l);
|
|
15
15
|
}, u = () => {
|
|
16
16
|
!e || e.size() === 0 || !i || (n.debug && console.warn(
|
|
17
17
|
`DotCMS Analytics: Flushing ${e.size()} events (page hidden/unload)`
|
|
18
|
-
),
|
|
18
|
+
), l = !0, e.flush(!0));
|
|
19
19
|
}, d = () => {
|
|
20
20
|
document.visibilityState === "hidden" && u();
|
|
21
21
|
};
|
|
@@ -26,11 +26,11 @@ const z = (n) => {
|
|
|
26
26
|
initialize: () => {
|
|
27
27
|
e = p(
|
|
28
28
|
(t) => {
|
|
29
|
-
|
|
29
|
+
c(t);
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
|
-
max:
|
|
33
|
-
interval:
|
|
32
|
+
max: o.eventBatchSize,
|
|
33
|
+
interval: o.flushInterval,
|
|
34
34
|
throttle: !1
|
|
35
35
|
// Always false - enables both batch size and interval triggers
|
|
36
36
|
}
|
|
@@ -45,9 +45,9 @@ const z = (n) => {
|
|
|
45
45
|
enqueue: (t, s) => {
|
|
46
46
|
if (i = s, !!e) {
|
|
47
47
|
if (n.debug) {
|
|
48
|
-
const a = e.size() + 1, r =
|
|
48
|
+
const a = e.size() + 1, r = o.eventBatchSize, f = a >= r;
|
|
49
49
|
console.log(
|
|
50
|
-
`DotCMS Analytics Queue: Event added. Queue size: ${a}/${r}${
|
|
50
|
+
`DotCMS Analytics Queue: Event added. Queue size: ${a}/${r}${f ? " (full, sending...)" : ""}`,
|
|
51
51
|
{ eventType: t.event_type, event: t }
|
|
52
52
|
);
|
|
53
53
|
}
|
|
@@ -64,7 +64,7 @@ const z = (n) => {
|
|
|
64
64
|
* Flushes remaining events and cleans up listeners
|
|
65
65
|
*/
|
|
66
66
|
cleanup: () => {
|
|
67
|
-
u(), typeof window < "u" && typeof document < "u" && (document.removeEventListener("visibilitychange", d), window.removeEventListener("pagehide", u)), e = null, i = null,
|
|
67
|
+
u(), typeof window < "u" && typeof document < "u" && (document.removeEventListener("visibilitychange", d), window.removeEventListener("pagehide", u)), e = null, i = null, l = !1;
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
};
|