@dotcms/analytics 0.0.1-beta.42 → 0.0.1-beta.43
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/lib/dotAnalytics/dot-content-analytics.d.ts +5 -5
- package/lib/dotAnalytics/dot-content-analytics.js +28 -9
- package/lib/dotAnalytics/plugin/dot-analytics.plugin.d.ts +9 -7
- package/lib/dotAnalytics/plugin/dot-analytics.plugin.js +30 -31
- package/lib/dotAnalytics/plugin/enricher/dot-analytics.enricher.plugin.d.ts +46 -0
- package/lib/dotAnalytics/plugin/enricher/dot-analytics.enricher.plugin.js +33 -0
- package/lib/dotAnalytics/plugin/identity/dot-analytics.identity.plugin.d.ts +80 -0
- package/lib/dotAnalytics/plugin/identity/dot-analytics.identity.plugin.js +40 -0
- package/lib/dotAnalytics/plugin/identity/dot-analytics.identity.utils.d.ts +24 -0
- package/lib/dotAnalytics/shared/dot-content-analytics.activity-tracker.d.ts +29 -0
- package/lib/dotAnalytics/shared/dot-content-analytics.activity-tracker.js +86 -0
- package/lib/dotAnalytics/shared/dot-content-analytics.constants.d.ts +16 -7
- package/lib/dotAnalytics/shared/dot-content-analytics.constants.js +8 -8
- package/lib/dotAnalytics/shared/dot-content-analytics.http.d.ts +2 -2
- package/lib/dotAnalytics/shared/dot-content-analytics.http.js +2 -8
- package/lib/dotAnalytics/shared/dot-content-analytics.model.d.ts +263 -89
- package/lib/dotAnalytics/shared/dot-content-analytics.utils.d.ts +91 -28
- package/lib/dotAnalytics/shared/dot-content-analytics.utils.js +125 -40
- package/lib/react/components/DotContentAnalyticsProvider.d.ts +4 -4
- package/lib/react/components/DotContentAnalyticsProvider.js +5 -2
- package/lib/react/contexts/DotContentAnalyticsContext.d.ts +3 -3
- package/lib/react/hook/useContentAnalytics.d.ts +36 -6
- package/lib/react/hook/useContentAnalytics.js +25 -25
- package/lib/react/hook/useRouterTracker.d.ts +3 -3
- package/lib/standalone.d.ts +2 -2
- package/package.json +4 -4
- package/lib/dotAnalytics/plugin/dot-analytics.enricher.plugin.d.ts +0 -31
- package/lib/dotAnalytics/plugin/dot-analytics.enricher.plugin.js +0 -28
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotCMSAnalytics, DotCMSAnalyticsConfig } from './shared/dot-content-analytics.model';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Creates an analytics instance.
|
|
4
|
+
* Creates an analytics instance for content analytics tracking.
|
|
5
5
|
*
|
|
6
|
-
* @param {
|
|
7
|
-
* @returns {
|
|
6
|
+
* @param {DotCMSAnalyticsConfig} config - The configuration object for the analytics instance.
|
|
7
|
+
* @returns {DotCMSAnalytics} - The analytics instance.
|
|
8
8
|
*/
|
|
9
|
-
export declare const initializeContentAnalytics: (config:
|
|
9
|
+
export declare const initializeContentAnalytics: (config: DotCMSAnalyticsConfig) => DotCMSAnalytics | null;
|
|
@@ -1,24 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Analytics as s } from "analytics";
|
|
2
|
+
import { dotAnalytics as l } from "./plugin/dot-analytics.plugin.js";
|
|
3
|
+
import { dotAnalyticsEnricherPlugin as a } from "./plugin/enricher/dot-analytics.enricher.plugin.js";
|
|
4
|
+
import { dotAnalyticsIdentityPlugin as u } from "./plugin/identity/dot-analytics.identity.plugin.js";
|
|
5
|
+
import { cleanupActivityTracking as c, updateSessionActivity as o } from "./shared/dot-content-analytics.activity-tracker.js";
|
|
6
|
+
const f = (n) => {
|
|
7
|
+
if (!n.siteKey)
|
|
8
|
+
return console.error('DotContentAnalytics: Missing "siteKey" in configuration'), null;
|
|
9
|
+
if (!n.server)
|
|
10
|
+
return console.error('DotContentAnalytics: Missing "server" in configuration'), null;
|
|
11
|
+
const t = s({
|
|
12
|
+
app: "dotAnalytics",
|
|
13
|
+
debug: n.debug,
|
|
14
|
+
plugins: [
|
|
15
|
+
u(n),
|
|
16
|
+
// Inject identity context (user_id, session_id, local_tz)
|
|
17
|
+
a(),
|
|
18
|
+
// Enrich with page, device, utm data
|
|
19
|
+
l(n)
|
|
20
|
+
// Send events to server
|
|
21
|
+
]
|
|
22
|
+
}), e = () => c();
|
|
23
|
+
return typeof window < "u" && (window.addEventListener("beforeunload", e), window.__dotAnalyticsCleanup = e), {
|
|
5
24
|
/**
|
|
6
25
|
* Track a page view.
|
|
7
26
|
* @param {Record<string, unknown>} payload - The payload to track.
|
|
8
27
|
*/
|
|
9
|
-
pageView: (
|
|
10
|
-
t == null || t.page(
|
|
28
|
+
pageView: (i = {}) => {
|
|
29
|
+
o(), t == null || t.page(i);
|
|
11
30
|
},
|
|
12
31
|
/**
|
|
13
32
|
* Track a custom event.
|
|
14
33
|
* @param {string} eventName - The name of the event to track.
|
|
15
34
|
* @param {Record<string, unknown>} payload - The payload to track.
|
|
16
35
|
*/
|
|
17
|
-
track: (
|
|
18
|
-
t == null || t.track(
|
|
36
|
+
track: (i, r = {}) => {
|
|
37
|
+
o(), t == null || t.track(i, r);
|
|
19
38
|
}
|
|
20
39
|
};
|
|
21
40
|
};
|
|
22
41
|
export {
|
|
23
|
-
|
|
42
|
+
f as initializeContentAnalytics
|
|
24
43
|
};
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotCMSAnalyticsConfig, DotCMSAnalyticsParams } from '../shared/dot-content-analytics.model';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Analytics plugin for tracking page views and custom events in DotCMS applications.
|
|
5
5
|
* This plugin handles sending analytics data to the DotCMS server, managing initialization,
|
|
6
6
|
* and processing both automatic and manual tracking events.
|
|
7
7
|
*
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {DotCMSAnalyticsConfig} config - Configuration object containing API key, server URL,
|
|
9
9
|
* debug mode and auto page view settings
|
|
10
10
|
* @returns {Object} Plugin object with methods for initialization and event tracking
|
|
11
11
|
*/
|
|
12
|
-
export declare const dotAnalytics: (config:
|
|
12
|
+
export declare const dotAnalytics: (config: DotCMSAnalyticsConfig) => {
|
|
13
13
|
name: string;
|
|
14
|
-
config:
|
|
14
|
+
config: DotCMSAnalyticsConfig;
|
|
15
15
|
/**
|
|
16
16
|
* Initialize the plugin
|
|
17
17
|
*/
|
|
18
|
-
initialize: (
|
|
18
|
+
initialize: () => Promise<void>;
|
|
19
19
|
/**
|
|
20
20
|
* Track a page view event
|
|
21
|
+
* Takes enriched data from properties and creates final structured event
|
|
21
22
|
*/
|
|
22
|
-
page: (params:
|
|
23
|
+
page: (params: DotCMSAnalyticsParams) => Promise<void>;
|
|
23
24
|
/**
|
|
24
25
|
* Track a custom event
|
|
26
|
+
* Takes enriched data and sends it to the analytics server
|
|
25
27
|
*/
|
|
26
|
-
track: (params:
|
|
28
|
+
track: (params: DotCMSAnalyticsParams) => Promise<void>;
|
|
27
29
|
/**
|
|
28
30
|
* Check if the plugin is loaded
|
|
29
31
|
*/
|
|
@@ -1,55 +1,54 @@
|
|
|
1
|
-
import { sendAnalyticsEventToServer as
|
|
2
|
-
const
|
|
3
|
-
let
|
|
1
|
+
import { sendAnalyticsEventToServer as c } from "../shared/dot-content-analytics.http.js";
|
|
2
|
+
const f = (l) => {
|
|
3
|
+
let t = !1;
|
|
4
4
|
return {
|
|
5
5
|
name: "dot-analytics",
|
|
6
|
-
config:
|
|
6
|
+
config: l,
|
|
7
7
|
/**
|
|
8
8
|
* Initialize the plugin
|
|
9
9
|
*/
|
|
10
|
-
initialize: (
|
|
11
|
-
const { config: i, payload: t } = o;
|
|
12
|
-
if (i.debug && console.warn("DotAnalytics: Initialized with config", i), n = !0, i.autoPageView) {
|
|
13
|
-
const e = {
|
|
14
|
-
...t.properties,
|
|
15
|
-
key: i.apiKey
|
|
16
|
-
};
|
|
17
|
-
return r(e, i);
|
|
18
|
-
}
|
|
19
|
-
return Promise.resolve();
|
|
20
|
-
},
|
|
10
|
+
initialize: () => (t = !0, Promise.resolve()),
|
|
21
11
|
/**
|
|
22
12
|
* Track a page view event
|
|
13
|
+
* Takes enriched data from properties and creates final structured event
|
|
23
14
|
*/
|
|
24
|
-
page: (
|
|
25
|
-
const { config:
|
|
26
|
-
if (!
|
|
15
|
+
page: (n) => {
|
|
16
|
+
const { config: e, payload: o } = n, { context: i, page: s, device: d, utm: r, local_time: g } = o;
|
|
17
|
+
if (!t)
|
|
27
18
|
throw new Error("DotAnalytics: Plugin not initialized");
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
const a = {
|
|
20
|
+
context: i,
|
|
21
|
+
events: [
|
|
22
|
+
{
|
|
23
|
+
event_type: "pageview",
|
|
24
|
+
local_time: g,
|
|
25
|
+
page: s,
|
|
26
|
+
device: d,
|
|
27
|
+
...r && { utm: r }
|
|
28
|
+
}
|
|
29
|
+
]
|
|
31
30
|
};
|
|
32
|
-
return
|
|
31
|
+
return e.debug && console.warn("Event to send:", a), c(a, e);
|
|
33
32
|
},
|
|
34
33
|
/**
|
|
35
34
|
* Track a custom event
|
|
35
|
+
* Takes enriched data and sends it to the analytics server
|
|
36
36
|
*/
|
|
37
|
-
track: (
|
|
38
|
-
const { config:
|
|
39
|
-
if (!
|
|
37
|
+
track: (n) => {
|
|
38
|
+
const { config: e, payload: o } = n;
|
|
39
|
+
if (!t)
|
|
40
40
|
throw new Error("DotAnalytics: Plugin not initialized");
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
key: i.apiKey
|
|
41
|
+
const i = {
|
|
42
|
+
context: o.context
|
|
44
43
|
};
|
|
45
|
-
return
|
|
44
|
+
return c(i, e);
|
|
46
45
|
},
|
|
47
46
|
/**
|
|
48
47
|
* Check if the plugin is loaded
|
|
49
48
|
*/
|
|
50
|
-
loaded: () =>
|
|
49
|
+
loaded: () => t
|
|
51
50
|
};
|
|
52
51
|
};
|
|
53
52
|
export {
|
|
54
|
-
|
|
53
|
+
f as dotAnalytics
|
|
55
54
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DotCMSAnalyticsPayload } from '../../shared/dot-content-analytics.model';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Plugin that enriches the analytics payload data based on the event type.
|
|
5
|
+
* Uses Analytics.js lifecycle events to inject context before processing.
|
|
6
|
+
* The identity plugin runs FIRST to inject context: { session_id, site_key, user_id }
|
|
7
|
+
* This enricher plugin runs SECOND to add page/device/utm data.
|
|
8
|
+
*
|
|
9
|
+
* OPTIMIZED: Uses existing payload.properties data to avoid duplication
|
|
10
|
+
*/
|
|
11
|
+
export declare const dotAnalyticsEnricherPlugin: () => {
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* PAGE VIEW ENRICHMENT - Runs after identity context injection
|
|
15
|
+
* Uses optimized enrichment that leverages analytics.js payload data
|
|
16
|
+
*/
|
|
17
|
+
'page:dot-analytics': ({ payload }: {
|
|
18
|
+
payload: DotCMSAnalyticsPayload;
|
|
19
|
+
}) => {
|
|
20
|
+
local_time: string;
|
|
21
|
+
utm?: import('../../shared/dot-content-analytics.model').DotCMSUtmData | undefined;
|
|
22
|
+
page: import('analytics').PageData;
|
|
23
|
+
device: import('../../shared/dot-content-analytics.model').DotCMSDeviceData;
|
|
24
|
+
type: string;
|
|
25
|
+
properties: Record<string, unknown>;
|
|
26
|
+
event: string;
|
|
27
|
+
options: Record<string, unknown>;
|
|
28
|
+
context: import('../../shared/dot-content-analytics.model').DotCMSAnalyticsContext;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* TRACK EVENT ENRICHMENT - Runs after identity context injection
|
|
32
|
+
* Creates structured track events with pre-injected context
|
|
33
|
+
*/
|
|
34
|
+
'track:dot-analytics': ({ payload }: {
|
|
35
|
+
payload: DotCMSAnalyticsPayload;
|
|
36
|
+
}) => {
|
|
37
|
+
events: {
|
|
38
|
+
event_type: string;
|
|
39
|
+
custom_event: string;
|
|
40
|
+
local_time: string;
|
|
41
|
+
properties: {
|
|
42
|
+
src: string;
|
|
43
|
+
};
|
|
44
|
+
}[];
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ANALYTICS_SOURCE_TYPE as r } from "../../shared/dot-content-analytics.constants.js";
|
|
2
|
+
import { getLocalTime as n, enrichPagePayloadOptimized as o } from "../../shared/dot-content-analytics.utils.js";
|
|
3
|
+
const s = () => ({
|
|
4
|
+
name: "enrich-dot-analytics",
|
|
5
|
+
/**
|
|
6
|
+
* PAGE VIEW ENRICHMENT - Runs after identity context injection
|
|
7
|
+
* Uses optimized enrichment that leverages analytics.js payload data
|
|
8
|
+
*/
|
|
9
|
+
"page:dot-analytics": ({ payload: e }) => o(e),
|
|
10
|
+
/**
|
|
11
|
+
* TRACK EVENT ENRICHMENT - Runs after identity context injection
|
|
12
|
+
* Creates structured track events with pre-injected context
|
|
13
|
+
*/
|
|
14
|
+
"track:dot-analytics": ({ payload: e }) => {
|
|
15
|
+
const t = n();
|
|
16
|
+
return {
|
|
17
|
+
events: [
|
|
18
|
+
{
|
|
19
|
+
event_type: "track",
|
|
20
|
+
custom_event: e.event,
|
|
21
|
+
local_time: t,
|
|
22
|
+
properties: {
|
|
23
|
+
...e.properties,
|
|
24
|
+
src: r
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
export {
|
|
32
|
+
s as dotAnalyticsEnricherPlugin
|
|
33
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { DotCMSAnalyticsConfig, DotCMSAnalyticsHookParams } from '../../shared/dot-content-analytics.model';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Identity Plugin for DotAnalytics
|
|
5
|
+
* Handles user ID generation, session management, and activity tracking.
|
|
6
|
+
* This plugin provides consistent identity context across all analytics events.
|
|
7
|
+
*
|
|
8
|
+
* Plugin execution order:
|
|
9
|
+
* 1. Identity Plugin (this) - Injects context
|
|
10
|
+
* 2. Enricher Plugin - Adds page/device/utm data
|
|
11
|
+
* 3. Main Plugin - Sends to server
|
|
12
|
+
*
|
|
13
|
+
* @param {DotCMSAnalyticsConfig} config - Configuration object containing server URL, site key, and debug settings
|
|
14
|
+
* @returns {Object} Plugin object with methods for initialization and event processing
|
|
15
|
+
*/
|
|
16
|
+
export declare const dotAnalyticsIdentityPlugin: (config: DotCMSAnalyticsConfig) => {
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* Initialize the identity plugin
|
|
20
|
+
* Sets up activity tracking for session management
|
|
21
|
+
*/
|
|
22
|
+
initialize: () => Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Inject identity context into page events
|
|
25
|
+
* This runs BEFORE the enricher plugin
|
|
26
|
+
*/
|
|
27
|
+
pageStart: ({ payload }: DotCMSAnalyticsHookParams) => {
|
|
28
|
+
context: import('../../shared/dot-content-analytics.model').DotCMSAnalyticsContext;
|
|
29
|
+
type: string;
|
|
30
|
+
properties: {
|
|
31
|
+
title: string;
|
|
32
|
+
url: string;
|
|
33
|
+
path: string;
|
|
34
|
+
hash: string;
|
|
35
|
+
search: string;
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
referrer?: string | undefined;
|
|
39
|
+
};
|
|
40
|
+
options: Record<string, unknown>;
|
|
41
|
+
userId: string | null;
|
|
42
|
+
anonymousId: string;
|
|
43
|
+
meta: {
|
|
44
|
+
rid: string;
|
|
45
|
+
ts: number;
|
|
46
|
+
hasCallback: boolean;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Inject identity context into track events
|
|
51
|
+
* This runs BEFORE the enricher plugin
|
|
52
|
+
*/
|
|
53
|
+
trackStart: ({ payload }: DotCMSAnalyticsHookParams) => {
|
|
54
|
+
context: import('../../shared/dot-content-analytics.model').DotCMSAnalyticsContext;
|
|
55
|
+
type: string;
|
|
56
|
+
properties: {
|
|
57
|
+
title: string;
|
|
58
|
+
url: string;
|
|
59
|
+
path: string;
|
|
60
|
+
hash: string;
|
|
61
|
+
search: string;
|
|
62
|
+
width: number;
|
|
63
|
+
height: number;
|
|
64
|
+
referrer?: string | undefined;
|
|
65
|
+
};
|
|
66
|
+
options: Record<string, unknown>;
|
|
67
|
+
userId: string | null;
|
|
68
|
+
anonymousId: string;
|
|
69
|
+
meta: {
|
|
70
|
+
rid: string;
|
|
71
|
+
ts: number;
|
|
72
|
+
hasCallback: boolean;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Clean up on plugin unload
|
|
77
|
+
* Sets up cleanup handlers for activity tracking
|
|
78
|
+
*/
|
|
79
|
+
loaded: () => boolean;
|
|
80
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getAnalyticsContext as i } from "../../shared/dot-content-analytics.utils.js";
|
|
2
|
+
import { cleanupActivityTracking as r, initializeActivityTracking as o } from "../../shared/dot-content-analytics.activity-tracker.js";
|
|
3
|
+
const c = (t) => ({
|
|
4
|
+
name: "dot-analytics-identity",
|
|
5
|
+
/**
|
|
6
|
+
* Initialize the identity plugin
|
|
7
|
+
* Sets up activity tracking for session management
|
|
8
|
+
*/
|
|
9
|
+
initialize: () => (o(t), Promise.resolve()),
|
|
10
|
+
/**
|
|
11
|
+
* Inject identity context into page events
|
|
12
|
+
* This runs BEFORE the enricher plugin
|
|
13
|
+
*/
|
|
14
|
+
pageStart: ({ payload: e }) => {
|
|
15
|
+
const n = i(t);
|
|
16
|
+
return {
|
|
17
|
+
...e,
|
|
18
|
+
context: n
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
/**
|
|
22
|
+
* Inject identity context into track events
|
|
23
|
+
* This runs BEFORE the enricher plugin
|
|
24
|
+
*/
|
|
25
|
+
trackStart: ({ payload: e }) => {
|
|
26
|
+
const n = i(t);
|
|
27
|
+
return {
|
|
28
|
+
...e,
|
|
29
|
+
context: n
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* Clean up on plugin unload
|
|
34
|
+
* Sets up cleanup handlers for activity tracking
|
|
35
|
+
*/
|
|
36
|
+
loaded: () => (typeof window < "u" && (window.addEventListener("beforeunload", r), window.addEventListener("pagehide", r)), !0)
|
|
37
|
+
});
|
|
38
|
+
export {
|
|
39
|
+
c as dotAnalyticsIdentityPlugin
|
|
40
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updates activity timestamp
|
|
3
|
+
*/
|
|
4
|
+
export declare const updateActivityTime: () => void;
|
|
5
|
+
/**
|
|
6
|
+
* Checks if user has been inactive
|
|
7
|
+
*/
|
|
8
|
+
export declare const isUserInactive: () => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a new day has started since session creation
|
|
11
|
+
*/
|
|
12
|
+
export declare const hasPassedMidnight: (sessionStartTime: number) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the last activity time
|
|
15
|
+
*/
|
|
16
|
+
export declare const getLastActivityTime: () => number;
|
|
17
|
+
/**
|
|
18
|
+
* Extracts UTM parameters from current location
|
|
19
|
+
*/
|
|
20
|
+
export declare const extractUTMParameters: () => Record<string, string>;
|
|
21
|
+
/**
|
|
22
|
+
* Compares UTM parameters to detect campaign changes
|
|
23
|
+
*/
|
|
24
|
+
export declare const hasUTMChanged: (currentUTM: Record<string, string>) => boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DotCMSAnalyticsConfig } from './dot-content-analytics.model';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Updates session activity with throttling
|
|
5
|
+
*/
|
|
6
|
+
export declare const updateSessionActivity: () => void;
|
|
7
|
+
/**
|
|
8
|
+
* Gets session information for debugging
|
|
9
|
+
*/
|
|
10
|
+
export declare const getSessionInfo: () => {
|
|
11
|
+
lastActivity: number;
|
|
12
|
+
isActive: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Initializes activity tracking
|
|
16
|
+
*/
|
|
17
|
+
export declare const initializeActivityTracking: (config: DotCMSAnalyticsConfig) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Cleans up activity tracking listeners
|
|
20
|
+
*/
|
|
21
|
+
export declare const cleanupActivityTracking: () => void;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if user has been inactive
|
|
24
|
+
*/
|
|
25
|
+
export declare const isUserInactive: () => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Gets last activity time
|
|
28
|
+
*/
|
|
29
|
+
export declare const getLastActivity: () => number;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { DEFAULT_SESSION_TIMEOUT_MINUTES as c, ACTIVITY_EVENTS as r } from "./dot-content-analytics.constants.js";
|
|
2
|
+
class o {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.activityListeners = [], this.lastActivityTime = Date.now(), this.inactivityTimer = null, this.isThrottled = !1, this.config = null, this.ACTIVITY_THROTTLE_MS = 1e3;
|
|
5
|
+
}
|
|
6
|
+
// Throttle activity events to max 1 per second
|
|
7
|
+
/**
|
|
8
|
+
* Updates activity timestamp (throttled for performance)
|
|
9
|
+
*/
|
|
10
|
+
updateActivityTime() {
|
|
11
|
+
this.lastActivityTime = Date.now(), this.inactivityTimer && clearTimeout(this.inactivityTimer), this.inactivityTimer = setTimeout(
|
|
12
|
+
() => {
|
|
13
|
+
var i;
|
|
14
|
+
(i = this.config) != null && i.debug && console.warn("DotCMS Analytics: User became inactive after timeout"), this.inactivityTimer = null;
|
|
15
|
+
},
|
|
16
|
+
c * 60 * 1e3
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Checks if user has been inactive
|
|
21
|
+
*/
|
|
22
|
+
isUserInactive() {
|
|
23
|
+
const i = c * 60 * 1e3;
|
|
24
|
+
return Date.now() - this.lastActivityTime > i;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Gets last activity time
|
|
28
|
+
*/
|
|
29
|
+
getLastActivity() {
|
|
30
|
+
return this.lastActivityTime;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Updates session activity with throttling
|
|
34
|
+
*/
|
|
35
|
+
updateSessionActivity() {
|
|
36
|
+
this.isThrottled || (this.isThrottled = !0, this.updateActivityTime(), setTimeout(() => {
|
|
37
|
+
this.isThrottled = !1;
|
|
38
|
+
}, this.ACTIVITY_THROTTLE_MS));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Initializes activity tracking with event listeners
|
|
42
|
+
*/
|
|
43
|
+
initialize(i) {
|
|
44
|
+
if (this.cleanup(), this.config = i, typeof window > "u")
|
|
45
|
+
return;
|
|
46
|
+
const s = () => this.updateSessionActivity();
|
|
47
|
+
r.forEach((a) => {
|
|
48
|
+
window.addEventListener(a, s, { passive: !0 }), this.activityListeners.push(
|
|
49
|
+
() => window.removeEventListener(a, s)
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
const n = () => {
|
|
53
|
+
document.visibilityState === "visible" && (this.updateSessionActivity(), i.debug && console.warn("DotCMS Analytics: User returned to tab, session reactivated"));
|
|
54
|
+
};
|
|
55
|
+
document.addEventListener("visibilitychange", n), this.activityListeners.push(
|
|
56
|
+
() => document.removeEventListener("visibilitychange", n)
|
|
57
|
+
), this.updateActivityTime(), i.debug && console.warn("DotCMS Analytics: Activity tracking initialized");
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Cleans up all activity tracking listeners
|
|
61
|
+
*/
|
|
62
|
+
cleanup() {
|
|
63
|
+
this.activityListeners.forEach((i) => i()), this.activityListeners = [], this.inactivityTimer && (clearTimeout(this.inactivityTimer), this.inactivityTimer = null), this.config = null;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets session information for debugging
|
|
67
|
+
*/
|
|
68
|
+
getSessionInfo() {
|
|
69
|
+
return {
|
|
70
|
+
lastActivity: this.getLastActivity(),
|
|
71
|
+
isActive: !this.isUserInactive()
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const t = new o(), h = () => {
|
|
76
|
+
t.updateSessionActivity();
|
|
77
|
+
}, l = (e) => {
|
|
78
|
+
t.initialize(e);
|
|
79
|
+
}, T = () => {
|
|
80
|
+
t.cleanup();
|
|
81
|
+
};
|
|
82
|
+
export {
|
|
83
|
+
T as cleanupActivityTracking,
|
|
84
|
+
l as initializeActivityTracking,
|
|
85
|
+
h as updateSessionActivity
|
|
86
|
+
};
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
export declare const ANALYTICS_WINDOWS_KEY = "dotAnalytics";
|
|
2
2
|
export declare const ANALYTICS_SOURCE_TYPE = "dotAnalytics";
|
|
3
3
|
export declare const ANALYTICS_ENDPOINT = "/api/v1/analytics/content/event";
|
|
4
|
-
export declare const ANALYTICS_PAGEVIEW_EVENT = "PAGE_REQUEST";
|
|
5
|
-
export declare const ANALYTICS_TRACK_EVENT = "TRACK_EVENT";
|
|
6
4
|
export declare const EXPECTED_UTM_KEYS: string[];
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
6
|
+
* Session configuration constants
|
|
9
7
|
*/
|
|
10
|
-
export declare
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export declare const DEFAULT_SESSION_TIMEOUT_MINUTES = 30;
|
|
9
|
+
export declare const SESSION_STORAGE_KEY = "dot_analytics_session_id";
|
|
10
|
+
export declare const SESSION_START_KEY = "dot_analytics_session_start";
|
|
11
|
+
export declare const SESSION_UTM_KEY = "dot_analytics_session_utm";
|
|
12
|
+
/**
|
|
13
|
+
* User ID configuration constants
|
|
14
|
+
*/
|
|
15
|
+
export declare const USER_ID_KEY = "dot_analytics_user_id";
|
|
16
|
+
/**
|
|
17
|
+
* Activity tracking configuration
|
|
18
|
+
* Events used to detect user activity for session management
|
|
19
|
+
* - click: Detects real user interaction with minimal performance impact
|
|
20
|
+
* - visibilitychange: Handled separately to detect tab changes
|
|
21
|
+
*/
|
|
22
|
+
export declare const ACTIVITY_EVENTS: string[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const
|
|
2
|
-
var _ = /* @__PURE__ */ ((t) => (t.Track = "track", t.PageView = "pageview", t))(_ || {});
|
|
1
|
+
const _ = "dotAnalytics", t = _, n = "/api/v1/analytics/content/event", s = 30, E = "dot_analytics_session_id", S = "dot_analytics_user_id", c = ["click"];
|
|
3
2
|
export {
|
|
4
|
-
|
|
5
|
-
n as
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
c as ACTIVITY_EVENTS,
|
|
4
|
+
n as ANALYTICS_ENDPOINT,
|
|
5
|
+
t as ANALYTICS_SOURCE_TYPE,
|
|
6
|
+
_ as ANALYTICS_WINDOWS_KEY,
|
|
7
|
+
s as DEFAULT_SESSION_TIMEOUT_MINUTES,
|
|
8
|
+
E as SESSION_STORAGE_KEY,
|
|
9
|
+
S as USER_ID_KEY
|
|
10
10
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotCMSAnalyticsConfig, DotCMSPageViewRequestBody, DotCMSTrackRequestBody } from './dot-content-analytics.model';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Send an analytics event to the server
|
|
@@ -6,4 +6,4 @@ import { DotContentAnalyticsConfig } from './dot-content-analytics.model';
|
|
|
6
6
|
* @param options - The options for the event
|
|
7
7
|
* @returns A promise that resolves to the response from the server
|
|
8
8
|
*/
|
|
9
|
-
export declare const sendAnalyticsEventToServer: (
|
|
9
|
+
export declare const sendAnalyticsEventToServer: (payload: DotCMSPageViewRequestBody | DotCMSTrackRequestBody, options: DotCMSAnalyticsConfig) => Promise<void>;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { ANALYTICS_ENDPOINT as o } from "./dot-content-analytics.constants.js";
|
|
2
|
-
const
|
|
3
|
-
const r = {
|
|
4
|
-
...n,
|
|
5
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6
|
-
key: t.apiKey
|
|
7
|
-
};
|
|
8
|
-
t.debug && console.warn("DotAnalytics: Event sent:", r);
|
|
2
|
+
const n = async (r, t) => {
|
|
9
3
|
try {
|
|
10
4
|
const e = await fetch(`${t.server}${o}`, {
|
|
11
5
|
method: "POST",
|
|
@@ -18,5 +12,5 @@ const a = async (n, t) => {
|
|
|
18
12
|
}
|
|
19
13
|
};
|
|
20
14
|
export {
|
|
21
|
-
|
|
15
|
+
n as sendAnalyticsEventToServer
|
|
22
16
|
};
|