@dotcms/analytics 1.1.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.
Files changed (64) hide show
  1. package/README.md +475 -72
  2. package/lib/core/{dot-content-analytics.d.ts → dot-analytics.content.d.ts} +8 -1
  3. package/lib/core/dot-analytics.content.js +63 -0
  4. package/lib/core/plugin/click/dot-analytics.click-tracker.d.ts +108 -0
  5. package/lib/core/plugin/click/dot-analytics.click-tracker.js +144 -0
  6. package/lib/core/plugin/click/dot-analytics.click.plugin.d.ts +36 -0
  7. package/lib/core/plugin/click/dot-analytics.click.plugin.js +27 -0
  8. package/lib/core/plugin/click/dot-analytics.click.utils.d.ts +12 -0
  9. package/lib/core/plugin/click/dot-analytics.click.utils.js +55 -0
  10. package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.d.ts +18 -30
  11. package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.js +30 -20
  12. package/lib/core/plugin/identity/dot-analytics.identity.activity-tracker.d.ts +20 -0
  13. package/lib/core/{shared/dot-content-analytics.activity-tracker.js → plugin/identity/dot-analytics.identity.activity-tracker.js} +19 -38
  14. package/lib/core/plugin/identity/dot-analytics.identity.plugin.d.ts +13 -31
  15. package/lib/core/plugin/identity/dot-analytics.identity.plugin.js +14 -12
  16. package/lib/core/plugin/identity/dot-analytics.identity.utils.d.ts +7 -22
  17. package/lib/core/plugin/impression/dot-analytics.impression-tracker.d.ts +62 -0
  18. package/lib/core/plugin/impression/dot-analytics.impression-tracker.js +200 -0
  19. package/lib/core/plugin/impression/dot-analytics.impression.plugin.d.ts +40 -0
  20. package/lib/core/plugin/impression/dot-analytics.impression.plugin.js +27 -0
  21. package/lib/core/plugin/impression/dot-analytics.impression.utils.d.ts +26 -0
  22. package/lib/core/plugin/impression/dot-analytics.impression.utils.js +27 -0
  23. package/lib/core/plugin/impression/index.d.ts +2 -0
  24. package/lib/core/plugin/main/dot-analytics.plugin.d.ts +46 -0
  25. package/lib/core/plugin/main/dot-analytics.plugin.js +114 -0
  26. package/lib/core/shared/constants/dot-analytics.constants.d.ts +131 -0
  27. package/lib/core/shared/constants/dot-analytics.constants.js +52 -0
  28. package/lib/core/shared/constants/index.d.ts +4 -0
  29. package/lib/core/shared/dot-analytics.logger.d.ts +85 -0
  30. package/lib/core/shared/dot-analytics.logger.js +90 -0
  31. package/lib/core/shared/http/dot-analytics.http.d.ts +9 -0
  32. package/lib/core/shared/http/dot-analytics.http.js +34 -0
  33. package/lib/core/shared/models/data.model.d.ts +141 -0
  34. package/lib/core/shared/models/event.model.d.ts +135 -0
  35. package/lib/core/shared/models/index.d.ts +7 -0
  36. package/lib/core/shared/models/library.model.d.ts +243 -0
  37. package/lib/core/shared/models/request.model.d.ts +32 -0
  38. package/lib/core/shared/queue/dot-analytics.queue.utils.d.ts +28 -0
  39. package/lib/core/shared/queue/dot-analytics.queue.utils.js +80 -0
  40. package/lib/core/shared/queue/index.d.ts +1 -0
  41. package/lib/core/shared/utils/dot-analytics.utils.d.ts +260 -0
  42. package/lib/core/shared/utils/dot-analytics.utils.js +202 -0
  43. package/lib/react/components/DotContentAnalytics.d.ts +1 -1
  44. package/lib/react/hook/useContentAnalytics.d.ts +43 -15
  45. package/lib/react/hook/useContentAnalytics.js +18 -21
  46. package/lib/react/hook/useRouterTracker.d.ts +1 -1
  47. package/lib/react/hook/useRouterTracker.js +4 -4
  48. package/lib/react/internal/utils.d.ts +1 -1
  49. package/lib/react/internal/utils.js +3 -3
  50. package/lib/react/public-api.d.ts +1 -1
  51. package/lib/standalone.d.ts +2 -2
  52. package/package.json +7 -5
  53. package/uve/src/internal/constants.js +8 -3
  54. package/lib/core/dot-content-analytics.js +0 -43
  55. package/lib/core/plugin/dot-analytics.plugin.d.ts +0 -32
  56. package/lib/core/plugin/dot-analytics.plugin.js +0 -79
  57. package/lib/core/shared/dot-content-analytics.activity-tracker.d.ts +0 -28
  58. package/lib/core/shared/dot-content-analytics.constants.d.ts +0 -37
  59. package/lib/core/shared/dot-content-analytics.constants.js +0 -14
  60. package/lib/core/shared/dot-content-analytics.http.d.ts +0 -8
  61. package/lib/core/shared/dot-content-analytics.http.js +0 -29
  62. package/lib/core/shared/dot-content-analytics.model.d.ts +0 -351
  63. package/lib/core/shared/dot-content-analytics.utils.d.ts +0 -111
  64. package/lib/core/shared/dot-content-analytics.utils.js +0 -123
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:**
62
77
 
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()`.
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
+ ```
91
+
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,477 @@ 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 |
80
- | -------------- | --------- | -------- | ----------------------------------- | -------------------------------------- |
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 |
111
+ | Option | Type | Required | Default | Description |
112
+ | -------------- | --------------------------- | -------- | ----------------------------------- | ---------------------------------------------------------------- |
113
+ | `siteAuth` | `string` | ✅ | - | Site auth from dotCMS Analytics app |
114
+ | `server` | `string` | ✅ | - | Your dotCMS server URL |
115
+ | `debug` | `boolean` | ❌ | `false` | Enable verbose logging |
116
+ | `autoPageView` | `boolean` | ❌ | React: `true` / Standalone: `false` | Auto track page views on route changes |
117
+ | `queueConfig` | `QueueConfig` | ❌ | See below | Event batching configuration |
118
+ | `impressions` | `ImpressionConfig\|boolean` | ❌ | `false` | Content impression tracking (disabled by default) |
119
+ | `clicks` | `boolean` | ❌ | `false` | Content click tracking with 300ms throttle (disabled by default) |
120
+
121
+ ### Queue Configuration
122
+
123
+ The `queueConfig` option controls event batching:
124
+
125
+ - **`false`**: Disable queuing, send events immediately
126
+ - **`undefined` (default)**: Enable queuing with default settings
127
+ - **`QueueConfig` object**: Enable queuing with custom settings
128
+
129
+ | Option | Type | Default | Description |
130
+ | ---------------- | -------- | ------- | ------------------------------------------------ |
131
+ | `eventBatchSize` | `number` | `15` | Max events per batch - auto-sends when reached |
132
+ | `flushInterval` | `number` | `5000` | Time between flushes - sends pending events (ms) |
133
+
134
+ **How it works:**
135
+
136
+ - ✅ Send immediately when `eventBatchSize` reached (e.g., 15 events)
137
+ - ✅ Send pending events every `flushInterval` (e.g., 5 seconds)
138
+ - ✅ Auto-flush on page navigation/close using `visibilitychange` + `pagehide` events
139
+ - Example: If you have 10 events and 5 seconds pass → sends those 10
140
+
141
+ **About page unload handling:**
142
+
143
+ The SDK uses modern APIs (`visibilitychange` + `pagehide`) instead of `beforeunload`/`unload` to ensure:
144
+
145
+ - ✅ Better reliability on mobile devices
146
+ - ✅ Compatible with browser back/forward cache (bfcache)
147
+ - ✅ Events are sent via `navigator.sendBeacon()` for guaranteed delivery
148
+ - ✅ No negative impact on page performance
149
+
150
+ **Example: Disable queuing for immediate sends**
151
+
152
+ ```javascript
153
+ const analytics = initializeContentAnalytics({
154
+ siteAuth: 'abc123',
155
+ server: 'https://your-dotcms.com',
156
+ queue: false // Send events immediately without batching
157
+ });
158
+ ```
159
+
160
+ **Example: Custom queue config**
161
+
162
+ ```javascript
163
+ const analytics = initializeContentAnalytics({
164
+ siteAuth: 'abc123',
165
+ server: 'https://your-dotcms.com',
166
+ queue: {
167
+ eventBatchSize: 10, // Auto-send when 10 events queued
168
+ flushInterval: 3000 // Or send every 3 seconds
169
+ }
170
+ });
171
+ ```
172
+
173
+ ### Impression Tracking Configuration
174
+
175
+ The `impressions` option controls automatic tracking of content visibility:
176
+
177
+ - **`false` or `undefined` (default)**: Impression tracking disabled
178
+ - **`true`**: Enable tracking with default settings
179
+ - **`ImpressionConfig` object**: Enable tracking with custom settings
180
+
181
+ | Option | Type | Default | Description |
182
+ | --------------------- | -------- | ------- | ----------------------------------------- |
183
+ | `visibilityThreshold` | `number` | `0.5` | Min percentage visible (0.0 to 1.0) |
184
+ | `dwellMs` | `number` | `750` | Min time visible in milliseconds |
185
+ | `maxNodes` | `number` | `1000` | Max elements to track (performance limit) |
186
+
187
+ **How it works:**
188
+
189
+ - ✅ Tracks contentlets marked with `dotcms-analytics-contentlet` class and `data-dot-analytics-*` attributes
190
+ - ✅ Uses Intersection Observer API for high performance and battery efficiency
191
+ - ✅ Only fires when element is ≥50% visible for ≥750ms (configurable)
192
+ - ✅ Only tracks during active tab (respects page visibility)
193
+ - ✅ One impression per contentlet per session (no duplicates)
194
+ - ✅ Respects user consent settings
195
+ - ✅ Automatically disabled in dotCMS editor mode
196
+
197
+ **Example: Enable with defaults**
198
+
199
+ ```javascript
200
+ const analytics = initializeContentAnalytics({
201
+ siteAuth: 'abc123',
202
+ server: 'https://your-dotcms.com',
203
+ impressions: true // 50% visible, 750ms dwell, 1000 max nodes
204
+ });
205
+ ```
206
+
207
+ **Example: Custom thresholds**
208
+
209
+ ```javascript
210
+ const analytics = initializeContentAnalytics({
211
+ siteAuth: 'abc123',
212
+ server: 'https://your-dotcms.com',
213
+ impressions: {
214
+ visibilityThreshold: 0.7, // Require 70% visible
215
+ dwellMs: 1000, // Must be visible for 1 second
216
+ maxNodes: 500 // Track max 500 elements
217
+ }
218
+ });
219
+ ```
220
+
221
+ **Example: Disable tracking**
222
+
223
+ ```javascript
224
+ const analytics = initializeContentAnalytics({
225
+ siteAuth: 'abc123',
226
+ server: 'https://your-dotcms.com',
227
+ impressions: false // Explicitly disabled (also default if omitted)
228
+ });
229
+ ```
230
+
231
+ ### Click Tracking Configuration
232
+
233
+ The `clicks` option controls automatic tracking of user interactions with content elements:
234
+
235
+ - **`false` or `undefined` (default)**: Click tracking disabled
236
+ - **`true`**: Enable tracking with default settings (300ms throttle)
237
+
238
+ **How it works:**
239
+
240
+ - ✅ Tracks clicks on `<a>` and `<button>` elements within contentlets
241
+ - ✅ Contentlets must be marked with `dotcms-analytics-contentlet` class and `data-dot-analytics-*` attributes
242
+ - ✅ Captures semantic attributes (`href`, `aria-label`, `data-*`) and excludes CSS classes
243
+ - ✅ Throttles rapid clicks to prevent duplicate tracking (300ms fixed)
244
+ - ✅ One click event per interaction
245
+ - ✅ Respects user consent settings
246
+ - ✅ Automatically disabled in dotCMS editor mode
247
+
248
+ **Captured Data:**
249
+
250
+ For each click, the SDK captures:
251
+
252
+ - **Content Info**: `identifier`, `inode`, `title`, `content_type`
253
+ - **Element Info**:
254
+ - `text` - Button/link text (truncated to 100 chars)
255
+ - `type` - Element type (`a` or `button`)
256
+ - `id` - Element ID (required by backend, empty string if not present)
257
+ - `class` - Element CSS classes (required by backend, empty string if not present)
258
+ - `href` - Link destination as written in HTML (e.g., `/signup` not `http://...`, only for `<a>`, empty string for buttons)
259
+ - `attributes` - Additional useful attributes (see below)
260
+ - **Position Info**:
261
+ - `viewport_offset_pct` - Position relative to viewport (0-100%)
262
+ - `dom_index` - Element position in DOM
263
+
264
+ **Attributes Array:**
265
+
266
+ > **Note**: The `attributes` field is formatted as an array of `'key:value'` strings (e.g., `['data-category:primary-cta', 'aria-label:Sign up']`) for efficient serialization and backend parsing.
267
+
268
+ The `attributes` array captures additional semantic data in `'key:value'` string format:
269
+
270
+ ✅ **Included** (semantic/analytics value):
271
+
272
+ - `data-*` - Custom data attributes (e.g., `'data-category:primary-cta'`)
273
+ - `aria-*` - Accessibility attributes (e.g., `'aria-label:Sign up now'`)
274
+ - `title` - Element title
275
+ - `target` - Link target (e.g., `'target:_blank'`)
276
+ - Any other standard HTML attributes
277
+
278
+ ❌ **Excluded** (to avoid duplication):
279
+
280
+ - `class` - Already captured as top-level property
281
+ - `id` - Already captured as top-level property
282
+ - `href` - Already captured as top-level property
283
+ - `data-dot-analytics-*` - Internal SDK attributes
284
+
285
+ **Example: Enable click tracking**
286
+
287
+ ```javascript
288
+ const analytics = initializeContentAnalytics({
289
+ siteAuth: 'abc123',
290
+ server: 'https://your-dotcms.com',
291
+ clicks: true // Enable with 300ms throttle (fixed)
292
+ });
293
+ ```
294
+
295
+ **Example: Adding Custom Analytics Metadata**
296
+
297
+ Use `data-*` attributes to enrich click tracking with custom metadata:
298
+
299
+ ```html
300
+ <!-- Primary CTA with category -->
301
+ <a
302
+ href="/signup"
303
+ id="cta-signup"
304
+ data-category="primary-cta"
305
+ data-campaign="summer-sale"
306
+ aria-label="Sign up for free trial">
307
+ Start Free Trial →
308
+ </a>
309
+
310
+ <!-- Product link with metadata -->
311
+ <a href="/products/123" data-product-id="123" data-product-name="Premium Plan" data-price="29.99">
312
+ View Product
313
+ </a>
314
+
315
+ <!-- Button with custom tracking -->
316
+ <button data-action="download" data-file-type="pdf" data-category="lead-magnet">
317
+ Download Whitepaper
318
+ </button>
319
+ ```
320
+
321
+ **Resulting Click Event:**
322
+
323
+ ```json
324
+ {
325
+ "content": {
326
+ "identifier": "abc123",
327
+ "inode": "xyz789",
328
+ "title": "Product Page",
329
+ "content_type": "Page"
330
+ },
331
+ "element": {
332
+ "text": "Start Free Trial →",
333
+ "type": "a",
334
+ "id": "cta-signup",
335
+ "class": "btn btn-primary text-white",
336
+ "href": "/signup",
337
+ "attributes": [
338
+ "data-category:primary-cta",
339
+ "data-campaign:summer-sale",
340
+ "aria-label:Sign up for free trial",
341
+ "target:_blank"
342
+ ]
343
+ },
344
+ "position": {
345
+ "viewport_offset_pct": 45.2,
346
+ "dom_index": 2
347
+ }
348
+ }
349
+ ```
350
+
351
+ **Example: Disable tracking**
352
+
353
+ ```javascript
354
+ const analytics = initializeContentAnalytics({
355
+ siteAuth: 'abc123',
356
+ server: 'https://your-dotcms.com',
357
+ clicks: false // Explicitly disabled (also default if omitted)
358
+ });
359
+ ```
85
360
 
