@dotcms/analytics 1.1.1 → 1.2.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 +284 -71
- package/lib/core/dot-content-analytics.d.ts +8 -1
- package/lib/core/dot-content-analytics.js +26 -23
- package/lib/core/plugin/dot-analytics.plugin.d.ts +8 -7
- package/lib/core/plugin/dot-analytics.plugin.js +25 -62
- package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.d.ts +12 -28
- package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.js +37 -15
- package/lib/core/plugin/identity/dot-analytics.identity.plugin.d.ts +11 -11
- package/lib/core/plugin/identity/dot-analytics.identity.plugin.js +13 -11
- package/lib/core/plugin/identity/dot-analytics.identity.utils.d.ts +7 -6
- package/lib/core/shared/constants/dot-content-analytics.constants.d.ts +70 -0
- package/lib/core/shared/constants/dot-content-analytics.constants.js +34 -0
- package/lib/core/shared/constants/index.d.ts +4 -0
- package/lib/core/shared/dot-content-analytics.activity-tracker.d.ts +9 -2
- package/lib/core/shared/dot-content-analytics.activity-tracker.js +11 -10
- package/lib/core/shared/dot-content-analytics.http.d.ts +13 -4
- package/lib/core/shared/dot-content-analytics.http.js +25 -13
- package/lib/core/shared/dot-content-analytics.utils.d.ts +105 -44
- package/lib/core/shared/dot-content-analytics.utils.js +92 -68
- package/lib/core/shared/models/data.model.d.ts +103 -0
- package/lib/core/shared/models/event.model.d.ts +64 -0
- package/lib/core/shared/models/index.d.ts +7 -0
- package/lib/core/shared/models/library.model.d.ts +191 -0
- package/lib/core/shared/models/request.model.d.ts +24 -0
- package/lib/core/shared/queue/dot-analytics.queue.utils.d.ts +28 -0
- package/lib/core/shared/queue/dot-analytics.queue.utils.js +73 -0
- package/lib/core/shared/queue/index.d.ts +1 -0
- package/lib/react/components/DotContentAnalytics.d.ts +1 -1
- package/lib/react/hook/useContentAnalytics.d.ts +43 -15
- package/lib/react/hook/useContentAnalytics.js +18 -21
- package/lib/react/hook/useRouterTracker.d.ts +1 -1
- package/lib/react/internal/utils.d.ts +1 -1
- package/lib/react/internal/utils.js +2 -2
- package/lib/react/public-api.d.ts +1 -1
- package/lib/standalone.d.ts +2 -2
- package/package.json +2 -1
- package/uve/src/internal/constants.js +8 -3
- package/lib/core/shared/dot-content-analytics.constants.d.ts +0 -37
- package/lib/core/shared/dot-content-analytics.constants.js +0 -14
- 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="
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
59
|
+
### Page Views
|
|
60
|
+
|
|
61
|
+
The `pageView()` method tracks page navigation events. **It automatically enriches the event with comprehensive data**, including:
|
|
58
62
|
|
|
59
|
-
|
|
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
|
|
60
67
|
|
|
61
|
-
|
|
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
|
|
62
83
|
|
|
63
|
-
|
|
64
|
-
|
|
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,287 @@ Track any user action as an event using `track('event-name', { payload })`.
|
|
|
76
108
|
|
|
77
109
|
## ⚙️ Configuration Options
|
|
78
110
|
|
|
79
|
-
| Option
|
|
111
|
+
| Option | Type | Required | Default | Description |
|
|
80
112
|
| -------------- | --------- | -------- | ----------------------------------- | -------------------------------------- |
|
|
81
|
-
| `
|
|
82
|
-
| `server`
|
|
83
|
-
| `debug`
|
|
84
|
-
| `autoPageView` | `boolean` | ❌
|
|
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
|
+
|
|
119
|
+
### Queue Configuration
|
|
120
|
+
|
|
121
|
+
The `queueConfig` option controls event batching:
|
|
122
|
+
|
|
123
|
+
- **`false`**: Disable queuing, send events immediately
|
|
124
|
+
- **`undefined` (default)**: Enable queuing with default settings
|
|
125
|
+
- **`QueueConfig` object**: Enable queuing with custom settings
|
|
126
|
+
|
|
127
|
+
| Option | Type | Default | Description |
|
|
128
|
+
| ---------------- | -------- | ------- | ------------------------------------------------ |
|
|
129
|
+
| `eventBatchSize` | `number` | `15` | Max events per batch - auto-sends when reached |
|
|
130
|
+
| `flushInterval` | `number` | `5000` | Time between flushes - sends pending events (ms) |
|
|
131
|
+
|
|
132
|
+
**How it works:**
|
|
133
|
+
|
|
134
|
+
- ✅ Send immediately when `eventBatchSize` reached (e.g., 15 events)
|
|
135
|
+
- ✅ Send pending events every `flushInterval` (e.g., 5 seconds)
|
|
136
|
+
- ✅ Auto-flush on page navigation/close using `visibilitychange` + `pagehide` events
|
|
137
|
+
- Example: If you have 10 events and 5 seconds pass → sends those 10
|
|
138
|
+
|
|
139
|
+
**About page unload handling:**
|
|
140
|
+
|
|
141
|
+
The SDK uses modern APIs (`visibilitychange` + `pagehide`) instead of `beforeunload`/`unload` to ensure:
|
|
142
|
+
|
|
143
|
+
- ✅ Better reliability on mobile devices
|
|
144
|
+
- ✅ Compatible with browser back/forward cache (bfcache)
|
|
145
|
+
- ✅ Events are sent via `navigator.sendBeacon()` for guaranteed delivery
|
|
146
|
+
- ✅ No negative impact on page performance
|
|
147
|
+
|
|
148
|
+
**Example: Disable queuing for immediate sends**
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
const analytics = initializeContentAnalytics({
|
|
152
|
+
siteAuth: 'abc123',
|
|
153
|
+
server: 'https://your-dotcms.com',
|
|
154
|
+
queue: false // Send events immediately without batching
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Example: Custom queue config**
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
const analytics = initializeContentAnalytics({
|
|
162
|
+
siteAuth: 'abc123',
|
|
163
|
+
server: 'https://your-dotcms.com',
|
|
164
|
+
queue: {
|
|
165
|
+
eventBatchSize: 10, // Auto-send when 10 events queued
|
|
166
|
+
flushInterval: 3000 // Or send every 3 seconds
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
```
|
|
85
170
|
|
|
86
171
|
## 🛠️ Usage Examples
|
|
87
172
|
|
|
88
173
|
### Vanilla JavaScript
|
|
89
174
|
|
|
90
|
-
**
|
|
175
|
+
**Basic Page View**
|
|
91
176
|
|
|
92
177
|
```javascript
|
|
93
|
-
// After init with the <script> tag
|
|
94
|
-
|
|
178
|
+
// After init with the <script> tag, dotAnalytics is added to the window
|
|
179
|
+
// Automatically captures: page, device, UTM, context (session, user, site)
|
|
95
180
|
window.dotAnalytics.pageView();
|
|
96
181
|
```
|
|
97
182
|
|
|
183
|
+
**Page View with Additional Custom Data**
|
|
184
|
+
|
|
185
|
+
```javascript
|
|
186
|
+
// All automatic data (page, device, UTM, context) is STILL captured
|
|
187
|
+
// Plus your custom properties are added under 'custom'
|
|
188
|
+
window.dotAnalytics.pageView({
|
|
189
|
+
contentType: 'blog',
|
|
190
|
+
category: 'technology',
|
|
191
|
+
author: 'john-doe',
|
|
192
|
+
wordCount: 1500
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// The server receives: page + device + utm + context + custom (your data)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Track Custom Events**
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
// Basic event tracking
|
|
202
|
+
window.dotAnalytics.track('cta-click', {
|
|
203
|
+
button: 'Buy Now',
|
|
204
|
+
location: 'hero-section'
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Track form submission
|
|
208
|
+
window.dotAnalytics.track('form-submit', {
|
|
209
|
+
formName: 'contact-form',
|
|
210
|
+
formType: 'lead-gen'
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Track video interaction
|
|
214
|
+
window.dotAnalytics.track('video-play', {
|
|
215
|
+
videoId: 'intro-video',
|
|
216
|
+
duration: 120,
|
|
217
|
+
autoplay: false
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
98
221
|
**Advanced: Manual Init with Custom Properties**
|
|
99
222
|
|
|
100
223
|
```javascript
|
|
101
224
|
const analytics = initializeContentAnalytics({
|
|
102
|
-
|
|
225
|
+
siteAuth: 'abc123',
|
|
103
226
|
server: 'https://your-dotcms.com',
|
|
104
227
|
debug: true,
|
|
105
228
|
autoPageView: false
|
|
106
229
|
});
|
|
107
230
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
231
|
+
// Track custom events with properties
|
|
232
|
+
analytics.track('product-view', {
|
|
233
|
+
productId: 'SKU-12345',
|
|
234
|
+
category: 'Electronics',
|
|
235
|
+
price: 299.99,
|
|
236
|
+
inStock: true
|
|
111
237
|
});
|
|
112
238
|
|
|
113
|
-
|
|
239
|
+
// Manual page view with custom data
|
|
240
|
+
// Automatic enrichment (page, device, UTM, context) + your custom data
|
|
241
|
+
analytics.pageView({
|
|
242
|
+
section: 'checkout',
|
|
243
|
+
step: 'payment',
|
|
244
|
+
cartValue: 299.99
|
|
245
|
+
});
|
|
114
246
|
```
|
|
115
247
|
|
|
116
248
|
### React
|
|
117
249
|
|
|
118
|
-
**
|
|
250
|
+
> **Note:** React integration is currently in development. The API may change.
|
|
251
|
+
|
|
252
|
+
**Basic Setup**
|
|
119
253
|
|
|
120
254
|
```tsx
|
|
121
|
-
import {
|
|
255
|
+
import { DotContentAnalytics } from '@dotcms/analytics/react';
|
|
122
256
|
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
server: 'https://demo.dotcms.com'
|
|
126
|
-
|
|
257
|
+
const config = {
|
|
258
|
+
siteAuth: 'SITE_KEY',
|
|
259
|
+
server: 'https://demo.dotcms.com',
|
|
260
|
+
autoPageView: true
|
|
261
|
+
};
|
|
127
262
|
|
|
128
|
-
|
|
263
|
+
export function AppRoot() {
|
|
264
|
+
return <DotContentAnalytics config={config} />;
|
|
265
|
+
}
|
|
129
266
|
```
|
|
130
267
|
|
|
131
|
-
**
|
|
268
|
+
**Using the Hook**
|
|
132
269
|
|
|
133
270
|
```tsx
|
|
134
271
|
import { useContentAnalytics } from '@dotcms/analytics/react';
|
|
135
272
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
pageView();
|
|
142
|
-
}, []);
|
|
143
|
-
```
|
|
273
|
+
function MyComponent() {
|
|
274
|
+
const { track, pageView } = useContentAnalytics({
|
|
275
|
+
siteAuth: 'SITE_AUTH',
|
|
276
|
+
server: 'https://demo.dotcms.com'
|
|
277
|
+
});
|
|
144
278
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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';
|
|
279
|
+
// Track custom events (same API as vanilla JS)
|
|
280
|
+
const handleClick = () => {
|
|
281
|
+
track('button-click', { label: 'CTA Button' });
|
|
282
|
+
};
|
|
152
283
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
server: 'https://demo.dotcms.com'
|
|
156
|
-
});
|
|
157
|
-
const location = useLocation();
|
|
158
|
-
|
|
159
|
-
useEffect(() => {
|
|
160
|
-
pageView();
|
|
161
|
-
}, [location]);
|
|
284
|
+
return <button onClick={handleClick}>Click Me</button>;
|
|
285
|
+
}
|
|
162
286
|
```
|
|
163
287
|
|
|
164
288
|
## API Reference
|
|
165
289
|
|
|
166
290
|
```typescript
|
|
167
291
|
interface DotCMSAnalytics {
|
|
168
|
-
|
|
169
|
-
|
|
292
|
+
/**
|
|
293
|
+
* Track a page view event with optional custom data
|
|
294
|
+
* @param customData - Optional object with custom properties to attach to the pageview
|
|
295
|
+
*/
|
|
296
|
+
pageView: (customData?: Record<string, unknown>) => void;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Track a custom event
|
|
300
|
+
* @param eventName - Name of the custom event (cannot be "pageview")
|
|
301
|
+
* @param properties - Optional object with event-specific properties
|
|
302
|
+
*/
|
|
303
|
+
track: (eventName: string, properties?: Record<string, unknown>) => void;
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Page View Event Structure
|
|
308
|
+
|
|
309
|
+
When you call `pageView(customData?)`, the SDK **automatically enriches** the event with comprehensive data and sends:
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
{
|
|
313
|
+
context: { // 🤖 AUTOMATIC - Identity & Session
|
|
314
|
+
site_key: string; // Your site key
|
|
315
|
+
session_id: string; // Current session ID
|
|
316
|
+
user_id: string; // Anonymous user ID
|
|
317
|
+
device: { // 🤖 AUTOMATIC - Device & Browser Info
|
|
318
|
+
screen_resolution: string; // Screen size
|
|
319
|
+
language: string; // Browser language
|
|
320
|
+
viewport_width: string; // Viewport width
|
|
321
|
+
viewport_height: string; // Viewport height
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
events: [{
|
|
325
|
+
event_type: "pageview",
|
|
326
|
+
local_time: string, // 🤖 AUTOMATIC - ISO 8601 timestamp with timezone
|
|
327
|
+
data: {
|
|
328
|
+
page: { // 🤖 AUTOMATIC - Page Information
|
|
329
|
+
url: string; // Full URL
|
|
330
|
+
title: string; // Page title
|
|
331
|
+
referrer: string; // Referrer URL
|
|
332
|
+
path: string; // Path
|
|
333
|
+
doc_host: string; // Hostname
|
|
334
|
+
doc_protocol: string; // Protocol (http/https)
|
|
335
|
+
doc_search: string; // Query string
|
|
336
|
+
doc_hash: string; // URL hash
|
|
337
|
+
doc_encoding: string; // Character encoding
|
|
338
|
+
},
|
|
339
|
+
utm?: { // 🤖 AUTOMATIC - Campaign Tracking (if present in URL)
|
|
340
|
+
source: string; // utm_source
|
|
341
|
+
medium: string; // utm_medium
|
|
342
|
+
campaign: string; // utm_campaign
|
|
343
|
+
term: string; // utm_term
|
|
344
|
+
content: string; // utm_content
|
|
345
|
+
},
|
|
346
|
+
custom?: { // 👤 YOUR DATA (optional)
|
|
347
|
+
// Any custom properties you pass to pageView(customData)
|
|
348
|
+
contentType?: string;
|
|
349
|
+
category?: string;
|
|
350
|
+
author?: string;
|
|
351
|
+
// ... any other properties
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}]
|
|
170
355
|
}
|
|
171
356
|
```
|
|
172
357
|
|
|
173
|
-
**
|
|
358
|
+
**Key Points:**
|
|
359
|
+
|
|
360
|
+
- 🤖 Most data is captured **automatically** - you don't need to provide it
|
|
361
|
+
- 👤 `custom` is where **your optional data** goes
|
|
362
|
+
- All automatic data is always captured, even if you don't pass `customData`
|
|
174
363
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
364
|
+
### Custom Event Structure
|
|
365
|
+
|
|
366
|
+
When you call `track(eventName, properties)`, the following structure is sent:
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
{
|
|
370
|
+
context: {
|
|
371
|
+
site_key: string; // Your site key
|
|
372
|
+
session_id: string; // Current session ID
|
|
373
|
+
user_id: string; // Anonymous user ID
|
|
374
|
+
device: { // 🤖 AUTOMATIC - Device & Browser Info
|
|
375
|
+
screen_resolution: string; // Screen size
|
|
376
|
+
language: string; // Browser language
|
|
377
|
+
viewport_width: string; // Viewport width
|
|
378
|
+
viewport_height: string; // Viewport height
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
events: [{
|
|
382
|
+
event_type: string, // Your custom event name
|
|
383
|
+
local_time: string, // ISO 8601 timestamp
|
|
384
|
+
data: {
|
|
385
|
+
custom: {
|
|
386
|
+
// Your properties object
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}]
|
|
390
|
+
}
|
|
391
|
+
```
|
|
179
392
|
|
|
180
393
|
## Under the Hood
|
|
181
394
|
|
|
@@ -213,25 +426,25 @@ Standalone attributes to verify:
|
|
|
213
426
|
- Angular & Vue support
|
|
214
427
|
- Realtime dashboard
|
|
215
428
|
|
|
216
|
-
##
|
|
429
|
+
## Support
|
|
217
430
|
|
|
218
|
-
We offer multiple channels to get help with the dotCMS
|
|
431
|
+
We offer multiple channels to get help with the dotCMS Analytics SDK:
|
|
219
432
|
|
|
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-
|
|
223
|
-
- **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://helpdesk.dotcms.com/support/)
|
|
433
|
+
- **GitHub Issues**: For bug reports and feature requests, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository
|
|
434
|
+
- **Community Forum**: Join our [community discussions](https://community.dotcms.com/) to ask questions and share solutions
|
|
435
|
+
- **Stack Overflow**: Use the tag `dotcms-analytics` when posting questions
|
|
436
|
+
- **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://helpdesk.dotcms.com/support/)
|
|
224
437
|
|
|
225
438
|
When reporting issues, please include:
|
|
226
439
|
|
|
227
440
|
- SDK version you're using
|
|
228
|
-
-
|
|
441
|
+
- Framework/library version (if applicable)
|
|
229
442
|
- Minimal reproduction steps
|
|
230
443
|
- Expected vs. actual behavior
|
|
231
444
|
|
|
232
|
-
##
|
|
445
|
+
## Contributing
|
|
233
446
|
|
|
234
|
-
GitHub pull requests are the preferred method to contribute code to dotCMS. We welcome contributions to the
|
|
447
|
+
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
448
|
|
|
236
449
|
1. Fork the repository [dotCMS/core](https://github.com/dotCMS/core)
|
|
237
450
|
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
@@ -241,7 +454,7 @@ GitHub pull requests are the preferred method to contribute code to dotCMS. We w
|
|
|
241
454
|
|
|
242
455
|
Please ensure your code follows the existing style and includes appropriate tests.
|
|
243
456
|
|
|
244
|
-
## Licensing
|
|
457
|
+
## Licensing
|
|
245
458
|
|
|
246
459
|
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
460
|
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
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
|
*
|
|
@@ -1,43 +1,46 @@
|
|
|
1
|
-
import { Analytics as
|
|
1
|
+
import { Analytics as a } from "analytics";
|
|
2
|
+
import { ANALYTICS_WINDOWS_ACTIVE_KEY as r, ANALYTICS_WINDOWS_CLEANUP_KEY as s } from "../../uve/src/internal/constants.js";
|
|
2
3
|
import { dotAnalytics as l } from "./plugin/dot-analytics.plugin.js";
|
|
3
|
-
import { dotAnalyticsEnricherPlugin as
|
|
4
|
-
import { dotAnalyticsIdentityPlugin as
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
return console.error(
|
|
11
|
-
const
|
|
4
|
+
import { dotAnalyticsEnricherPlugin as c } from "./plugin/enricher/dot-analytics.enricher.plugin.js";
|
|
5
|
+
import { dotAnalyticsIdentityPlugin as p } from "./plugin/identity/dot-analytics.identity.plugin.js";
|
|
6
|
+
import { validateAnalyticsConfig as m } from "./shared/dot-content-analytics.utils.js";
|
|
7
|
+
import { cleanupActivityTracking as u } from "./shared/dot-content-analytics.activity-tracker.js";
|
|
8
|
+
const I = (n) => {
|
|
9
|
+
const o = m(n);
|
|
10
|
+
if (o)
|
|
11
|
+
return console.error(`DotCMS Analytics: Missing ${o.join(" and ")} in configuration`), typeof window < "u" && (window[r] = !1), null;
|
|
12
|
+
const i = a({
|
|
12
13
|
app: "dotAnalytics",
|
|
13
14
|
debug: n.debug,
|
|
14
15
|
plugins: [
|
|
15
|
-
|
|
16
|
+
p(n),
|
|
16
17
|
// Inject identity context (user_id, session_id, local_tz)
|
|
17
|
-
|
|
18
|
-
// Enrich with page, device, utm data
|
|
18
|
+
c(),
|
|
19
|
+
// Enrich and clean payload with page, device, utm data and custom data
|
|
19
20
|
l(n)
|
|
20
21
|
// Send events to server
|
|
21
22
|
]
|
|
22
|
-
}), e = () =>
|
|
23
|
-
return typeof window < "u" && (window.addEventListener("beforeunload", e), window
|
|
23
|
+
}), e = () => u();
|
|
24
|
+
return typeof window < "u" && (window.addEventListener("beforeunload", e), window[s] = e, window[r] = !0, window.dispatchEvent(new CustomEvent("dotcms:analytics:ready"))), {
|
|
24
25
|
/**
|
|
25
26
|
* Track a page view.
|
|
26
|
-
*
|
|
27
|
+
* Session activity is automatically updated by the identity plugin.
|
|
28
|
+
* @param payload - Optional custom data to include with the page view (any valid JSON object)
|
|
27
29
|
*/
|
|
28
|
-
pageView: (
|
|
29
|
-
|
|
30
|
+
pageView: (t = {}) => {
|
|
31
|
+
i == null || i.page(t);
|
|
30
32
|
},
|
|
31
33
|
/**
|
|
32
34
|
* Track a custom event.
|
|
33
|
-
*
|
|
34
|
-
* @param
|
|
35
|
+
* Session activity is automatically updated by the identity plugin.
|
|
36
|
+
* @param eventName - The name of the event to track
|
|
37
|
+
* @param payload - Custom data to include with the event (any valid JSON object)
|
|
35
38
|
*/
|
|
36
|
-
track: (
|
|
37
|
-
|
|
39
|
+
track: (t, d = {}) => {
|
|
40
|
+
i == null || i.track(t, d);
|
|
38
41
|
}
|
|
39
42
|
};
|
|
40
43
|
};
|
|
41
44
|
export {
|
|
42
|
-
|
|
45
|
+
I as initializeContentAnalytics
|
|
43
46
|
};
|
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
import { DotCMSAnalyticsConfig, DotCMSAnalyticsParams } from '../shared/
|
|
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,
|
|
5
5
|
* and processing both automatic and manual tracking events.
|
|
6
|
+
* Supports optional queue management for batching events before sending.
|
|
6
7
|
*
|
|
7
8
|
* @param {DotCMSAnalyticsConfig} config - Configuration object containing API key, server URL,
|
|
8
|
-
* debug mode
|
|
9
|
+
* debug mode, auto page view settings, and queue config
|
|
9
10
|
* @returns {Object} Plugin object with methods for initialization and event tracking
|
|
10
11
|
*/
|
|
11
12
|
export declare const dotAnalytics: (config: DotCMSAnalyticsConfig) => {
|
|
12
13
|
name: string;
|
|
13
14
|
config: DotCMSAnalyticsConfig;
|
|
14
15
|
/**
|
|
15
|
-
* Initialize the plugin
|
|
16
|
+
* Initialize the plugin with optional queue management
|
|
16
17
|
*/
|
|
17
18
|
initialize: () => Promise<void>;
|
|
18
19
|
/**
|
|
19
20
|
* Track a page view event
|
|
20
|
-
*
|
|
21
|
+
* The enricher plugin has already built the complete request body
|
|
21
22
|
*/
|
|
22
|
-
page: (params: DotCMSAnalyticsParams) =>
|
|
23
|
+
page: (params: DotCMSAnalyticsParams) => void;
|
|
23
24
|
/**
|
|
24
25
|
* Track a custom event
|
|
25
|
-
*
|
|
26
|
+
* The enricher plugin has already built the complete request body
|
|
26
27
|
*/
|
|
27
|
-
track: (params: DotCMSAnalyticsParams) =>
|
|
28
|
+
track: (params: DotCMSAnalyticsParams) => void;
|
|
28
29
|
/**
|
|
29
30
|
* Check if the plugin is loaded
|
|
30
31
|
*/
|