@dotcms/analytics 1.2.0-next.1 → 1.2.0-next.10
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 +197 -7
- package/lib/core/dot-analytics.content.js +63 -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 -37
- 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 +200 -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 +114 -0
- package/lib/core/shared/constants/{dot-content-analytics.constants.d.ts → dot-analytics.constants.d.ts} +61 -0
- package/lib/core/shared/constants/dot-analytics.constants.js +52 -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 +74 -3
- package/lib/core/shared/models/library.model.d.ts +77 -25
- package/lib/core/shared/models/request.model.d.ts +17 -9
- package/lib/core/shared/queue/dot-analytics.queue.utils.js +44 -37
- 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 +202 -0
- package/lib/react/hook/useRouterTracker.js +4 -4
- package/lib/react/internal/utils.js +1 -1
- package/package.json +7 -6
- 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,5 +1,5 @@
|
|
|
1
|
-
import { DotCMSEventPageData, DotCMSEventUtmData } from './data.model';
|
|
2
|
-
import { DotCMSCustomEventType, DotCMSEventType, DotCMSPredefinedEventType } from '../constants/dot-
|
|
1
|
+
import { DotCMSContentImpressionPageData, DotCMSEventPageData, DotCMSEventUtmData } from './data.model';
|
|
2
|
+
import { DotCMSCustomEventType, DotCMSEventType, DotCMSPredefinedEventType } from '../constants/dot-analytics.constants';
|
|
3
3
|
/**
|
|
4
4
|
* JSON value type for analytics custom data.
|
|
5
5
|
* Represents any valid JSON value that can be serialized and sent to the analytics server.
|
|
@@ -50,15 +50,86 @@ export type DotCMSCustomEventData = {
|
|
|
50
50
|
/** Custom data associated with the event (any valid JSON) */
|
|
51
51
|
custom: JsonObject;
|
|
52
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* Partial content impression data sent by producer plugins.
|
|
55
|
+
* Contains only impression-specific data (content and position).
|
|
56
|
+
* The enricher plugin will add page data automatically.
|
|
57
|
+
*/
|
|
58
|
+
export type DotCMSContentImpressionPayload = {
|
|
59
|
+
/** Content information */
|
|
60
|
+
content: {
|
|
61
|
+
/** Content identifier */
|
|
62
|
+
identifier: string;
|
|
63
|
+
/** Content inode */
|
|
64
|
+
inode: string;
|
|
65
|
+
/** Content title */
|
|
66
|
+
title: string;
|
|
67
|
+
/** Content type name */
|
|
68
|
+
content_type: string;
|
|
69
|
+
};
|
|
70
|
+
/** Position information in the viewport and DOM */
|
|
71
|
+
position: {
|
|
72
|
+
/** Viewport offset percentage from top */
|
|
73
|
+
viewport_offset_pct: number;
|
|
74
|
+
/** DOM index position */
|
|
75
|
+
dom_index: number;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Partial content click data sent by producer plugins.
|
|
80
|
+
* Extends impression payload with element metadata.
|
|
81
|
+
*/
|
|
82
|
+
export type DotCMSContentClickPayload = DotCMSContentImpressionPayload & {
|
|
83
|
+
/** Clicked element information */
|
|
84
|
+
element: {
|
|
85
|
+
/** Text content of the element */
|
|
86
|
+
text: string;
|
|
87
|
+
/** Type of element (anchor, button, etc.) */
|
|
88
|
+
type: string;
|
|
89
|
+
/** Element ID (required by backend, empty string if not present) */
|
|
90
|
+
id: string;
|
|
91
|
+
/** Element classes (required by backend, empty string if not present) */
|
|
92
|
+
class: string;
|
|
93
|
+
/** Link destination as written in HTML (relative path, only for <a> elements, empty string for buttons) */
|
|
94
|
+
href: string;
|
|
95
|
+
/** Additional element attributes in key:value format (e.g., ['data-category:val', 'data-campaign:val2']) */
|
|
96
|
+
attributes: string[];
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Complete data structure for content impression events after enrichment.
|
|
101
|
+
* Includes minimal page data (title and url) added by the enricher plugin.
|
|
102
|
+
*/
|
|
103
|
+
export type DotCMSContentImpressionEventData = DotCMSContentImpressionPayload & {
|
|
104
|
+
/** Minimal page data where the impression occurred (added by enricher) */
|
|
105
|
+
page: DotCMSContentImpressionPageData;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Complete data structure for content click events after enrichment.
|
|
109
|
+
* Includes minimal page data (title and url) added by the enricher plugin.
|
|
110
|
+
*/
|
|
111
|
+
export type DotCMSContentClickEventData = DotCMSContentClickPayload & {
|
|
112
|
+
/** Minimal page data where the click occurred (added by enricher) */
|
|
113
|
+
page: DotCMSContentImpressionPageData;
|
|
114
|
+
};
|
|
53
115
|
/**
|
|
54
116
|
* Pageview event structure.
|
|
55
117
|
*/
|
|
56
118
|
export type DotCMSPageViewEvent = DotCMSEventBase<typeof DotCMSPredefinedEventType.PAGEVIEW, DotCMSPageViewEventData>;
|
|
119
|
+
/**
|
|
120
|
+
* Content impression event structure.
|
|
121
|
+
*/
|
|
122
|
+
export type DotCMSContentImpressionEvent = DotCMSEventBase<typeof DotCMSPredefinedEventType.CONTENT_IMPRESSION, DotCMSContentImpressionEventData>;
|
|
123
|
+
/**
|
|
124
|
+
* Content click event structure.
|
|
125
|
+
*/
|
|
126
|
+
export type DotCMSContentClickEvent = DotCMSEventBase<typeof DotCMSPredefinedEventType.CONTENT_CLICK, DotCMSContentClickEventData>;
|
|
57
127
|
/**
|
|
58
128
|
* Custom event structure.
|
|
59
129
|
*/
|
|
60
130
|
export type DotCMSCustomEvent = DotCMSEventBase<DotCMSCustomEventType, DotCMSCustomEventData>;
|
|
61
131
|
/**
|
|
62
132
|
* Union type for all possible analytics events.
|
|
133
|
+
* Used primarily for type documentation and validation.
|
|
63
134
|
*/
|
|
64
|
-
export type DotCMSEvent = DotCMSPageViewEvent | DotCMSCustomEvent;
|
|
135
|
+
export type DotCMSEvent = DotCMSPageViewEvent | DotCMSContentImpressionEvent | DotCMSContentClickEvent | DotCMSCustomEvent;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DotCMSAnalyticsEventContext, DotCMSEventPageData, DotCMSEventUtmData } from './data.model';
|
|
2
|
-
import { JsonObject } from './event.model';
|
|
1
|
+
import { DotCMSAnalyticsEventContext, DotCMSContentImpressionPageData, DotCMSEventPageData, DotCMSEventUtmData } from './data.model';
|
|
2
|
+
import { DotCMSContentImpressionPayload, JsonObject } from './event.model';
|
|
3
3
|
import { DotCMSAnalyticsRequestBody } from './request.model';
|
|
4
|
-
import {
|
|
4
|
+
import { LogLevel } from '../dot-analytics.logger';
|
|
5
5
|
/**
|
|
6
6
|
* Configuration for event queue management.
|
|
7
7
|
* Controls how events are batched before sending to the server.
|
|
@@ -12,6 +12,37 @@ export interface QueueConfig {
|
|
|
12
12
|
/** Time in milliseconds between flushes - sends pending events (default: 5000) */
|
|
13
13
|
flushInterval?: number;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for content impression tracking.
|
|
17
|
+
* Controls how content visibility is detected and tracked.
|
|
18
|
+
*/
|
|
19
|
+
export interface ImpressionConfig {
|
|
20
|
+
/** Minimum percentage of element visible (0.0 to 1.0) - default: 0.5 */
|
|
21
|
+
visibilityThreshold?: number;
|
|
22
|
+
/** Minimum time in milliseconds element must be visible - default: 750 */
|
|
23
|
+
dwellMs?: number;
|
|
24
|
+
/** Maximum number of elements to track (performance limit) - default: 1000 */
|
|
25
|
+
maxNodes?: number;
|
|
26
|
+
/** Throttle time in milliseconds for intersection callbacks - default: 100 */
|
|
27
|
+
throttleMs?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Interface for contentlet data extracted from DOM elements
|
|
31
|
+
*/
|
|
32
|
+
export interface ContentletData {
|
|
33
|
+
identifier: string;
|
|
34
|
+
inode: string;
|
|
35
|
+
contentType: string;
|
|
36
|
+
title: string;
|
|
37
|
+
baseType: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Interface for viewport metrics
|
|
41
|
+
*/
|
|
42
|
+
export interface ViewportMetrics {
|
|
43
|
+
offsetPercentage: number;
|
|
44
|
+
visibilityRatio: number;
|
|
45
|
+
}
|
|
15
46
|
/**
|
|
16
47
|
* Main interface for the DotCMS Analytics SDK.
|
|
17
48
|
* Provides the core methods for tracking page views and custom events.
|
|
@@ -42,6 +73,16 @@ export interface DotCMSAnalyticsConfig {
|
|
|
42
73
|
* Enable debug mode to get additional logging information.
|
|
43
74
|
*/
|
|
44
75
|
debug: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Set the minimum log level for console output.
|
|
78
|
+
* - 'debug': Show all logs including detailed debugging information
|
|
79
|
+
* - 'info': Show informational messages, warnings, and errors
|
|
80
|
+
* - 'warn': Show only warnings and errors
|
|
81
|
+
* - 'error': Show only errors
|
|
82
|
+
*
|
|
83
|
+
* If not specified, falls back to debug flag (debug=true → 'debug', debug=false → 'warn')
|
|
84
|
+
*/
|
|
85
|
+
logLevel?: LogLevel;
|
|
45
86
|
/**
|
|
46
87
|
* Automatically track page views when set to true.
|
|
47
88
|
*/
|
|
@@ -57,15 +98,28 @@ export interface DotCMSAnalyticsConfig {
|
|
|
57
98
|
* - `QueueConfig`: Enable queuing with custom settings
|
|
58
99
|
*/
|
|
59
100
|
queue?: QueueConfig | boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Content impression tracking configuration (default: undefined - disabled):
|
|
103
|
+
* - `undefined` or `false`: Impression tracking disabled
|
|
104
|
+
* - `true`: Enable with default settings (threshold: 0.5, dwell: 750ms, maxNodes: 1000)
|
|
105
|
+
* - `ImpressionConfig`: Enable with custom settings
|
|
106
|
+
*/
|
|
107
|
+
impressions?: ImpressionConfig | boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Content click tracking configuration (default: undefined - disabled):
|
|
110
|
+
* - `undefined` or `false`: Click tracking disabled
|
|
111
|
+
* - `true`: Enable click tracking
|
|
112
|
+
*/
|
|
113
|
+
clicks?: boolean;
|
|
60
114
|
}
|
|
61
115
|
/**
|
|
62
116
|
* Track event payload with context.
|
|
63
|
-
* This is the payload for
|
|
117
|
+
* This is the payload for track events after the identity plugin adds context.
|
|
64
118
|
* Used in the track:dot-analytics enricher plugin.
|
|
65
119
|
*/
|
|
66
120
|
export interface AnalyticsTrackPayloadWithContext extends AnalyticsBasePayload {
|
|
67
|
-
/** The
|
|
68
|
-
event:
|
|
121
|
+
/** The event name (can be predefined or custom) */
|
|
122
|
+
event: string;
|
|
69
123
|
/** Analytics context added by identity plugin */
|
|
70
124
|
context: DotCMSAnalyticsEventContext;
|
|
71
125
|
}
|
|
@@ -84,29 +138,16 @@ type AnalyticsBasePayloadType = 'page' | 'track';
|
|
|
84
138
|
* Analytics.js hook parameter types for DotCMS.
|
|
85
139
|
* Represents the payload structure used by Analytics.js lifecycle hooks
|
|
86
140
|
* for intercepting and modifying analytics events.
|
|
141
|
+
*
|
|
142
|
+
* Properties are flexible (Record<string, unknown>) to support both:
|
|
143
|
+
* - Page events: with page-specific fields (title, url, path, etc.)
|
|
144
|
+
* - Track events: with any custom event data structure
|
|
87
145
|
*/
|
|
88
146
|
export interface AnalyticsBasePayload {
|
|
89
147
|
/** The type of analytics event */
|
|
90
148
|
type: AnalyticsBasePayloadType;
|
|
91
|
-
/** Properties associated with the event */
|
|
92
|
-
properties:
|
|
93
|
-
/** Page title */
|
|
94
|
-
title: string;
|
|
95
|
-
/** Page URL */
|
|
96
|
-
url: string;
|
|
97
|
-
/** Page path */
|
|
98
|
-
path: string;
|
|
99
|
-
/** URL hash fragment */
|
|
100
|
-
hash: string;
|
|
101
|
-
/** URL search parameters */
|
|
102
|
-
search: string;
|
|
103
|
-
/** Viewport width */
|
|
104
|
-
width: number;
|
|
105
|
-
/** Viewport height */
|
|
106
|
-
height: number;
|
|
107
|
-
/** Referrer URL */
|
|
108
|
-
referrer?: string;
|
|
109
|
-
};
|
|
149
|
+
/** Properties associated with the event (flexible structure) */
|
|
150
|
+
properties: Record<string, unknown>;
|
|
110
151
|
/** Configuration options for the event */
|
|
111
152
|
options: Record<string, unknown>;
|
|
112
153
|
/** User identifier */
|
|
@@ -146,6 +187,17 @@ export type EnrichedAnalyticsPayload = AnalyticsBasePayloadWithContext & {
|
|
|
146
187
|
/** Local timestamp when the event occurred */
|
|
147
188
|
local_time: string;
|
|
148
189
|
};
|
|
190
|
+
/**
|
|
191
|
+
* Enriched track event payload with fields added to root based on event type.
|
|
192
|
+
* Used by the enricher plugin for track events.
|
|
193
|
+
*/
|
|
194
|
+
export interface EnrichedTrackPayload extends AnalyticsTrackPayloadWithContext {
|
|
195
|
+
local_time: string;
|
|
196
|
+
page?: DotCMSContentImpressionPageData | DotCMSEventPageData;
|
|
197
|
+
content?: DotCMSContentImpressionPayload['content'];
|
|
198
|
+
position?: DotCMSContentImpressionPayload['position'];
|
|
199
|
+
utm?: DotCMSEventUtmData;
|
|
200
|
+
}
|
|
149
201
|
/**
|
|
150
202
|
* Analytics.js instance structure for DotCMS.
|
|
151
203
|
* Represents the internal structure of an Analytics.js instance,
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
import { DotCMSAnalyticsEventContext } from './data.model';
|
|
2
|
-
import {
|
|
2
|
+
import { DotCMSEvent } from './event.model';
|
|
3
3
|
/**
|
|
4
4
|
* Analytics request body for DotCMS Analytics.
|
|
5
5
|
* Generic structure sent to the DotCMS analytics server.
|
|
6
|
+
*
|
|
7
|
+
* This structure contains properly typed events that match the DotCMS event specifications.
|
|
8
|
+
* Events can be pageviews, content impressions, or custom events, each with their own data structure.
|
|
6
9
|
*/
|
|
7
|
-
export interface DotCMSRequestBody
|
|
10
|
+
export interface DotCMSRequestBody {
|
|
8
11
|
/** Context information shared across all events */
|
|
9
12
|
context: DotCMSAnalyticsEventContext;
|
|
10
13
|
/** Array of analytics events to be tracked */
|
|
11
|
-
events:
|
|
14
|
+
events: DotCMSEvent[];
|
|
12
15
|
}
|
|
13
16
|
/**
|
|
14
|
-
*
|
|
17
|
+
* Main type for analytics request bodies.
|
|
18
|
+
* Flexible enough to accept any event type (pageview, content_impression, custom, etc.)
|
|
15
19
|
*/
|
|
16
|
-
export type
|
|
20
|
+
export type DotCMSAnalyticsRequestBody = DotCMSRequestBody;
|
|
17
21
|
/**
|
|
18
|
-
* Specific request body type for
|
|
22
|
+
* Specific request body type for PageView events (for type documentation)
|
|
19
23
|
*/
|
|
20
|
-
export type
|
|
24
|
+
export type DotCMSPageViewRequestBody = DotCMSRequestBody;
|
|
21
25
|
/**
|
|
22
|
-
*
|
|
26
|
+
* Specific request body type for ContentImpression events (for type documentation)
|
|
23
27
|
*/
|
|
24
|
-
export type
|
|
28
|
+
export type DotCMSContentImpressionRequestBody = DotCMSRequestBody;
|
|
29
|
+
/**
|
|
30
|
+
* Specific request body type for Custom events (for type documentation)
|
|
31
|
+
*/
|
|
32
|
+
export type DotCMSCustomEventRequestBody = DotCMSRequestBody;
|
|
@@ -1,40 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import m from "@analytics/queue-utils";
|
|
2
|
+
import v from "@analytics/router-utils";
|
|
3
|
+
import { DEFAULT_QUEUE_CONFIG as y } from "../constants/dot-analytics.constants.js";
|
|
4
|
+
import { sendAnalyticsEvent as b } from "../http/dot-analytics.http.js";
|
|
5
|
+
import { createPluginLogger as w } from "../utils/dot-analytics.utils.js";
|
|
6
|
+
const L = (o) => {
|
|
7
|
+
const i = w("Queue", o);
|
|
8
|
+
let e = null, n = null, u = !1, d = !1, f = typeof window < "u" ? window.location.pathname : "";
|
|
9
|
+
const a = {
|
|
10
|
+
...y,
|
|
11
|
+
...typeof o.queue == "object" ? o.queue : {}
|
|
12
|
+
}, g = (t, s) => {
|
|
13
|
+
if (!n) return;
|
|
14
|
+
i.debug(`Sending batch of ${t.length} event(s)`, {
|
|
12
15
|
events: t,
|
|
13
|
-
|
|
14
|
-
}),
|
|
15
|
-
},
|
|
16
|
-
!e || e.size() === 0 || !
|
|
17
|
-
|
|
18
|
-
),
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
keepalive: u
|
|
17
|
+
}), b({ context: n, events: t }, o, u);
|
|
18
|
+
}, l = () => {
|
|
19
|
+
!e || e.size() === 0 || !n || (i.info(`Flushing ${e.size()} events (page hidden/unload)`), u = !0, e.flush(!0));
|
|
20
|
+
}, c = () => {
|
|
21
|
+
if (i.debug("handleVisibilityChange", document.visibilityState), document.visibilityState === "hidden") {
|
|
22
|
+
if (d) {
|
|
23
|
+
i.debug("Skipping flush (SPA navigation detected)");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
l();
|
|
27
|
+
} else document.visibilityState === "visible" && (d = !1);
|
|
21
28
|
};
|
|
22
29
|
return {
|
|
23
30
|
/**
|
|
24
31
|
* Initialize the queue with smart batching
|
|
25
32
|
*/
|
|
26
33
|
initialize: () => {
|
|
27
|
-
e =
|
|
28
|
-
(t) => {
|
|
29
|
-
|
|
34
|
+
e = m(
|
|
35
|
+
(t, s) => {
|
|
36
|
+
g(t);
|
|
30
37
|
},
|
|
31
38
|
{
|
|
32
|
-
max:
|
|
33
|
-
interval:
|
|
39
|
+
max: a.eventBatchSize,
|
|
40
|
+
interval: a.flushInterval,
|
|
34
41
|
throttle: !1
|
|
35
42
|
// Always false - enables both batch size and interval triggers
|
|
36
43
|
}
|
|
37
|
-
), typeof window < "u" && typeof document < "u" && (document.addEventListener("visibilitychange",
|
|
44
|
+
), typeof window < "u" && typeof document < "u" && (document.addEventListener("visibilitychange", c), window.addEventListener("pagehide", l), v((t) => {
|
|
45
|
+
d = !0, f = t, i.debug(`SPA navigation detected (${f})`), setTimeout(() => {
|
|
46
|
+
d = !1;
|
|
47
|
+
}, 100);
|
|
48
|
+
}));
|
|
38
49
|
},
|
|
39
50
|
/**
|
|
40
51
|
* Add event to queue
|
|
@@ -43,16 +54,12 @@ const z = (n) => {
|
|
|
43
54
|
* - Sends pending events every flushInterval
|
|
44
55
|
*/
|
|
45
56
|
enqueue: (t, s) => {
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
e.push(t);
|
|
55
|
-
}
|
|
57
|
+
if (n = s, !e) return;
|
|
58
|
+
const r = e.size() + 1, p = a.eventBatchSize, h = r >= p;
|
|
59
|
+
i.debug(
|
|
60
|
+
`Event added. Queue size: ${r}/${p}${h ? " (full, sending...)" : ""}`,
|
|
61
|
+
{ eventType: t.event_type, event: t }
|
|
62
|
+
), e.push(t);
|
|
56
63
|
},
|
|
57
64
|
/**
|
|
58
65
|
* Get queue size for debugging
|
|
@@ -64,10 +71,10 @@ const z = (n) => {
|
|
|
64
71
|
* Flushes remaining events and cleans up listeners
|
|
65
72
|
*/
|
|
66
73
|
cleanup: () => {
|
|
67
|
-
|
|
74
|
+
l(), typeof window < "u" && typeof document < "u" && (document.removeEventListener("visibilitychange", c), window.removeEventListener("pagehide", l)), e = null, n = null, u = !1;
|
|
68
75
|
}
|
|
69
76
|
};
|
|
70
77
|
};
|
|
71
78
|
export {
|
|
72
|
-
|
|
79
|
+
L as createAnalyticsQueue
|
|
73
80
|
};
|
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
import { PageData } from 'analytics';
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { AnalyticsPlugin, PageData } from 'analytics';
|
|
2
|
+
import { DotCMSPredefinedEventType } from '../constants';
|
|
3
|
+
import { DotLogger, LogLevel } from '../dot-analytics.logger';
|
|
4
|
+
import { AnalyticsBasePayloadWithContext, ContentletData, DotCMSAnalyticsConfig, DotCMSAnalyticsEventContext, DotCMSBrowserData, DotCMSEventDeviceData, DotCMSEventUtmData, EnrichedAnalyticsPayload } from '../models';
|
|
5
|
+
export { cleanupActivityTracking, initializeActivityTracking, updateSessionActivity } from '../../plugin/identity/dot-analytics.identity.activity-tracker';
|
|
6
|
+
/**
|
|
7
|
+
* Type guard to check if an event is a predefined event type.
|
|
8
|
+
* Enables TypeScript type narrowing for better type safety.
|
|
9
|
+
*
|
|
10
|
+
* @param event - Event name to check
|
|
11
|
+
* @returns True if event is a predefined type, false for custom events
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* if (isPredefinedEventType(eventName)) {
|
|
16
|
+
* // TypeScript knows eventName is DotCMSPredefinedEventType here
|
|
17
|
+
* console.log('Predefined event:', eventName);
|
|
18
|
+
* } else {
|
|
19
|
+
* // TypeScript knows eventName is string (custom) here
|
|
20
|
+
* console.log('Custom event:', eventName);
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function isPredefinedEventType(event: string): event is DotCMSPredefinedEventType;
|
|
4
25
|
/**
|
|
5
26
|
* Validates required configuration fields for Analytics initialization.
|
|
6
27
|
*
|
|
@@ -170,3 +191,70 @@ export declare const enrichPagePayload: (payload: {
|
|
|
170
191
|
properties: Record<string, unknown>;
|
|
171
192
|
};
|
|
172
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* Creates a throttled version of a callback function
|
|
196
|
+
* Ensures the callback is executed at most once every `limitMs` milliseconds
|
|
197
|
+
* @param callback - The function to throttle
|
|
198
|
+
* @param limitMs - The time limit in milliseconds
|
|
199
|
+
* @returns A throttled function
|
|
200
|
+
*/
|
|
201
|
+
export declare function createThrottle<T extends (...args: unknown[]) => void>(callback: T, limitMs: number): (...args: Parameters<T>) => void;
|
|
202
|
+
/**
|
|
203
|
+
* Extracts the contentlet identifier from a DOM element
|
|
204
|
+
* @param element - The HTML element containing data attributes
|
|
205
|
+
* @returns The contentlet identifier or null if not found
|
|
206
|
+
*/
|
|
207
|
+
export declare function extractContentletIdentifier(element: HTMLElement): string | null;
|
|
208
|
+
/**
|
|
209
|
+
* Extracts all contentlet data from a DOM element's data attributes
|
|
210
|
+
* @param element - The HTML element containing data attributes
|
|
211
|
+
* @returns Complete contentlet data object
|
|
212
|
+
*/
|
|
213
|
+
export declare function extractContentletData(element: HTMLElement): ContentletData;
|
|
214
|
+
/**
|
|
215
|
+
* Initial scan delay for DOM readiness
|
|
216
|
+
* Allows React/Next.js to finish rendering before scanning for contentlets
|
|
217
|
+
*/
|
|
218
|
+
export declare const INITIAL_SCAN_DELAY_MS = 100;
|
|
219
|
+
/**
|
|
220
|
+
* Checks if code is running in a browser environment
|
|
221
|
+
* @returns true if window and document are available
|
|
222
|
+
*/
|
|
223
|
+
export declare const isBrowser: () => boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Finds all contentlet elements in the DOM
|
|
226
|
+
* @returns Array of contentlet HTMLElements
|
|
227
|
+
*/
|
|
228
|
+
export declare const findContentlets: () => HTMLElement[];
|
|
229
|
+
/**
|
|
230
|
+
* Creates a MutationObserver that watches for contentlet changes in the DOM
|
|
231
|
+
* @param callback - Function to call when mutations are detected
|
|
232
|
+
* @param debounceMs - Debounce time in milliseconds (default: 250ms)
|
|
233
|
+
* @returns Configured and active MutationObserver
|
|
234
|
+
*/
|
|
235
|
+
export declare const createContentletObserver: (callback: () => void, debounceMs?: number) => MutationObserver;
|
|
236
|
+
/**
|
|
237
|
+
* Sets up cleanup handlers for page unload events
|
|
238
|
+
* Registers cleanup function to both 'beforeunload' and 'pagehide' for maximum compatibility
|
|
239
|
+
* @param cleanup - Function to call on page unload
|
|
240
|
+
*/
|
|
241
|
+
export declare const setupPluginCleanup: (cleanup: () => void) => void;
|
|
242
|
+
/**
|
|
243
|
+
* Creates a logger with plugin-specific prefix and configurable log level
|
|
244
|
+
* @param pluginName - Name of the plugin (e.g., 'Click', 'Impression')
|
|
245
|
+
* @param config - Analytics configuration with debug flag and optional logLevel
|
|
246
|
+
* @returns DotLogger instance with configured log level
|
|
247
|
+
*/
|
|
248
|
+
export declare const createPluginLogger: (pluginName: string, config: {
|
|
249
|
+
debug: boolean;
|
|
250
|
+
logLevel?: LogLevel;
|
|
251
|
+
}) => DotLogger;
|
|
252
|
+
/**
|
|
253
|
+
* Gets enhanced tracking plugins based on configuration
|
|
254
|
+
* Returns content impression and click tracking plugins if enabled
|
|
255
|
+
* @param config - Analytics configuration
|
|
256
|
+
* @param impressionPlugin - Impression tracking plugin factory
|
|
257
|
+
* @param clickPlugin - Click tracking plugin factory
|
|
258
|
+
* @returns Array of enabled tracking plugins
|
|
259
|
+
*/
|
|
260
|
+
export declare const getEnhancedTrackingPlugins: (config: DotCMSAnalyticsConfig, impressionPlugin: (config: DotCMSAnalyticsConfig) => AnalyticsPlugin, clickPlugin: (config: DotCMSAnalyticsConfig) => AnalyticsPlugin) => AnalyticsPlugin[];
|