86
361
  ## 🛠️ Usage Examples
87
362
 
88
363
  ### Vanilla JavaScript
89
364
 
90
- **Manual Page View & Events**
365
+ **Basic Page View**
91
366
 
92
367
  ```javascript
93
- // After init with the <script> tag the dotAnalytics is added to the window.
94
- window.dotAnalytics.track('cta-click', { button: 'Buy Now' });
368
+ // After init with the <script> tag, dotAnalytics is added to the window
369
+ // Automatically captures: page, device, UTM, context (session, user, site)
95
370
  window.dotAnalytics.pageView();
96
371
  ```
97
372
 
373
+ **Page View with Additional Custom Data**
374
+
375
+ ```javascript
376
+ // All automatic data (page, device, UTM, context) is STILL captured
377
+ // Plus your custom properties are added under 'custom'
378
+ window.dotAnalytics.pageView({
379
+ contentType: 'blog',
380
+ category: 'technology',
381
+ author: 'john-doe',
382
+ wordCount: 1500
383
+ });
384
+
385
+ // The server receives: page + device + utm + context + custom (your data)
386
+ ```
387
+
388
+ **Track Custom Events**
389
+
390
+ ```javascript
391
+ // Basic event tracking
392
+ window.dotAnalytics.track('cta-click', {
393
+ button: 'Buy Now',
394
+ location: 'hero-section'
395
+ });
396
+
397
+ // Track form submission
398
+ window.dotAnalytics.track('form-submit', {
399
+ formName: 'contact-form',
400
+ formType: 'lead-gen'
401
+ });
402
+
403
+ // Track video interaction
404
+ window.dotAnalytics.track('video-play', {
405
+ videoId: 'intro-video',
406
+ duration: 120,
407
+ autoplay: false
408
+ });
409
+ ```
410
+
98
411
  **Advanced: Manual Init with Custom Properties**
