@dotcms/analytics 1.1.1-next.1 → 1.1.1-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +220 -65
  2. package/lib/core/dot-content-analytics.d.ts +1 -1
  3. package/lib/core/dot-content-analytics.js +26 -24
  4. package/lib/core/plugin/dot-analytics.plugin.d.ts +3 -3
  5. package/lib/core/plugin/dot-analytics.plugin.js +25 -57
  6. package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.d.ts +11 -27
  7. package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.js +38 -15
  8. package/lib/core/plugin/identity/dot-analytics.identity.plugin.d.ts +11 -11
  9. package/lib/core/plugin/identity/dot-analytics.identity.plugin.js +13 -11
  10. package/lib/core/plugin/identity/dot-analytics.identity.utils.d.ts +7 -6
  11. package/lib/core/shared/{dot-content-analytics.constants.d.ts → constants/dot-content-analytics.constants.d.ts} +22 -5
  12. package/lib/core/shared/constants/dot-content-analytics.constants.js +28 -0
  13. package/lib/core/shared/constants/index.d.ts +4 -0
  14. package/lib/core/shared/dot-content-analytics.activity-tracker.d.ts +1 -1
  15. package/lib/core/shared/dot-content-analytics.activity-tracker.js +1 -1
  16. package/lib/core/shared/dot-content-analytics.http.d.ts +2 -2
  17. package/lib/core/shared/dot-content-analytics.http.js +10 -9
  18. package/lib/core/shared/dot-content-analytics.utils.d.ts +82 -44
  19. package/lib/core/shared/dot-content-analytics.utils.js +86 -73
  20. package/lib/core/shared/models/data.model.d.ts +101 -0
  21. package/lib/core/shared/models/event.model.d.ts +66 -0
  22. package/lib/core/shared/models/index.d.ts +12 -0
  23. package/lib/core/shared/models/library.model.d.ts +176 -0
  24. package/lib/core/shared/models/request.model.d.ts +24 -0
  25. package/lib/react/components/DotContentAnalytics.d.ts +1 -1
  26. package/lib/react/hook/useContentAnalytics.d.ts +43 -15
  27. package/lib/react/hook/useContentAnalytics.js +18 -21
  28. package/lib/react/hook/useRouterTracker.d.ts +1 -1
  29. package/lib/react/internal/utils.d.ts +1 -1
  30. package/lib/react/internal/utils.js +2 -2
  31. package/lib/react/public-api.d.ts +1 -1
  32. package/lib/standalone.d.ts +2 -2
  33. package/package.json +1 -1
  34. package/lib/core/shared/dot-content-analytics.constants.js +0 -14
  35. package/lib/core/shared/dot-content-analytics.model.d.ts +0 -351
package/README.md CHANGED
@@ -10,7 +10,7 @@ Lightweight JavaScript SDK for tracking content-aware events in dotCMS. Works in
10
10
  <script
11
11
  src="ca.min.js"
12
12
  data-analytics-server="https://demo.dotcms.com"
13
- data-analytics-auth="SITE_KEY"
13
+ data-analytics-auth="SITE_AUTH"
14
14
  data-analytics-auto-page-view="true"
15
15
  data-analytics-debug="false"></script>
16
16
  ```
@@ -25,14 +25,14 @@ npm install @dotcms/analytics
25
25
  import { initializeContentAnalytics } from '@dotcms/analytics';
26
26
 
27
27
  const analytics = initializeContentAnalytics({
28
- siteKey: 'SITE_KEY',
28
+ siteAuth: 'SITE_AUTH',
29
29
  server: 'https://demo.dotcms.com'
30
30
  });
31
31
 
32
32
  analytics.track('page-loaded');
33
33
  ```
34
34
 
35
- ### React
35
+ ### React (In Development)
36
36
 
37
37
  ```bash
38
38
  npm install @dotcms/analytics
@@ -42,7 +42,7 @@ npm install @dotcms/analytics
42
42
  import { DotContentAnalytics } from '@dotcms/analytics/react';
43
43
 
44
44
  const config = {
45
- siteKey: 'SITE_KEY',
45
+ siteAuth: 'SITE_AUTH',
46
46
  server: 'https://demo.dotcms.com',
47
47
  autoPageView: true // Optional, default is true in React
48
48
  };
@@ -52,16 +52,48 @@ export function AppRoot() {
52
52
  }
53
53
  ```
