@dotcms/events 0.0.0-stage → 26.10.5-1-alpha.0
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 +516 -2
- package/decision.cjs.js +108 -0
- package/decision.esm.js +92 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +3674 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +1 -0
- package/index.esm.js +3672 -0
- package/markup.cjs.default.js +1 -0
- package/markup.cjs.js +161 -0
- package/markup.cjs.mjs +2 -0
- package/markup.d.ts +1 -0
- package/markup.esm.js +159 -0
- package/package.json +77 -4
- package/react.cjs.default.js +1 -0
- package/react.cjs.js +39 -0
- package/react.cjs.mjs +2 -0
- package/react.d.ts +1 -0
- package/react.esm.js +37 -0
- package/src/index.d.ts +8 -0
- package/src/lib/clicks/constants.d.ts +14 -0
- package/src/lib/clicks/plugin.d.ts +35 -0
- package/src/lib/clicks/tracker.d.ts +42 -0
- package/src/lib/clicks/utils.d.ts +13 -0
- package/src/lib/contentlets/constants.d.ts +36 -0
- package/src/lib/contentlets/utils.d.ts +64 -0
- package/src/lib/contentlets/viewport.d.ts +23 -0
- package/src/lib/events.d.ts +17 -0
- package/src/lib/experiments/api.d.ts +9 -0
- package/src/lib/experiments/boot.d.ts +53 -0
- package/src/lib/experiments/constants.d.ts +46 -0
- package/src/lib/experiments/decision.d.ts +53 -0
- package/src/lib/experiments/dom.d.ts +62 -0
- package/src/lib/experiments/engine.d.ts +66 -0
- package/src/lib/experiments/markup.d.ts +17 -0
- package/src/lib/experiments/models.d.ts +62 -0
- package/src/lib/experiments/plugin.d.ts +27 -0
- package/src/lib/experiments/store.d.ts +54 -0
- package/src/lib/impressions/constants.d.ts +28 -0
- package/src/lib/impressions/plugin.d.ts +38 -0
- package/src/lib/impressions/tracker.d.ts +67 -0
- package/src/lib/impressions/utils.d.ts +10 -0
- package/src/lib/models.d.ts +130 -0
- package/src/lib/pipeline/constants.d.ts +88 -0
- package/src/lib/pipeline/enricher/plugin.d.ts +32 -0
- package/src/lib/pipeline/identity/activity.d.ts +19 -0
- package/src/lib/pipeline/identity/plugin.d.ts +60 -0
- package/src/lib/pipeline/logger.d.ts +74 -0
- package/src/lib/pipeline/models.d.ts +588 -0
- package/src/lib/pipeline/navigation.d.ts +21 -0
- package/src/lib/pipeline/sender/http.d.ts +9 -0
- package/src/lib/pipeline/sender/plugin.d.ts +47 -0
- package/src/lib/pipeline/sender/queue.d.ts +33 -0
- package/src/lib/pipeline/utils.d.ts +119 -0
- package/src/lib/react/DotCMSExperiment.d.ts +36 -0
- package/src/markup.d.ts +7 -0
- package/src/react.d.ts +8 -0
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pipeline's internal types: its config, the payloads its plugins pass along, and the
|
|
3
|
+
* shapes of the events and requests dotCMS receives.
|
|
4
|
+
*/
|
|
5
|
+
import type { DotCMSPredefinedEventType } from './constants';
|
|
6
|
+
import type { LogLevel } from './logger';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for event queue management.
|
|
9
|
+
* Controls how events are batched before sending to the server.
|
|
10
|
+
*/
|
|
11
|
+
export interface QueueConfig {
|
|
12
|
+
/** Maximum events per batch - auto-sends when reached (default: 15) */
|
|
13
|
+
eventBatchSize?: number;
|
|
14
|
+
/** Time in milliseconds between flushes - sends pending events (default: 5000) */
|
|
15
|
+
flushInterval?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Configuration for content impression tracking.
|
|
19
|
+
* Controls how content visibility is detected and tracked.
|
|
20
|
+
*/
|
|
21
|
+
export interface ImpressionConfig {
|
|
22
|
+
/** Minimum percentage of element visible (0.0 to 1.0) - default: 0.5 */
|
|
23
|
+
visibilityThreshold?: number;
|
|
24
|
+
/** Minimum time in milliseconds element must be visible - default: 750 */
|
|
25
|
+
dwellMs?: number;
|
|
26
|
+
/** Maximum number of elements to track (performance limit) - default: 100 */
|
|
27
|
+
maxNodes?: 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
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Configuration interface for DotCMS Analytics SDK.
|
|
48
|
+
* Contains all necessary settings for initializing and configuring the analytics client.
|
|
49
|
+
*/
|
|
50
|
+
export interface PipelineConfig {
|
|
51
|
+
/**
|
|
52
|
+
* The URL of the Analytics server endpoint.
|
|
53
|
+
*/
|
|
54
|
+
server: string;
|
|
55
|
+
/**
|
|
56
|
+
* Enable debug mode to get additional logging information.
|
|
57
|
+
*/
|
|
58
|
+
debug: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Set the minimum log level for console output.
|
|
61
|
+
* - 'debug': Show all logs including detailed debugging information
|
|
62
|
+
* - 'info': Show informational messages, warnings, and errors
|
|
63
|
+
* - 'warn': Show only warnings and errors
|
|
64
|
+
* - 'error': Show only errors
|
|
65
|
+
*
|
|
66
|
+
* If not specified, falls back to debug flag (debug=true → 'debug', debug=false → 'warn')
|
|
67
|
+
*/
|
|
68
|
+
logLevel?: LogLevel;
|
|
69
|
+
/**
|
|
70
|
+
* Automatically track page views. Defaults to `true` (opt-out).
|
|
71
|
+
* Set explicitly to `false` to disable automatic page view tracking.
|
|
72
|
+
* Via the HTML `data-analytics-auto-page-view` attribute, only the literal string "false"
|
|
73
|
+
* disables it (any other value, including "", enables it).
|
|
74
|
+
*/
|
|
75
|
+
autoPageView?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* The site auth for authenticating with the Analytics service.
|
|
78
|
+
*/
|
|
79
|
+
siteAuth: string;
|
|
80
|
+
/**
|
|
81
|
+
* Queue configuration for event batching:
|
|
82
|
+
* - `false`: Disable queuing, send events immediately
|
|
83
|
+
* - `true` or `undefined` (default): Enable queuing with default settings
|
|
84
|
+
* - `QueueConfig`: Enable queuing with custom settings
|
|
85
|
+
*/
|
|
86
|
+
queue?: QueueConfig | boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Content impression tracking configuration (default: undefined - disabled):
|
|
89
|
+
* - `undefined` or `false`: Impression tracking disabled
|
|
90
|
+
* - `true`: Enable with default settings (threshold: 0.5, dwell: 750ms, maxNodes: 100)
|
|
91
|
+
* - `ImpressionConfig`: Enable with custom settings
|
|
92
|
+
*/
|
|
93
|
+
impressions?: ImpressionConfig | boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Content click tracking configuration (default: undefined - disabled):
|
|
96
|
+
* - `undefined` or `false`: Click tracking disabled
|
|
97
|
+
* - `true`: Enable click tracking
|
|
98
|
+
*/
|
|
99
|
+
clicks?: boolean;
|
|
100
|
+
/** Called when an events request fails. It must not throw. */
|
|
101
|
+
onError?: (error: PipelineError) => void;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* An events request that failed. Events are never retried.
|
|
105
|
+
*/
|
|
106
|
+
export interface PipelineError {
|
|
107
|
+
/**
|
|
108
|
+
* `REJECTED`: dotCMS answered with an error, or accepted the request but failed some of its
|
|
109
|
+
* events. `NETWORK`: the request got no answer.
|
|
110
|
+
*/
|
|
111
|
+
code: 'REJECTED' | 'NETWORK';
|
|
112
|
+
message: string;
|
|
113
|
+
/** The HTTP status, when dotCMS answered. */
|
|
114
|
+
status?: number;
|
|
115
|
+
/** What dotCMS said about the failure: its error list, when it sent one. */
|
|
116
|
+
detail?: unknown;
|
|
117
|
+
/** How many events the request carried. */
|
|
118
|
+
events: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Track event payload with context.
|
|
122
|
+
* This is the payload for track events after the identity plugin adds context.
|
|
123
|
+
* Used in the enricher's track hook.
|
|
124
|
+
*/
|
|
125
|
+
export interface AnalyticsTrackPayloadWithContext extends AnalyticsBasePayload {
|
|
126
|
+
/** The event name (can be predefined or custom) */
|
|
127
|
+
event: string;
|
|
128
|
+
/** Analytics context added by identity plugin */
|
|
129
|
+
context: EventContext;
|
|
130
|
+
}
|
|
131
|
+
type AnalyticsBasePayloadType = 'page' | 'track';
|
|
132
|
+
/**
|
|
133
|
+
* Analytics.js hook parameter types for DotCMS.
|
|
134
|
+
* Represents the payload structure used by Analytics.js lifecycle hooks
|
|
135
|
+
* for intercepting and modifying analytics events.
|
|
136
|
+
*
|
|
137
|
+
* Properties are flexible (Record<string, unknown>) to support both:
|
|
138
|
+
* - Page events: with page-specific fields (title, url, path, etc.)
|
|
139
|
+
* - Track events: with any custom event data structure
|
|
140
|
+
*/
|
|
141
|
+
export interface AnalyticsBasePayload {
|
|
142
|
+
/** The type of analytics event */
|
|
143
|
+
type: AnalyticsBasePayloadType;
|
|
144
|
+
/** Properties associated with the event (flexible structure) */
|
|
145
|
+
properties: Record<string, unknown>;
|
|
146
|
+
/** Configuration options for the event */
|
|
147
|
+
options: Record<string, unknown>;
|
|
148
|
+
/** User identifier */
|
|
149
|
+
userId: string;
|
|
150
|
+
/** Anonymous user identifier */
|
|
151
|
+
anonymousId: string;
|
|
152
|
+
/** Metadata about the event */
|
|
153
|
+
meta: {
|
|
154
|
+
/** Request identifier */
|
|
155
|
+
rid: string;
|
|
156
|
+
/** Timestamp */
|
|
157
|
+
ts: number;
|
|
158
|
+
/** Whether the event has a callback function */
|
|
159
|
+
hasCallback: boolean;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Analytics.js payload with context.
|
|
164
|
+
* This is the result of enriching the base Analytics.js payload
|
|
165
|
+
* with context data added by the identity plugin.
|
|
166
|
+
*/
|
|
167
|
+
export interface AnalyticsBasePayloadWithContext extends AnalyticsBasePayload {
|
|
168
|
+
context: EventContext;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Enriched analytics payload with DotCMS-specific data.
|
|
172
|
+
* This is the result of enriching the base Analytics.js payload with context (from identity plugin)
|
|
173
|
+
* and then adding page, UTM, and custom data (from enricher plugin).
|
|
174
|
+
*/
|
|
175
|
+
export type EnrichedAnalyticsPayload = AnalyticsBasePayloadWithContext & {
|
|
176
|
+
/** Page data for the current page */
|
|
177
|
+
page: DotCMSEventPageData;
|
|
178
|
+
/** UTM parameters for campaign tracking */
|
|
179
|
+
utm?: DotCMSEventUtmData;
|
|
180
|
+
/** Custom data associated with the event (any valid JSON) */
|
|
181
|
+
custom?: JsonObject;
|
|
182
|
+
/** Local timestamp when the event occurred */
|
|
183
|
+
local_time: string;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Enriched track event payload with fields added to root based on event type.
|
|
187
|
+
* Used by the enricher plugin for track events.
|
|
188
|
+
*/
|
|
189
|
+
export interface EnrichedTrackPayload extends AnalyticsTrackPayloadWithContext {
|
|
190
|
+
local_time: string;
|
|
191
|
+
page?: DotCMSContentImpressionPageData | DotCMSEventPageData;
|
|
192
|
+
content?: DotCMSContentImpressionPayload['content'];
|
|
193
|
+
position?: DotCMSContentImpressionPayload['position'];
|
|
194
|
+
utm?: DotCMSEventUtmData;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Analytics.js instance structure for DotCMS.
|
|
198
|
+
* Represents the internal structure of an Analytics.js instance,
|
|
199
|
+
* providing access to plugins, storage, and event configuration.
|
|
200
|
+
*/
|
|
201
|
+
export interface AnalyticsPluginInstance {
|
|
202
|
+
/** Available plugins and their configurations */
|
|
203
|
+
plugins: Record<string, unknown>;
|
|
204
|
+
/** Storage mechanisms for analytics data */
|
|
205
|
+
storage: Record<string, unknown>;
|
|
206
|
+
/** Event configuration */
|
|
207
|
+
events: {
|
|
208
|
+
/** Core event types */
|
|
209
|
+
core: string[];
|
|
210
|
+
/** Plugin-specific event types */
|
|
211
|
+
plugins: string[];
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Base parameters structure passed by Analytics.js to plugin hooks.
|
|
216
|
+
* Contains all the context and data needed for Analytics.js lifecycle hooks
|
|
217
|
+
* to process and modify analytics events.
|
|
218
|
+
*/
|
|
219
|
+
export interface AnalyticsBaseParams {
|
|
220
|
+
/** The event payload data */
|
|
221
|
+
payload: AnalyticsBasePayload;
|
|
222
|
+
/** The analytics instance */
|
|
223
|
+
instance: AnalyticsPluginInstance;
|
|
224
|
+
/** Global configuration settings */
|
|
225
|
+
config: Record<string, unknown>;
|
|
226
|
+
/** Available plugins and their status */
|
|
227
|
+
plugins: Record<string, {
|
|
228
|
+
/** Whether the plugin is enabled */
|
|
229
|
+
enabled: boolean;
|
|
230
|
+
/** Whether the plugin is initialized */
|
|
231
|
+
initialized: boolean;
|
|
232
|
+
/** Whether the plugin is loaded */
|
|
233
|
+
loaded: boolean;
|
|
234
|
+
/** Plugin-specific configuration */
|
|
235
|
+
config: Record<string, unknown>;
|
|
236
|
+
}>;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Browser event data collected from the user's session in DotCMS.
|
|
240
|
+
* Contains comprehensive information about the user's browser environment,
|
|
241
|
+
* page context, and session details for analytics tracking.
|
|
242
|
+
*
|
|
243
|
+
* This is an internal type used by utility functions.
|
|
244
|
+
*/
|
|
245
|
+
export interface DotCMSBrowserData {
|
|
246
|
+
/** UTC timestamp when the event occurred */
|
|
247
|
+
utc_time: string;
|
|
248
|
+
/** Local timezone offset in minutes */
|
|
249
|
+
local_tz_offset: number;
|
|
250
|
+
/** Screen resolution as a string (e.g., "1920x1080") */
|
|
251
|
+
screen_resolution: string;
|
|
252
|
+
/** Viewport size as a string (e.g., "1200x800") */
|
|
253
|
+
vp_size: string;
|
|
254
|
+
/** User's preferred language */
|
|
255
|
+
user_language: string;
|
|
256
|
+
/** Document encoding */
|
|
257
|
+
doc_encoding: string;
|
|
258
|
+
/** Document path */
|
|
259
|
+
doc_path: string;
|
|
260
|
+
/** Document host */
|
|
261
|
+
doc_host: string;
|
|
262
|
+
/** Document protocol (http/https) */
|
|
263
|
+
doc_protocol: string;
|
|
264
|
+
/** Document hash fragment */
|
|
265
|
+
doc_hash: string;
|
|
266
|
+
/** Document search parameters */
|
|
267
|
+
doc_search: string;
|
|
268
|
+
/** Referrer URL */
|
|
269
|
+
referrer: string;
|
|
270
|
+
/** Page title */
|
|
271
|
+
page_title: string;
|
|
272
|
+
/** Current page URL */
|
|
273
|
+
url: string;
|
|
274
|
+
/** UTM parameters for campaign tracking */
|
|
275
|
+
utm: DotCMSEventUtmData;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Analytics context shared across all events in DotCMS.
|
|
279
|
+
* Contains session and user identification data that provides
|
|
280
|
+
* continuity across multiple analytics events.
|
|
281
|
+
*/
|
|
282
|
+
export interface EventContext {
|
|
283
|
+
/** The site key for the DotCMS instance */
|
|
284
|
+
site_auth: string;
|
|
285
|
+
/** Unique session identifier */
|
|
286
|
+
session_id: string;
|
|
287
|
+
/** Unique user identifier */
|
|
288
|
+
user_id: string;
|
|
289
|
+
/** Device and browser information */
|
|
290
|
+
device: DotCMSEventDeviceData;
|
|
291
|
+
/**
|
|
292
|
+
* Experiments the visitor reached in this session, cumulative, on events from a page that
|
|
293
|
+
* runs an experiment the visitor is in. Left out on any other page.
|
|
294
|
+
*/
|
|
295
|
+
experiments?: DotCMSEventContextExperiment[];
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* One experiment in `context.experiments`, in the shape CAEM stores.
|
|
299
|
+
*/
|
|
300
|
+
export interface DotCMSEventContextExperiment {
|
|
301
|
+
/** Experiment identifier */
|
|
302
|
+
id: string;
|
|
303
|
+
/** Identifier of the experiment's current run */
|
|
304
|
+
running_id: string;
|
|
305
|
+
/** Name of the variant the visitor was assigned */
|
|
306
|
+
variant: string;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Device and browser information for DotCMS analytics tracking.
|
|
310
|
+
* Contains technical details about the user's device and browser environment.
|
|
311
|
+
*/
|
|
312
|
+
export interface DotCMSEventDeviceData {
|
|
313
|
+
/** Screen resolution as a string (e.g., "1920x1080") */
|
|
314
|
+
screen_resolution: string;
|
|
315
|
+
/** User's preferred language */
|
|
316
|
+
language: string;
|
|
317
|
+
/** Viewport width in pixels */
|
|
318
|
+
viewport_width: string;
|
|
319
|
+
/** Viewport height in pixels */
|
|
320
|
+
viewport_height: string;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* UTM (Urchin Tracking Module) parameters for DotCMS campaign tracking.
|
|
324
|
+
* Contains marketing campaign attribution data extracted from URL parameters.
|
|
325
|
+
*/
|
|
326
|
+
export interface DotCMSEventUtmData {
|
|
327
|
+
/** The marketing medium (e.g., email, social, cpc) */
|
|
328
|
+
medium?: string;
|
|
329
|
+
/** The traffic source (e.g., google, newsletter) */
|
|
330
|
+
source?: string;
|
|
331
|
+
/** The campaign name */
|
|
332
|
+
campaign?: string;
|
|
333
|
+
/** The campaign term or keyword */
|
|
334
|
+
term?: string;
|
|
335
|
+
/** The campaign content or ad variation */
|
|
336
|
+
content?: string;
|
|
337
|
+
/** The campaign ID for tracking specific campaigns */
|
|
338
|
+
id?: string;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Page data structure for DotCMS analytics (used in pageview events).
|
|
342
|
+
* Contains comprehensive information about the current page and its context
|
|
343
|
+
* within the DotCMS environment.
|
|
344
|
+
*/
|
|
345
|
+
export type DotCMSEventPageData = Pick<DotCMSBrowserData, 'url' | 'doc_path' | 'doc_hash' | 'doc_search' | 'doc_host' | 'doc_protocol' | 'doc_encoding'> & {
|
|
346
|
+
/** Page title */
|
|
347
|
+
title: string | undefined;
|
|
348
|
+
/** Locale identifier (e.g., es-es, en-us) */
|
|
349
|
+
locale_id: string;
|
|
350
|
+
/** Persona identifier */
|
|
351
|
+
persona?: string;
|
|
352
|
+
};
|
|
353
|
+
/**
|
|
354
|
+
* Minimal page data for content impression events.
|
|
355
|
+
* Contains only essential page information (title and url) to keep payload lightweight.
|
|
356
|
+
*/
|
|
357
|
+
export type DotCMSContentImpressionPageData = Pick<DotCMSEventPageData, 'title' | 'url'>;
|
|
358
|
+
/**
|
|
359
|
+
* Data structure for content impression events.
|
|
360
|
+
* Tracks when a contentlet becomes visible in the viewport.
|
|
361
|
+
*/
|
|
362
|
+
export interface DotCMSImpressionEventData {
|
|
363
|
+
/** Contentlet identification data extracted from data-dot-analytics-* attributes */
|
|
364
|
+
contentlet: {
|
|
365
|
+
/** Unique identifier of the contentlet */
|
|
366
|
+
identifier: string;
|
|
367
|
+
/** Inode of the contentlet */
|
|
368
|
+
inode: string;
|
|
369
|
+
/** Content type name */
|
|
370
|
+
contentType: string;
|
|
371
|
+
/** Title of the contentlet */
|
|
372
|
+
title: string;
|
|
373
|
+
/** Base type of the contentlet (e.g., CONTENT, WIDGET) */
|
|
374
|
+
baseType: string;
|
|
375
|
+
};
|
|
376
|
+
/** Viewport position and visibility metrics */
|
|
377
|
+
viewport: {
|
|
378
|
+
/** Percentage offset from top of viewport (0-100) */
|
|
379
|
+
offsetPercentage: number;
|
|
380
|
+
/** Percentage of element visible in viewport (0-1) */
|
|
381
|
+
visibilityRatio: number;
|
|
382
|
+
};
|
|
383
|
+
/** Timing information about the impression */
|
|
384
|
+
timing: {
|
|
385
|
+
/** Time in milliseconds the element was continuously visible */
|
|
386
|
+
dwellTime: number;
|
|
387
|
+
/** ISO 8601 timestamp when the impression was fired */
|
|
388
|
+
timestamp: string;
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* JSON value type for analytics custom data.
|
|
393
|
+
* Represents any valid JSON value that can be serialized and sent to the analytics server.
|
|
394
|
+
*/
|
|
395
|
+
export type JsonValue = string | number | boolean | null | undefined | JsonObject | JsonArray;
|
|
396
|
+
/**
|
|
397
|
+
* JSON object type for analytics custom data.
|
|
398
|
+
*/
|
|
399
|
+
export type JsonObject = {
|
|
400
|
+
[key: string]: JsonValue;
|
|
401
|
+
};
|
|
402
|
+
/**
|
|
403
|
+
* JSON array type for analytics custom data.
|
|
404
|
+
*/
|
|
405
|
+
export type JsonArray = JsonValue[];
|
|
406
|
+
/**
|
|
407
|
+
* Generic base event structure for DotCMS Analytics.
|
|
408
|
+
* All events share this base structure with customizable event type and data.
|
|
409
|
+
*
|
|
410
|
+
* @template TEventType - The type of the event (pageview, custom event name, etc.)
|
|
411
|
+
* @template TData - The data structure for the event
|
|
412
|
+
*/
|
|
413
|
+
export interface DotCMSEventBase<TEventType extends DotCMSPredefinedEventType, TData> {
|
|
414
|
+
/** The type of event being tracked */
|
|
415
|
+
event_type: TEventType;
|
|
416
|
+
/** Local timestamp when the event occurred */
|
|
417
|
+
local_time: string;
|
|
418
|
+
/** Event-specific data with structured format */
|
|
419
|
+
data: TData;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Data structure for pageview events.
|
|
423
|
+
* Contains page and optional UTM/custom data.
|
|
424
|
+
*/
|
|
425
|
+
export type DotCMSPageViewEventData = {
|
|
426
|
+
/** Page data associated with the event */
|
|
427
|
+
page: DotCMSEventPageData;
|
|
428
|
+
/** UTM parameters for campaign tracking (optional) */
|
|
429
|
+
utm?: DotCMSEventUtmData;
|
|
430
|
+
/** Custom data associated with the event (any valid JSON) */
|
|
431
|
+
custom?: JsonObject;
|
|
432
|
+
};
|
|
433
|
+
/**
|
|
434
|
+
* Element information for analytics events.
|
|
435
|
+
* Base type for element metadata in click and conversion events.
|
|
436
|
+
*/
|
|
437
|
+
export type DotCMSElementData = {
|
|
438
|
+
/** Text content of the element */
|
|
439
|
+
text: string;
|
|
440
|
+
/** Type of element (anchor, button, input, etc.) */
|
|
441
|
+
type: string;
|
|
442
|
+
/** Element ID (required by backend, empty string if not present) */
|
|
443
|
+
id: string;
|
|
444
|
+
/** Element classes (required by backend, empty string if not present) */
|
|
445
|
+
class: string;
|
|
446
|
+
/** Link destination as written in HTML (relative path, only for <a> elements, empty string for buttons) */
|
|
447
|
+
href: string;
|
|
448
|
+
/** Additional element attributes in key:value format (e.g., ['data-category:val', 'data-campaign:val2']) */
|
|
449
|
+
attributes: string[];
|
|
450
|
+
};
|
|
451
|
+
/**
|
|
452
|
+
* Partial content impression data sent by producer plugins.
|
|
453
|
+
* Contains only impression-specific data (content and position).
|
|
454
|
+
* The enricher plugin will add page data automatically.
|
|
455
|
+
*/
|
|
456
|
+
export type DotCMSContentImpressionPayload = {
|
|
457
|
+
/** Content information */
|
|
458
|
+
content: {
|
|
459
|
+
/** Content identifier */
|
|
460
|
+
identifier: string;
|
|
461
|
+
/** Content inode */
|
|
462
|
+
inode: string;
|
|
463
|
+
/** Content title */
|
|
464
|
+
title: string;
|
|
465
|
+
/** Content type name */
|
|
466
|
+
content_type: string;
|
|
467
|
+
};
|
|
468
|
+
/** Position information in the viewport and DOM */
|
|
469
|
+
position: {
|
|
470
|
+
/** Viewport offset percentage from top */
|
|
471
|
+
viewport_offset_pct: number;
|
|
472
|
+
/** DOM index position */
|
|
473
|
+
dom_index: number;
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* Partial content click data sent by producer plugins.
|
|
478
|
+
* Extends impression payload with element metadata.
|
|
479
|
+
*/
|
|
480
|
+
export type DotCMSContentClickPayload = DotCMSContentImpressionPayload & {
|
|
481
|
+
/** Clicked element information */
|
|
482
|
+
element: DotCMSElementData;
|
|
483
|
+
};
|
|
484
|
+
/**
|
|
485
|
+
* Conversion payload sent when tracking conversions: its name. dotCMS's conversion schema
|
|
486
|
+
* accepts no custom data.
|
|
487
|
+
*/
|
|
488
|
+
export type DotCMSConversionPayload = {
|
|
489
|
+
/** Name of the conversion event */
|
|
490
|
+
name: string;
|
|
491
|
+
};
|
|
492
|
+
/**
|
|
493
|
+
* Complete data structure for content impression events after enrichment.
|
|
494
|
+
* Includes minimal page data (title and url) added by the enricher plugin.
|
|
495
|
+
*/
|
|
496
|
+
export type DotCMSContentImpressionEventData = DotCMSContentImpressionPayload & {
|
|
497
|
+
/** Minimal page data where the impression occurred (added by enricher) */
|
|
498
|
+
page: DotCMSContentImpressionPageData;
|
|
499
|
+
};
|
|
500
|
+
/**
|
|
501
|
+
* Complete data structure for content click events after enrichment.
|
|
502
|
+
* Includes minimal page data (title and url) added by the enricher plugin.
|
|
503
|
+
*/
|
|
504
|
+
export type DotCMSContentClickEventData = DotCMSContentClickPayload & {
|
|
505
|
+
/** Minimal page data where the click occurred (added by enricher) */
|
|
506
|
+
page: DotCMSContentImpressionPageData;
|
|
507
|
+
};
|
|
508
|
+
/**
|
|
509
|
+
* Complete data structure for conversion events after enrichment.
|
|
510
|
+
* Includes page data added by the enricher plugin.
|
|
511
|
+
*/
|
|
512
|
+
export type DotCMSConversionEventData = {
|
|
513
|
+
/** Conversion information */
|
|
514
|
+
conversion: {
|
|
515
|
+
/** Name of the user-defined conversion */
|
|
516
|
+
name: string;
|
|
517
|
+
};
|
|
518
|
+
/** Page data where the conversion occurred (added by enricher) */
|
|
519
|
+
page: DotCMSContentImpressionPageData;
|
|
520
|
+
};
|
|
521
|
+
/**
|
|
522
|
+
* Pageview event structure.
|
|
523
|
+
*/
|
|
524
|
+
export type DotCMSPageViewEvent = DotCMSEventBase<typeof DotCMSPredefinedEventType.PAGEVIEW, DotCMSPageViewEventData>;
|
|
525
|
+
/**
|
|
526
|
+
* Content impression event structure.
|
|
527
|
+
*/
|
|
528
|
+
export type DotCMSContentImpressionEvent = DotCMSEventBase<typeof DotCMSPredefinedEventType.CONTENT_IMPRESSION, DotCMSContentImpressionEventData>;
|
|
529
|
+
/**
|
|
530
|
+
* Content click event structure.
|
|
531
|
+
*/
|
|
532
|
+
export type DotCMSContentClickEvent = DotCMSEventBase<typeof DotCMSPredefinedEventType.CONTENT_CLICK, DotCMSContentClickEventData>;
|
|
533
|
+
/**
|
|
534
|
+
* Conversion event structure.
|
|
535
|
+
*/
|
|
536
|
+
export type DotCMSConversionEvent = DotCMSEventBase<typeof DotCMSPredefinedEventType.CONVERSION, DotCMSConversionEventData>;
|
|
537
|
+
/**
|
|
538
|
+
* Union type for all possible analytics events.
|
|
539
|
+
* Used primarily for type documentation and validation.
|
|
540
|
+
*/
|
|
541
|
+
export type DotCMSEvent = DotCMSPageViewEvent | DotCMSContentImpressionEvent | DotCMSContentClickEvent | DotCMSConversionEvent;
|
|
542
|
+
/**
|
|
543
|
+
* Structure for persisted queue in sessionStorage.
|
|
544
|
+
* Used to preserve events across traditional page navigations.
|
|
545
|
+
*/
|
|
546
|
+
export interface PersistedQueue {
|
|
547
|
+
/** Unique identifier for this browser tab */
|
|
548
|
+
tabId: string;
|
|
549
|
+
/** Timestamp when the queue was last persisted */
|
|
550
|
+
timestamp: number;
|
|
551
|
+
/** Events waiting to be sent, each with its context */
|
|
552
|
+
events: QueuedEvent[];
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* An event waiting in the queue, with the context it was created with: a batch can hold
|
|
556
|
+
* events of several pages, and each goes out with its own.
|
|
557
|
+
*/
|
|
558
|
+
export interface QueuedEvent {
|
|
559
|
+
event: DotCMSEvent;
|
|
560
|
+
context: EventContext;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Analytics request body for DotCMS Analytics.
|
|
564
|
+
* Generic structure sent to the DotCMS analytics server.
|
|
565
|
+
*
|
|
566
|
+
* This structure contains properly typed events that match the DotCMS event specifications.
|
|
567
|
+
* Events can be pageviews, content impressions, or custom events, each with their own data structure.
|
|
568
|
+
*/
|
|
569
|
+
export interface DotCMSRequestBody {
|
|
570
|
+
/** Context information shared across all events */
|
|
571
|
+
context: EventContext;
|
|
572
|
+
/** Array of analytics events to be tracked */
|
|
573
|
+
events: DotCMSEvent[];
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Main type for analytics request bodies.
|
|
577
|
+
* It carries any of the four event types dotCMS accepts.
|
|
578
|
+
*/
|
|
579
|
+
export type EventRequestBody = DotCMSRequestBody;
|
|
580
|
+
/**
|
|
581
|
+
* Specific request body type for PageView events (for type documentation)
|
|
582
|
+
*/
|
|
583
|
+
export type DotCMSPageViewRequestBody = DotCMSRequestBody;
|
|
584
|
+
/**
|
|
585
|
+
* Specific request body type for ContentImpression events (for type documentation)
|
|
586
|
+
*/
|
|
587
|
+
export type DotCMSContentImpressionRequestBody = DotCMSRequestBody;
|
|
588
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls back on every navigation inside the page, an SPA route change, that changes the path
|
|
3
|
+
* or the query. It listens to the browser's Navigation API, which reports every History change,
|
|
4
|
+
* back and forward included, without patching `history`. Where the browser has none, it falls
|
|
5
|
+
* back to `@analytics/router-utils`, which reports path changes only.
|
|
6
|
+
*
|
|
7
|
+
* @param navigated - Called once the URL has changed
|
|
8
|
+
* @returns Stops the calls. router-utils has no way to detach, so in the fallback its listener
|
|
9
|
+
* stays and only stops calling back
|
|
10
|
+
*/
|
|
11
|
+
export declare const onNavigation: (navigated: () => void) => (() => void);
|
|
12
|
+
/**
|
|
13
|
+
* Calls back each time the browser restores the page from its back/forward cache (`pageshow`
|
|
14
|
+
* with `persisted`). The page comes back as the visitor left it, its scripts still running, so
|
|
15
|
+
* nothing that runs on a load runs again, and onNavigation reports nothing: the visitor is
|
|
16
|
+
* back on the same page, not on another route.
|
|
17
|
+
*
|
|
18
|
+
* @param restored - Called on each restore
|
|
19
|
+
* @returns Stops the calls
|
|
20
|
+
*/
|
|
21
|
+
export declare const onPageRestore: (restored: () => void) => (() => void);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PipelineConfig, EventRequestBody } from '../models';
|
|
2
|
+
/**
|
|
3
|
+
* Send analytics events to the server using fetch API
|
|
4
|
+
* @param payload - The event payload data
|
|
5
|
+
* @param config - The analytics configuration
|
|
6
|
+
* @param keepalive - Use keepalive mode for page unload scenarios (default: false)
|
|
7
|
+
* @returns A promise that resolves when the request is complete
|
|
8
|
+
*/
|
|
9
|
+
export declare const sendEvents: (payload: EventRequestBody, config: PipelineConfig, keepalive?: boolean) => Promise<boolean>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { PipelineConfig, EnrichedAnalyticsPayload, EnrichedTrackPayload } from '../models';
|
|
2
|
+
/**
|
|
3
|
+
* Analytics plugin for tracking page views and custom events in DotCMS applications.
|
|
4
|
+
* This plugin handles:
|
|
5
|
+
* 1. Event structuring (deciding between predefined and custom events)
|
|
6
|
+
* 2. Building complete request bodies
|
|
7
|
+
* 3. Sending analytics data to the DotCMS server
|
|
8
|
+
* 4. Managing initialization and queue management
|
|
9
|
+
*
|
|
10
|
+
* The enricher plugin runs BEFORE this plugin and adds page/utm/custom data.
|
|
11
|
+
* This plugin receives enriched payloads and structures them into proper events.
|
|
12
|
+
*
|
|
13
|
+
* @param {PipelineConfig} config - Configuration object containing API key, server URL,
|
|
14
|
+
* debug mode, auto page view settings, and queue config
|
|
15
|
+
* @returns {Object} Plugin object with methods for initialization and event tracking
|
|
16
|
+
*/
|
|
17
|
+
export declare const senderPlugin: (config: PipelineConfig) => {
|
|
18
|
+
name: string;
|
|
19
|
+
config: PipelineConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Initialize the plugin with optional queue management
|
|
22
|
+
*/
|
|
23
|
+
initialize: () => Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Track a page view event
|
|
26
|
+
* Receives enriched payload from the enricher plugin and structures it into a pageview event
|
|
27
|
+
*/
|
|
28
|
+
page: ({ payload }: {
|
|
29
|
+
payload: EnrichedAnalyticsPayload;
|
|
30
|
+
}) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Builds a content impression, content click or conversion from the enriched payload.
|
|
33
|
+
*
|
|
34
|
+
* - content_impression → extracts from properties, combines with enriched page data
|
|
35
|
+
* - content_click → extracts from properties, combines with enriched page data
|
|
36
|
+
* - conversion → its name and the page
|
|
37
|
+
*
|
|
38
|
+
* Those, with pageviews, are the only event types dotCMS accepts.
|
|
39
|
+
*/
|
|
40
|
+
track: ({ payload }: {
|
|
41
|
+
payload: EnrichedTrackPayload;
|
|
42
|
+
}) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Check if the plugin is loaded
|
|
45
|
+
*/
|
|
46
|
+
loaded: () => boolean;
|
|
47
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PipelineConfig, EventContext, DotCMSEvent } from '../models';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a queue manager for batching analytics events.
|
|
4
|
+
* Uses factory function pattern consistent with the plugin architecture.
|
|
5
|
+
*/
|
|
6
|
+
export declare const createEventQueue: (config: PipelineConfig) => {
|
|
7
|
+
/**
|
|
8
|
+
* Initialize the queue with smart batching
|
|
9
|
+
*/
|
|
10
|
+
initialize: () => void;
|
|
11
|
+
/**
|
|
12
|
+
* Add event to queue
|
|
13
|
+
* smartQueue handles all batching logic automatically:
|
|
14
|
+
* - Sends immediately when eventBatchSize reached (with throttle: false)
|
|
15
|
+
* - Sends pending events every flushInterval
|
|
16
|
+
*/
|
|
17
|
+
enqueue: (event: DotCMSEvent, context: EventContext) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Get queue size for debugging
|
|
20
|
+
* Returns the number of events in smartQueue
|
|
21
|
+
*/
|
|
22
|
+
size: () => number;
|
|
23
|
+
/**
|
|
24
|
+
* Clean up queue resources
|
|
25
|
+
* Flushes remaining events and cleans up listeners
|
|
26
|
+
*
|
|
27
|
+
* IMPORTANT: Does NOT clear sessionStorage
|
|
28
|
+
* - Storage is updated when sendBatch dispatches a batch, whether or not its request
|
|
29
|
+
* succeeds, and in initialize()
|
|
30
|
+
* - This allows events to persist across traditional page navigations
|
|
31
|
+
*/
|
|
32
|
+
cleanup: () => void;
|
|
33
|
+
};
|