99
412
 
100
413
  ```javascript
101
414
  const analytics = initializeContentAnalytics({
102
- siteKey: 'abc123',
415
+ siteAuth: 'abc123',
103
416
  server: 'https://your-dotcms.com',
104
417
  debug: true,
105
418
  autoPageView: false
106
419
  });
107
420
 
108
- analytics.track('custom-event', {
109
- category: 'Marketing',
110
- value: 'Banner Clicked'
421
+ // Track custom events with properties
422
+ analytics.track('product-view', {
423
+ productId: 'SKU-12345',
424
+ category: 'Electronics',
425
+ price: 299.99,
426
+ inStock: true
111
427
  });
112
428
 
113
- analytics.pageView();
429
+ // Manual page view with custom data
430
+ // Automatic enrichment (page, device, UTM, context) + your custom data
431
+ analytics.pageView({
432
+ section: 'checkout',
433
+ step: 'payment',
434
+ cartValue: 299.99
435
+ });
114
436
  ```
115
437
 
116
438
  ### React
117
439
 
118
- **Track Events**
440
+ > **Note:** React integration is currently in development. The API may change.
441
+
442
+ **Basic Setup**
119
443
 
120
444
  ```tsx
121
- import { useContentAnalytics } from '@dotcms/analytics/react';
445
+ import { DotContentAnalytics } from '@dotcms/analytics/react';
122
446
 
123
- const { track } = useContentAnalytics({
124
- siteKey: 'SITE_KEY',
125
- server: 'https://demo.dotcms.com'
126
- });
447
+ const config = {
448
+ siteAuth: 'SITE_KEY',
449
+ server: 'https://demo.dotcms.com',
450
+ autoPageView: true
451
+ };
127
452
 
128
- track('cta-click', { label: 'Download PDF' });
453
+ export function AppRoot() {
454
+ return <DotContentAnalytics config={config} />;
455
+ }
129
456
  ```