54
54
 
55
+ > **Note:** React API is subject to change during development.
56
+
55
57
  ## 📘 Core Concepts
56
58
 
57
- ### Events
59
+ ### Page Views
58
60
 
59
- Track any user action as an event using `track('event-name', { payload })`.
61
+ The `pageView()` method tracks page navigation events. **It automatically enriches the event with comprehensive data**, including:
60
62
 
61
- ### Page Views
63
+ - **Page data**: URL, title, referrer, path, protocol, search params, etc.
64
+ - **Device data**: Screen resolution, viewport size, language, user agent
65
+ - **UTM parameters**: Campaign tracking data (source, medium, campaign, etc.)
66
+ - **Context**: Site key, session ID, user ID, timestamp
67
+
68
+ You can optionally include custom data that will be sent **in addition** to all the automatic enrichment.
69
+
70
+ **Method signature:**
71
+
72
+ ```typescript
73
+ pageView(customData?: Record<string, unknown>): void
74
+ ```
75
+
76
+ **Behavior:**
77
+
78
+ - **Standalone (IIFE)**: Auto-tracked only if `data-analytics-auto-page-view="true"`; otherwise call `window.dotAnalytics.pageView()` manually.
79
+ - **React**: In development (API may change)
80
+ - Custom data is optional and gets attached to the pageview event under the `custom` property alongside all automatically captured data.
81
+
82
+ ### Custom Events
83
+
84
+ The `track()` method allows you to track any custom user action with a unique event name and optional properties.
85
+
86
+ **Method signature:**
87
+
88
+ ```typescript
89
+ track(eventName: string, properties?: Record<string, unknown>): void
90
+ ```
62
91
 
63
- - React: Automatically tracked on route changes when using `DotContentAnalytics`.
64
- - Standalone: Auto-tracked only if `data-analytics-auto-page-view="true"`; otherwise call `window.dotAnalytics.pageView()`.
92
+ **Important:**
93
+
94
+ - `eventName` cannot be `"pageview"` (reserved for page view tracking)
95
+ - `eventName` should be a descriptive string like `"button-click"`, `"form-submit"`, `"video-play"`, etc.
96
+ - `properties` is optional and can contain any custom data relevant to the event
65
97
 
66
98
  ### Sessions
67
99
 
@@ -76,106 +108,229 @@ Track any user action as an event using `track('event-name', { payload })`.
76
108
 
77
109
  ## ⚙️ Configuration Options
78
110
 
79
- | Option | Type | Required | Default | Description |
111
+ <<<<<<< HEAD
112
+ | Option | Type | Required | Default | Description |
80
113
  | -------------- | --------- | -------- | ----------------------------------- | -------------------------------------- |
81
- | `siteKey` | `string` | ✅ | - | Site key from dotCMS Analytics app |
82
- | `server` | `string` | ✅ | - | Your dotCMS server URL |
83
- | `debug` | `boolean` | ❌ | `false` | Enable verbose logging |
84
- | `autoPageView` | `boolean` | ❌ | React: `true` / Standalone: `false` | Auto track page views on route changes |
114
+ | `siteAuth` | `string` | ✅ | - | Site auth from dotCMS Analytics app |
115
+ | `server` | `string` | ✅ | - | Your dotCMS server URL |
116
+ | `debug` | `boolean` | ❌ | `false` | Enable verbose logging |
117
+ | `autoPageView` | `boolean` | ❌ | React: `true` / Standalone: `false` | Auto track page views on route changes |
85
118
 
86
119
  ## 🛠️ Usage Examples
87
120
 
88
121
  ### Vanilla JavaScript
89
122
 
90
- **Manual Page View & Events**
123
+ **Basic Page View**
91
124
 
92
125
  ```javascript
93
- // After init with the <script> tag the dotAnalytics is added to the window.
94
- window.dotAnalytics.track('cta-click', { button: 'Buy Now' });
126
+ // After init with the <script> tag, dotAnalytics is added to the window
127
+ // Automatically captures: page, device, UTM, context (session, user, site)
95
128
  window.dotAnalytics.pageView();
96
129
  ```
