@dotcms/analytics 1.2.0-next.4 → 1.2.0-next.6

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,7 +1,6 @@
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 { DotCMSCustomEventType } from '../constants';
5
4
  /**
6
5
  * Configuration for event queue management.
7
6
  * Controls how events are batched before sending to the server.
@@ -12,6 +11,37 @@ export interface QueueConfig {
12
11
  /** Time in milliseconds between flushes - sends pending events (default: 5000) */
13
12
  flushInterval?: number;
14
13
  }
14
+ /**
15
+ * Configuration for content impression tracking.
16
+ * Controls how content visibility is detected and tracked.
17
+ */
18
+ export interface ImpressionConfig {
19
+ /** Minimum percentage of element visible (0.0 to 1.0) - default: 0.5 */
20
+ visibilityThreshold?: number;
21
+ /** Minimum time in milliseconds element must be visible - default: 750 */
22
+ dwellMs?: number;
23
+ /** Maximum number of elements to track (performance limit) - default: 1000 */
24
+ maxNodes?: number;
25
+ /** Throttle time in milliseconds for intersection callbacks - default: 100 */
26
+ throttleMs?: number;
27
+ }
28
+ /**
29
+ * Interface for contentlet data extracted from DOM elements
30
+ */
31
+ export interface ContentletData {
32
+ identifier: string;
33
+ inode: string;
34
+ contentType: string;
35
+ title: string;
36
+ baseType: string;
37
+ }
38
+ /**
39
+ * Interface for viewport metrics
40
+ */
41
+ export interface ViewportMetrics {
42
+ offsetPercentage: number;
43
+ visibilityRatio: number;
44
+ }
15
45
  /**
16
46
  * Main interface for the DotCMS Analytics SDK.
17
47
  * Provides the core methods for tracking page views and custom events.
@@ -57,15 +87,22 @@ export interface DotCMSAnalyticsConfig {
57
87
  * - `QueueConfig`: Enable queuing with custom settings
58
88
  */
59
89
  queue?: QueueConfig | boolean;
90
+ /**
91
+ * Content impression tracking configuration:
92
+ * - `undefined` or `false` (default): Impression tracking disabled
93
+ * - `true`: Enable with default settings (threshold: 0.5, dwell: 750ms, maxNodes: 1000)
94
+ * - `ImpressionConfig`: Enable with custom settings
95
+ */
96
+ impressions?: ImpressionConfig | boolean;
60
97
  }
61
98
  /**
62
99
  * Track event payload with context.
63
- * This is the payload for custom track events after the identity plugin adds context.
100
+ * This is the payload for track events after the identity plugin adds context.
64
101
  * Used in the track:dot-analytics enricher plugin.
65
102
  */
66
103
  export interface AnalyticsTrackPayloadWithContext extends AnalyticsBasePayload {
67
- /** The custom event name (any string except 'pageview') */
68
- event: DotCMSCustomEventType;
104
+ /** The event name (can be predefined or custom) */
105
+ event: string;
69
106
  /** Analytics context added by identity plugin */
70
107
  context: DotCMSAnalyticsEventContext;
71
108
  }
@@ -84,29 +121,16 @@ type AnalyticsBasePayloadType = 'page' | 'track';
84
121
  * Analytics.js hook parameter types for DotCMS.
85
122
  * Represents the payload structure used by Analytics.js lifecycle hooks
86
123
  * for intercepting and modifying analytics events.
124
+ *
125
+ * Properties are flexible (Record<string, unknown>) to support both:
126
+ * - Page events: with page-specific fields (title, url, path, etc.)
127
+ * - Track events: with any custom event data structure
87
128
  */
88
129
  export interface AnalyticsBasePayload {
89
130
  /** The type of analytics event */
90
131
  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
- };
132
+ /** Properties associated with the event (flexible structure) */
133
+ properties: Record<string, unknown>;
110
134
  /** Configuration options for the event */
111
135
  options: Record<string, unknown>;
112
136
  /** User identifier */
@@ -146,6 +170,17 @@ export type EnrichedAnalyticsPayload = AnalyticsBasePayloadWithContext & {
146
170
  /** Local timestamp when the event occurred */
147
171
  local_time: string;
148
172
  };
173
+ /**
174
+ * Enriched track event payload with fields added to root based on event type.
175
+ * Used by the enricher plugin for track events.
176
+ */
177
+ export interface EnrichedTrackPayload extends AnalyticsTrackPayloadWithContext {
178
+ local_time: string;
179
+ page?: DotCMSContentImpressionPageData | DotCMSEventPageData;
180
+ content?: DotCMSContentImpressionPayload['content'];
181
+ position?: DotCMSContentImpressionPayload['position'];
182
+ utm?: DotCMSEventUtmData;
183
+ }
149
184
  /**
150
185
  * Analytics.js instance structure for DotCMS.
151
186
  * Represents the internal structure of an Analytics.js instance,
@@ -1,24 +1,32 @@
1
1
  import { DotCMSAnalyticsEventContext } from './data.model';
2
- import { DotCMSCustomEvent, DotCMSEvent, DotCMSPageViewEvent } from './event.model';
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<T extends DotCMSEvent> {
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: T[];
14
+ events: DotCMSEvent[];
12
15
  }
13
16
  /**
14
- * Specific request body type for PageView events
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 DotCMSPageViewRequestBody = DotCMSRequestBody<DotCMSPageViewEvent>;
20
+ export type DotCMSAnalyticsRequestBody = DotCMSRequestBody;
17
21
  /**
18
- * Specific request body type for Custom events
22
+ * Specific request body type for PageView events (for type documentation)
19
23
  */
20
- export type DotCMSCustomEventRequestBody = DotCMSRequestBody<DotCMSCustomEvent>;
24
+ export type DotCMSPageViewRequestBody = DotCMSRequestBody;
21
25
  /**
22
- * Union type for all possible request bodies
26
+ * Specific request body type for ContentImpression events (for type documentation)
23
27
  */
24
- export type DotCMSAnalyticsRequestBody = DotCMSPageViewRequestBody | DotCMSCustomEventRequestBody;
28
+ export type DotCMSContentImpressionRequestBody = DotCMSRequestBody;
29
+ /**
30
+ * Specific request body type for Custom events (for type documentation)
31
+ */
32
+ export type DotCMSCustomEventRequestBody = DotCMSRequestBody;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/analytics",
3
- "version": "1.2.0-next.4",
3
+ "version": "1.2.0-next.6",
4
4
  "description": "Official JavaScript library for Content Analytics with DotCMS.",
5
5
  "repository": {
6
6
  "type": "git",