130
457
 
131
- **Manual Page View**
458
+ **Using the Hook**
132
459
 
133
460
  ```tsx
134
461
  import { useContentAnalytics } from '@dotcms/analytics/react';
135
462
 
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**
463
+ function MyComponent() {
464
+ const { track, pageView } = useContentAnalytics({
465
+ siteAuth: 'SITE_AUTH',
466
+ server: 'https://demo.dotcms.com'
467
+ });
146
468
 
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';
152
-
153
- const { pageView } = useContentAnalytics({
154
- siteKey: 'SITE_KEY',
155
- server: 'https://demo.dotcms.com'
156
- });
157
- const location = useLocation();
469
+ // Track custom events (same API as vanilla JS)
470
+ const handleClick = () => {
471
+ track('button-click', { label: 'CTA Button' });
472
+ };
158
473
 
159
- useEffect(() => {
160
- pageView();
161
- }, [location]);
474
+ return <button onClick={handleClick}>Click Me</button>;
475
+ }
162
476
  ```
163
477
 
164
478
  ## API Reference
165
479
 
166
480
  ```typescript
167
481
  interface DotCMSAnalytics {
168
- track: (eventName: string, payload?: Record<string, unknown>) => void;
169
- pageView: () => void;
482
+ /**
483
+ * Track a page view event with optional custom data
484
+ * @param customData - Optional object with custom properties to attach to the pageview
485
+ */
486
+ pageView: (customData?: Record<string, unknown>) => void;
487
+
488
+ /**
489
+ * Track a custom event
490
+ * @param eventName - Name of the custom event (cannot be "pageview")
491
+ * @param properties - Optional object with event-specific properties
492
+ */
493
+ track: (eventName: string, properties?: Record<string, unknown>) => void;
170
494
  }
171
495
  ```