97
130
 
131
+ **Page View with Additional Custom Data**
132
+
133
+ ```javascript
134
+ // All automatic data (page, device, UTM, context) is STILL captured
135
+ // Plus your custom properties are added under 'custom'
136
+ window.dotAnalytics.pageView({
137
+ contentType: 'blog',
138
+ category: 'technology',
139
+ author: 'john-doe',
140
+ wordCount: 1500
141
+ });
142
+
143
+ // The server receives: page + device + utm + context + custom (your data)
144
+ ```
145
+
146
+ **Track Custom Events**
147
+
148
+ ```javascript
149
+ // Basic event tracking
150
+ window.dotAnalytics.track('cta-click', {
151
+ button: 'Buy Now',
152
+ location: 'hero-section'
153
+ });
154
+
155
+ // Track form submission
156
+ window.dotAnalytics.track('form-submit', {
157
+ formName: 'contact-form',
158
+ formType: 'lead-gen'
159
+ });
160
+
161
+ // Track video interaction
162
+ window.dotAnalytics.track('video-play', {
163
+ videoId: 'intro-video',
164
+ duration: 120,
165
+ autoplay: false
166
+ });
167
+ ```
168
+
98
169
  **Advanced: Manual Init with Custom Properties**
99
170
 
100
171
  ```javascript
101
172
  const analytics = initializeContentAnalytics({
102
- siteKey: 'abc123',
173
+ siteAuth: 'abc123',
103
174
  server: 'https://your-dotcms.com',
104
175
  debug: true,
105
176
  autoPageView: false
106
177
  });
107
178
 
108
- analytics.track('custom-event', {
109
- category: 'Marketing',
110
- value: 'Banner Clicked'
179
+ // Track custom events with properties
180
+ analytics.track('product-view', {
181
+ productId: 'SKU-12345',
182
+ category: 'Electronics',
183
+ price: 299.99,
184
+ inStock: true
111
185
  });
112
186
 
113
- analytics.pageView();
187
+ // Manual page view with custom data
188
+ // Automatic enrichment (page, device, UTM, context) + your custom data
189
+ analytics.pageView({
190
+ section: 'checkout',
191
+ step: 'payment',
192
+ cartValue: 299.99
193
+ });
114
194
  ```
115
195
 
116
196
  ### React
117
197
 
118
- **Track Events**
198
+ > **Note:** React integration is currently in development. The API may change.
199
+
200
+ **Basic Setup**
119
201
 
120
202
  ```tsx
121
- import { useContentAnalytics } from '@dotcms/analytics/react';
203
+ import { DotContentAnalytics } from '@dotcms/analytics/react';
122
204
 
123
- const { track } = useContentAnalytics({
124
- siteKey: 'SITE_KEY',
125
- server: 'https://demo.dotcms.com'
126
- });
205
+ const config = {
206
+ siteAuth: 'SITE_KEY',
207
+ server: 'https://demo.dotcms.com',
208
+ autoPageView: true
209
+ };
127
210
 
128
- track('cta-click', { label: 'Download PDF' });
211
+ export function AppRoot() {
212
+ return <DotContentAnalytics config={config} />;
213
+ }
129
214
  ```
130
215
 
131
- **Manual Page View**
216
+ **Using the Hook**
132
217
 
133
218
  ```tsx
134
219
  import { useContentAnalytics } from '@dotcms/analytics/react';
135
220
 
136
- const { pageView } = useContentAnalytics({
137
- siteKey: 'SITE_KEY',
138
- server: 'https://demo.dotcms.com'
139
- });
140
- useEffect(() => {
141
- pageView();
142
- }, []);
143
- ```
144
-
145
- **Advanced: Manual Tracking with Router**
221
+ function MyComponent() {
222
+ const { track, pageView } = useContentAnalytics({
223
+ siteAuth: 'SITE_AUTH',
224
+ server: 'https://demo.dotcms.com'
225
+ });
146
226
 
147
- ```tsx
148
- // Next.js App Router is automatically tracked by <DotContentAnalytics />
149
- // For other routers, you can call pageView on location change
150
- import { useLocation } from 'react-router-dom';
151
- import { useContentAnalytics } from '@dotcms/analytics/react';
227
+ // Track custom events (same API as vanilla JS)
228
+ const handleClick = () => {
229
+ track('button-click', { label: 'CTA Button' });
230
+ };
152
231
 
153
- const { pageView } = useContentAnalytics({
154
- siteKey: 'SITE_KEY',
155
- server: 'https://demo.dotcms.com'
156
- });
157
- const location = useLocation();
158
-
159
- useEffect(() => {
160
- pageView();
161
- }, [location]);
232
+ return <button onClick={handleClick}>Click Me</button>;
233
+ }
162
234
  ```
163
235
 
164
236
  ## API Reference
165
237
 
166
238
  ```typescript
167
239
  interface DotCMSAnalytics {
168
- track: (eventName: string, payload?: Record<string, unknown>) => void;
169
- pageView: () => void;
240
+ /**
241
+ * Track a page view event with optional custom data
242
+ * @param customData - Optional object with custom properties to attach to the pageview
243
+ */
244
+ pageView: (customData?: Record<string, unknown>) => void;
245
+
246
+ /**
247
+ * Track a custom event
248
+ * @param eventName - Name of the custom event (cannot be "pageview")
249
+ * @param properties - Optional object with event-specific properties
250
+ */
251
+ track: (eventName: string, properties?: Record<string, unknown>) => void;
252
+ }
253
+ ```
254
+
255
+ ### Page View Event Structure
256
+
257
+ When you call `pageView(customData?)`, the SDK **automatically enriches** the event with comprehensive data and sends:
258
+
259
+ ```typescript
260
+ {
261
+ context: { // 🤖 AUTOMATIC - Identity & Session
262
+ site_key: string; // Your site key
263
+ session_id: string; // Current session ID
264
+ user_id: string; // Anonymous user ID
265
+ },
266
+ events: [{
267
+ event_type: "pageview",
268
+ local_time: string, // 🤖 AUTOMATIC - ISO 8601 timestamp with timezone
269
+ data: {
270
+ page: { // 🤖 AUTOMATIC - Page Information
271
+ url: string; // Full URL
272
+ title: string; // Page title
273
+ referrer: string; // Referrer URL
274
+ path: string; // Path
275
+ doc_host: string; // Hostname
276
+ doc_protocol: string; // Protocol (http/https)
277
+ doc_search: string; // Query string
278
+ doc_hash: string; // URL hash
279
+ doc_encoding: string; // Character encoding
280
+ },
281
+ device: { // 🤖 AUTOMATIC - Device & Browser Info
282
+ screen_resolution: string; // Screen size
283
+ language: string; // Browser language
284
+ viewport_width: string; // Viewport width
285
+ viewport_height: string; // Viewport height
286
+ },
287
+ utm?: { // 🤖 AUTOMATIC - Campaign Tracking (if present in URL)
288
+ source: string; // utm_source
289
+ medium: string; // utm_medium
290
+ campaign: string; // utm_campaign
291
+ term: string; // utm_term
292
+ content: string; // utm_content
293
+ },
294
+ custom?: { // 👤 YOUR DATA (optional)
295
+ // Any custom properties you pass to pageView(customData)
296
+ contentType?: string;
297
+ category?: string;
298
+ author?: string;
299
+ // ... any other properties
300
+ }
301
+ }
302
+ }]
170
303
  }
171
304
  ```
172
305
 
173
- **Enriched AnalyticsEvent includes:**
306
+ **Key Points:**
307
+
308
+ - 🤖 Most data is captured **automatically** - you don't need to provide it
309
+ - 👤 `custom` is where **your optional data** goes
310
+ - All automatic data is always captured, even if you don't pass `customData`
311
+
312
+ ### Custom Event Structure
174
313
 
175
- - `context`: siteKey, sessionId, userId
176
- - `page`: URL, title, referrer, path
177
- - `device`: screen size, language, viewport
178
- - `utm`: source, medium, campaign, term, etc.
314
+ When you call `track(eventName, properties)`, the following structure is sent:
315
+
316
+ ```typescript
317
+ {
318
+ context: {
319
+ site_key: string; // Your site key
320
+ session_id: string; // Current session ID
321
+ user_id: string; // Anonymous user ID
322
+ },
323
+ events: [{
324
+ event_type: string, // Your custom event name
325
+ local_time: string, // ISO 8601 timestamp
326
+ data: {
327
+ custom: {
328
+ // Your properties object
329
+ }
330
+ }
331
+ }]
332
+ }
333
+ ```
179
334
 
180
335
  ## Under the Hood
181
336
 
@@ -215,23 +370,23 @@ Standalone attributes to verify:
215
370
 
216
371
  ## dotCMS Support
217
372
 
218
- We offer multiple channels to get help with the dotCMS React SDK:
373
+ We offer multiple channels to get help with the dotCMS Analytics SDK:
219
374
 
220
375
  - **GitHub Issues**: For bug reports and feature requests, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository.
221
376
  - **Community Forum**: Join our [community discussions](https://community.dotcms.com/) to ask questions and share solutions.
222
- - **Stack Overflow**: Use the tag `dotcms-react` when posting questions.
377
+ - **Stack Overflow**: Use the tag `dotcms-analytics` when posting questions.
223
378
  - **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://helpdesk.dotcms.com/support/).
224
379
 
225
380
  When reporting issues, please include:
226
381
 
227
382
  - SDK version you're using
228
- - React version
383
+ - Framework/library version (if applicable)
229
384
  - Minimal reproduction steps
230
385
  - Expected vs. actual behavior
231
386
 
232
387
  ## How To Contribute
233
388
 
234
- GitHub pull requests are the preferred method to contribute code to dotCMS. We welcome contributions to the DotCMS UVE SDK! If you'd like to contribute, please follow these steps:
389
+ GitHub pull requests are the preferred method to contribute code to dotCMS. We welcome contributions to the DotCMS Analytics SDK! If you'd like to contribute, please follow these steps:
235
390
 
236
391
  1. Fork the repository [dotCMS/core](https://github.com/dotCMS/core)
237
392
  2. Create a feature branch (`git checkout -b feature/amazing-feature`)
@@ -1,4 +1,4 @@
1
- import { DotCMSAnalytics, DotCMSAnalyticsConfig } from './shared/dot-content-analytics.model';
1
+ import { DotCMSAnalytics, DotCMSAnalyticsConfig } from './shared/models';
2
2
  /**
3
3
  * Creates an analytics instance for content analytics tracking.
4
4
  *
@@ -1,40 +1,42 @@
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";
1
+ import { Analytics as o } from "analytics";
2
+ import { dotAnalytics as s } from "./plugin/dot-analytics.plugin.js";
3
+ import { dotAnalyticsEnricherPlugin as l } from "./plugin/enricher/dot-analytics.enricher.plugin.js";
4
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({
5
+ import { cleanupActivityTracking as a } from "./shared/dot-content-analytics.activity-tracker.js";
6
+ const f = (i) => {
7
+ if (!i.siteAuth)
8
+ return console.error('DotCMS Analytics: Missing "siteAuth" in configuration'), null;
9
+ if (!i.server)
10
+ return console.error('DotCMS Analytics: Missing "server" in configuration'), null;
11
+ const t = o({
12
12
  app: "dotAnalytics",
13
- debug: n.debug,
13
+ debug: i.debug,
14
14
  plugins: [
15
- u(n),
15
+ u(i),
16
16
  // Inject identity context (user_id, session_id, local_tz)
17
- a(),
18
- // Enrich with page, device, utm data
19
- l(n)
17
+ l(),
18
+ // Enrich and clean payload with page, device, utm data and custom data
19
+ s(i)
20
20
  // Send events to server
21
21
  ]
22
- }), e = () => c();
23
- return typeof window < "u" && (window.addEventListener("beforeunload", e), window.__dotAnalyticsCleanup = e), {
22
+ }), r = () => a();
23
+ return typeof window < "u" && (window.addEventListener("beforeunload", r), window.__dotAnalyticsCleanup = r), {
24
24
  /**
25
25
  * Track a page view.
26
- * @param {Record<string, unknown>} payload - The payload to track.
26
+ * Session activity is automatically updated by the identity plugin.
27
+ * @param payload - Optional custom data to include with the page view (any valid JSON object)
27
28
  */
28
- pageView: (i = {}) => {
29
- o(), t == null || t.page(i);
29
+ pageView: (n = {}) => {
30
+ t == null || t.page(n);
30
31
  },
31
32
  /**
32
33
  * Track a custom event.
33
- * @param {string} eventName - The name of the event to track.
34
- * @param {Record<string, unknown>} payload - The payload to track.
34
+ * Session activity is automatically updated by the identity plugin.
35
+ * @param eventName - The name of the event to track
36
+ * @param payload - Custom data to include with the event (any valid JSON object)
35
37
  */
36
- track: (i, r = {}) => {
37
- o(), t == null || t.track(i, r);
38
+ track: (n, e = {}) => {
39
+ t == null || t.track(n, e);
38
40
  }
39
41
  };
40
42
  };
@@ -1,4 +1,4 @@
1
- import { DotCMSAnalyticsConfig, DotCMSAnalyticsParams } from '../shared/dot-content-analytics.model';
1
+ import { DotCMSAnalyticsConfig, DotCMSAnalyticsParams } from '../shared/models';
2
2
  /**
3
3
  * Analytics plugin for tracking page views and custom events in DotCMS applications.
4
4
  * This plugin handles sending analytics data to the DotCMS server, managing initialization,
@@ -17,12 +17,12 @@ export declare const dotAnalytics: (config: DotCMSAnalyticsConfig) => {
17
17
  initialize: () => Promise<void>;
18
18
  /**
19
19
  * Track a page view event
20
- * Takes enriched data from properties and creates final structured event
20
+ * The enricher plugin has already built the complete request body
21
21
  */
22
22
  page: (params: DotCMSAnalyticsParams) => Promise<void>;
23
23
  /**
24
24
  * Track a custom event
25
- * Takes enriched data and sends it to the analytics server
25
+ * The enricher plugin has already built the complete request body
26
26
  */
27
27
  track: (params: DotCMSAnalyticsParams) => Promise<void>;
28
28
  /**
@@ -1,79 +1,47 @@
1
- import { EVENT_TYPES as y } from "../shared/dot-content-analytics.constants.js";
2
- import { sendAnalyticsEventToServer as c } from "../shared/dot-content-analytics.http.js";
3
- const p = (v) => {
4
- let r = !1;
1
+ import { sendAnalyticsEventToServer as r } from "../shared/dot-content-analytics.http.js";
2
+ const s = (a) => {
3
+ let n = !1;
5
4
  return {
6
5
  name: "dot-analytics",
7
- config: v,
6
+ config: a,
8
7
  /**
9
8
  * Initialize the plugin
10
9
  */
11
- initialize: () => (r = !0, Promise.resolve()),
10
+ initialize: () => (n = !0, Promise.resolve()),
12
11
  /**
13
12
  * Track a page view event
14
- * Takes enriched data from properties and creates final structured event
13
+ * The enricher plugin has already built the complete request body
15
14
  */
16
- page: (a) => {
17
- const { config: t, payload: e } = a, { context: n, page: o, device: i, utm: s, local_time: l } = e;
18
- if (!r)
19
- throw new Error("DotAnalytics: Plugin not initialized");
20
- if (!n || !o || !i || !l)
21
- throw new Error("DotAnalytics: Missing required payload data for pageview event");
22
- const d = {
23
- context: n,
24
- events: [
25
- {
26
- event_type: y.PAGEVIEW,
27
- local_time: l,
28
- data: {
29
- page: o,
30
- device: i,
31
- ...s && { utm: s }
32
- }
33
- }
34
- ]
15
+ page: (e) => {
16
+ const { config: o, payload: t } = e;
17
+ if (!n)
18
+ throw new Error("DotCMS Analytics: Plugin not initialized");
19
+ const i = {
20
+ context: t.context,
21
+ events: t.events
35
22
  };
36
- return t.debug && console.warn("DotAnalytics: Pageview event to send:", d), c(d, t);
23
+ return r(i, o);
37
24
  },
38
- // TODO: Fix this when we haver the final design for the track event
39
25
  /**
40
26
  * Track a custom event
41
- * Takes enriched data and sends it to the analytics server
27
+ * The enricher plugin has already built the complete request body
42
28
  */
43
- track: (a) => {
44
- const { config: t, payload: e } = a;
45
- if (!r)
46
- throw new Error("DotAnalytics: Plugin not initialized");
47
- if ("events" in e && Array.isArray(e.events)) {
48
- const o = e, i = {
49
- context: o.context,
50
- events: o.events
51
- };
52
- return t.debug && console.warn("DotAnalytics: Track event to send:", i), c(i, t);
53
- }
54
- if (!e.context || !e.local_time)
55
- throw new Error("DotAnalytics: Missing required payload data for track event");
56
- const n = {
57
- context: e.context,
58
- events: [
59
- {
60
- event_type: y.TRACK,
61
- local_time: e.local_time,
62
- data: {
63
- event: e.event,
64
- ...e.properties
65
- }
66
- }
67
- ]
29
+ track: (e) => {
30
+ const { config: o, payload: t } = e;
31
+ if (!n)
32
+ throw new Error("DotCMS Analytics: Plugin not initialized");
33
+ const i = {
34
+ context: t.context,
35
+ events: t.events
68
36
  };
69
- return t.debug && console.warn("DotAnalytics: Track event to send (fallback):", n), c(n, t);
37
+ return r(i, o);
70
38
  },
71
39
  /**
72
40
  * Check if the plugin is loaded
73
41
  */
74
- loaded: () => r
42
+ loaded: () => n
75
43
  };
76
44
  };
77
45
  export {
78
- p as dotAnalytics
46
+ s as dotAnalytics
79
47
  };
@@ -1,44 +1,28 @@
1
- import { DotCMSAnalyticsPayload } from '../../shared/dot-content-analytics.model';
1
+ import { AnalyticsBasePayloadWithContext, AnalyticsTrackPayloadWithContext, DotCMSAnalyticsRequestBody } from '../../shared/models';
2
2
  /**
3
3
  * Plugin that enriches the analytics payload data based on the event type.
4
4
  * Uses Analytics.js lifecycle events to inject context before processing.
5
- * The identity plugin runs FIRST to inject context: { session_id, site_key, user_id }
5
+ * The identity plugin runs FIRST to inject context: { session_id, site_auth, user_id }
6
6
  * This enricher plugin runs SECOND to add page/device/utm data.
7
7
  *
8
- * OPTIMIZED: Uses existing payload.properties data to avoid duplication
8
+ * Returns the final request body structure ready to send to the server.
9
9
  */
10
10
  export declare const dotAnalyticsEnricherPlugin: () => {
11
11
  name: string;
12
12
  /**
13
13
  * PAGE VIEW ENRICHMENT - Runs after identity context injection
14
- * Uses optimized enrichment that leverages analytics.js payload data
14
+ * Returns the complete request body for pageview events
15
+ * @returns {DotCMSAnalyticsRequestBody} Complete request body ready to send
15
16
  */
16
17
  'page:dot-analytics': ({ payload }: {
17
- payload: DotCMSAnalyticsPayload;
18
- }) => {
19
- local_time: string;
20
- utm?: import('../../shared/dot-content-analytics.model').DotCMSUtmData;
21
- page: import('../../shared/dot-content-analytics.model').DotCMSPageData;
22
- device: import('../../shared/dot-content-analytics.model').DotCMSDeviceData;
23
- event: string;
24
- properties: Record<string, unknown>;
25
- options: Record<string, unknown>;
26
- context?: import('../../shared/dot-content-analytics.model').DotCMSAnalyticsContext;
27
- };
18
+ payload: AnalyticsBasePayloadWithContext;
19
+ }) => DotCMSAnalyticsRequestBody;
28
20
  /**
29
21
  * TRACK EVENT ENRICHMENT - Runs after identity context injection
30
- * Creates structured track events with pre-injected context
22
+ * Returns the complete request body for custom events
23
+ * @returns {DotCMSAnalyticsRequestBody} Complete request body ready to send
31
24
  */
32
25
  'track:dot-analytics': ({ payload }: {
33
- payload: DotCMSAnalyticsPayload;
34
- }) => {
35
- events: {
36
- event_type: "track";
37
- local_time: string;
38
- data: {
39
- src: string;
40
- event: string;
41
- };
42
- }[];
43
- };
26
+ payload: AnalyticsTrackPayloadWithContext;
27
+ }) => DotCMSAnalyticsRequestBody;
44
28
  };