172
496
 
173
- **Enriched AnalyticsEvent includes:**
497
+ ### Page View Event Structure
498
+
499
+ When you call `pageView(customData?)`, the SDK **automatically enriches** the event with comprehensive data and sends:
174
500
 
175
- - `context`: siteKey, sessionId, userId
176
- - `page`: URL, title, referrer, path
177
- - `device`: screen size, language, viewport
178
- - `utm`: source, medium, campaign, term, etc.
501
+ ```typescript
502
+ {
503
+ context: { // 🤖 AUTOMATIC - Identity & Session
504
+ site_key: string; // Your site key
505
+ session_id: string; // Current session ID
506
+ user_id: string; // Anonymous user ID
507
+ device: { // 🤖 AUTOMATIC - Device & Browser Info
508
+ screen_resolution: string; // Screen size
509
+ language: string; // Browser language
510
+ viewport_width: string; // Viewport width
511
+ viewport_height: string; // Viewport height
512
+ }
513
+ },
514
+ events: [{
515
+ event_type: "pageview",
516
+ local_time: string, // 🤖 AUTOMATIC - ISO 8601 timestamp with timezone
517
+ data: {
518
+ page: { // 🤖 AUTOMATIC - Page Information
519
+ url: string; // Full URL
520
+ title: string; // Page title
521
+ referrer: string; // Referrer URL
522
+ path: string; // Path
523
+ doc_host: string; // Hostname
524
+ doc_protocol: string; // Protocol (http/https)
525
+ doc_search: string; // Query string
526
+ doc_hash: string; // URL hash
527
+ doc_encoding: string; // Character encoding
528
+ },
529
+ utm?: { // 🤖 AUTOMATIC - Campaign Tracking (if present in URL)
530
+ source: string; // utm_source
531
+ medium: string; // utm_medium
532
+ campaign: string; // utm_campaign
533
+ term: string; // utm_term
534
+ content: string; // utm_content
535
+ },
536
+ custom?: { // 👤 YOUR DATA (optional)
537
+ // Any custom properties you pass to pageView(customData)
538
+ contentType?: string;
539
+ category?: string;
540
+ author?: string;
541
+ // ... any other properties
542
+ }
543
+ }
544
+ }]
545
+ }
546
+ ```
547
+
548
+ **Key Points:**
549
+
550
+ - 🤖 Most data is captured **automatically** - you don't need to provide it
551
+ - 👤 `custom` is where **your optional data** goes
552
+ - All automatic data is always captured, even if you don't pass `customData`
553
+
554
+ ### Custom Event Structure
555
+
556
+ When you call `track(eventName, properties)`, the following structure is sent:
557
+
558
+ ```typescript
559
+ {
560
+ context: {
561
+ site_key: string; // Your site key
562
+ session_id: string; // Current session ID
563
+ user_id: string; // Anonymous user ID
564
+ device: { // 🤖 AUTOMATIC - Device & Browser Info
565
+ screen_resolution: string; // Screen size
566
+ language: string; // Browser language
567
+ viewport_width: string; // Viewport width
568
+ viewport_height: string; // Viewport height
569
+ }
570
+ },
571
+ events: [{
572
+ event_type: string, // Your custom event name
573
+ local_time: string, // ISO 8601 timestamp
574
+ data: {
575
+ custom: {
576
+ // Your properties object
577
+ }
578
+ }
579
+ }]
580
+ }
581
+ ```
179
582
 
180
583
  ## Under the Hood
181
584
 
@@ -213,25 +616,25 @@ Standalone attributes to verify:
213
616
  - Angular & Vue support
214
617
  - Realtime dashboard
215
618
 
216
- ## dotCMS Support
619
+ ## Support
217
620
 
218
- We offer multiple channels to get help with the dotCMS React SDK:
621
+ We offer multiple channels to get help with the dotCMS Analytics SDK:
219
622
 
220
- - **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
- - **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.
223
- - **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://helpdesk.dotcms.com/support/).
623
+ - **GitHub Issues**: For bug reports and feature requests, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository
624
+ - **Community Forum**: Join our [community discussions](https://community.dotcms.com/) to ask questions and share solutions
625
+ - **Stack Overflow**: Use the tag `dotcms-analytics` when posting questions
626
+ - **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://helpdesk.dotcms.com/support/)
224
627
 
225
628
  When reporting issues, please include:
226
629
 
227
630
  - SDK version you're using
228
- - React version
631
+ - Framework/library version (if applicable)
229
632
  - Minimal reproduction steps
230
633
  - Expected vs. actual behavior
231
634
 
232
- ## How To Contribute
635
+ ## Contributing
233
636
 
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:
637
+ 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
638
 
236
639
  1. Fork the repository [dotCMS/core](https://github.com/dotCMS/core)
237
640
  2. Create a feature branch (`git checkout -b feature/amazing-feature`)
@@ -241,7 +644,7 @@ GitHub pull requests are the preferred method to contribute code to dotCMS. We w
241
644
 
242
645
  Please ensure your code follows the existing style and includes appropriate tests.
243
646
 
244
- ## Licensing Information
647
+ ## Licensing
245
648
 
246
649
  dotCMS comes in multiple editions and as such is dual-licensed. The dotCMS Community Edition is licensed under the GPL 3.0 and is freely available for download, customization, and deployment for use within organizations of all stripes. dotCMS Enterprise Editions (EE) adds several enterprise features and is available via a supported, indemnified commercial license from dotCMS. For the differences between the editions, see [the feature page](http://www.dotcms.com/cms-platform/features).
247
650
 
@@ -1,4 +1,11 @@
1
- import { DotCMSAnalytics, DotCMSAnalyticsConfig } from './shared/dot-content-analytics.model';
1
+ import { ANALYTICS_WINDOWS_ACTIVE_KEY, ANALYTICS_WINDOWS_CLEANUP_KEY } from '../../../../uve/src/internal.ts';
2
+ import { DotCMSAnalytics, DotCMSAnalyticsConfig } from './shared/models';
3
+ declare global {
4
+ interface Window {
5
+ [ANALYTICS_WINDOWS_ACTIVE_KEY]?: boolean;
6
+ [ANALYTICS_WINDOWS_CLEANUP_KEY]?: () => void;
7
+ }
8
+ }
2
9
  /**
3
10
  * Creates an analytics instance for content analytics tracking.
4
11
  *