@dotcms/analytics 1.1.1-next.2 → 1.1.1-next.4
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 +222 -61
- package/lib/core/dot-content-analytics.d.ts +1 -1
- package/lib/core/dot-content-analytics.js +27 -25
- package/lib/core/plugin/dot-analytics.plugin.d.ts +3 -3
- package/lib/core/plugin/dot-analytics.plugin.js +25 -57
- 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/{dot-content-analytics.constants.d.ts → constants/dot-content-analytics.constants.d.ts} +22 -5
- package/lib/core/shared/constants/dot-content-analytics.constants.js +28 -0
- package/lib/core/shared/constants/index.d.ts +4 -0
- package/lib/core/shared/dot-content-analytics.activity-tracker.d.ts +1 -1
- package/lib/core/shared/dot-content-analytics.activity-tracker.js +1 -1
- package/lib/core/shared/dot-content-analytics.http.d.ts +2 -2
- package/lib/core/shared/dot-content-analytics.http.js +10 -9
- package/lib/core/shared/dot-content-analytics.utils.d.ts +90 -44
- package/lib/core/shared/dot-content-analytics.utils.js +82 -65
- 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 +12 -0
- package/lib/core/shared/models/library.model.d.ts +174 -0
- package/lib/core/shared/models/request.model.d.ts +24 -0
- package/lib/react/components/DotContentAnalytics.d.ts +1 -1
- package/lib/react/hook/useContentAnalytics.d.ts +42 -14
- package/lib/react/hook/useContentAnalytics.js +17 -20
- package/lib/react/hook/useRouterTracker.d.ts +1 -1
- package/lib/react/internal/utils.d.ts +1 -1
- package/lib/react/public-api.d.ts +1 -1
- package/lib/standalone.d.ts +2 -2
- package/package.json +1 -1
- 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
|
@@ -32,7 +32,7 @@ const analytics = initializeContentAnalytics({
|
|
|
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
|
|
@@ -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
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
The `pageView()` method tracks page navigation events. **It automatically enriches the event with comprehensive data**, including:
|
|
60
62
|
|
|
61
|
-
|
|
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
|
+
```
|
|
91
|
+
|
|
92
|
+
**Important:**
|
|
62
93
|
|
|
63
|
-
-
|
|
64
|
-
-
|
|
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,25 +108,64 @@ Track any user action as an event using `track('event-name', { payload })`.
|
|
|
76
108
|
|
|
77
109
|
## ⚙️ Configuration Options
|
|
78
110
|
|
|
79
|
-
|
|
111
|
+
<<<<<<< HEAD
|
|
112
|
+
| Option | Type | Required | Default | Description |
|
|
80
113
|
| -------------- | --------- | -------- | ----------------------------------- | -------------------------------------- |
|
|
81
|
-
| `siteAuth`
|
|
82
|
-
| `server`
|
|
83
|
-
| `debug`
|
|
84
|
-
| `autoPageView` | `boolean` | ❌
|
|
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
|
-
**
|
|
123
|
+
**Basic Page View**
|
|
91
124
|
|
|
92
125
|
```javascript
|
|
93
|
-
// After init with the <script> tag
|
|
94
|
-
|
|
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
|
|
@@ -105,77 +176,167 @@ const analytics = initializeContentAnalytics({
|
|
|
105
176
|
autoPageView: false
|
|
106
177
|
});
|
|
107
178
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
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
|
-
**
|
|
198
|
+
> **Note:** React integration is currently in development. The API may change.
|
|
199
|
+
|
|
200
|
+
**Basic Setup**
|
|
119
201
|
|
|
120
202
|
```tsx
|
|
121
|
-
import {
|
|
203
|
+
import { DotContentAnalytics } from '@dotcms/analytics/react';
|
|
122
204
|
|
|
123
|
-
const
|
|
124
|
-
siteAuth: '
|
|
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
|
-
|
|
211
|
+
export function AppRoot() {
|
|
212
|
+
return <DotContentAnalytics config={config} />;
|
|
213
|
+
}
|
|
129
214
|
```
|
|
130
215
|
|
|
131
|
-
**
|
|
216
|
+
**Using the Hook**
|
|
132
217
|
|
|
133
218
|
```tsx
|
|
134
219
|
import { useContentAnalytics } from '@dotcms/analytics/react';
|
|
135
220
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
154
|
-
|
|
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
|
-
|
|
169
|
-
|
|
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;
|
|
170
252
|
}
|
|
171
253
|
```
|
|
172
254
|
|
|
173
|
-
|
|
255
|
+
### Page View Event Structure
|
|
174
256
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
+
device: { // 🤖 AUTOMATIC - Device & Browser Info
|
|
266
|
+
screen_resolution: string; // Screen size
|
|
267
|
+
language: string; // Browser language
|
|
268
|
+
viewport_width: string; // Viewport width
|
|
269
|
+
viewport_height: string; // Viewport height
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
events: [{
|
|
273
|
+
event_type: "pageview",
|
|
274
|
+
local_time: string, // 🤖 AUTOMATIC - ISO 8601 timestamp with timezone
|
|
275
|
+
data: {
|
|
276
|
+
page: { // 🤖 AUTOMATIC - Page Information
|
|
277
|
+
url: string; // Full URL
|
|
278
|
+
title: string; // Page title
|
|
279
|
+
referrer: string; // Referrer URL
|
|
280
|
+
path: string; // Path
|
|
281
|
+
doc_host: string; // Hostname
|
|
282
|
+
doc_protocol: string; // Protocol (http/https)
|
|
283
|
+
doc_search: string; // Query string
|
|
284
|
+
doc_hash: string; // URL hash
|
|
285
|
+
doc_encoding: string; // Character encoding
|
|
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
|
+
}]
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
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
|
|
313
|
+
|
|
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
|
+
device: { // 🤖 AUTOMATIC - Device & Browser Info
|
|
323
|
+
screen_resolution: string; // Screen size
|
|
324
|
+
language: string; // Browser language
|
|
325
|
+
viewport_width: string; // Viewport width
|
|
326
|
+
viewport_height: string; // Viewport height
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
events: [{
|
|
330
|
+
event_type: string, // Your custom event name
|
|
331
|
+
local_time: string, // ISO 8601 timestamp
|
|
332
|
+
data: {
|
|
333
|
+
custom: {
|
|
334
|
+
// Your properties object
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}]
|
|
338
|
+
}
|
|
339
|
+
```
|
|
179
340
|
|
|
180
341
|
## Under the Hood
|
|
181
342
|
|
|
@@ -215,23 +376,23 @@ Standalone attributes to verify:
|
|
|
215
376
|
|
|
216
377
|
## dotCMS Support
|
|
217
378
|
|
|
218
|
-
We offer multiple channels to get help with the dotCMS
|
|
379
|
+
We offer multiple channels to get help with the dotCMS Analytics SDK:
|
|
219
380
|
|
|
220
381
|
- **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
382
|
- **Community Forum**: Join our [community discussions](https://community.dotcms.com/) to ask questions and share solutions.
|
|
222
|
-
- **Stack Overflow**: Use the tag `dotcms-
|
|
383
|
+
- **Stack Overflow**: Use the tag `dotcms-analytics` when posting questions.
|
|
223
384
|
- **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://helpdesk.dotcms.com/support/).
|
|
224
385
|
|
|
225
386
|
When reporting issues, please include:
|
|
226
387
|
|
|
227
388
|
- SDK version you're using
|
|
228
|
-
-
|
|
389
|
+
- Framework/library version (if applicable)
|
|
229
390
|
- Minimal reproduction steps
|
|
230
391
|
- Expected vs. actual behavior
|
|
231
392
|
|
|
232
393
|
## How To Contribute
|
|
233
394
|
|
|
234
|
-
GitHub pull requests are the preferred method to contribute code to dotCMS. We welcome contributions to the DotCMS
|
|
395
|
+
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
396
|
|
|
236
397
|
1. Fork the repository [dotCMS/core](https://github.com/dotCMS/core)
|
|
237
398
|
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
@@ -1,40 +1,42 @@
|
|
|
1
|
-
import { Analytics as
|
|
2
|
-
import { dotAnalytics as
|
|
3
|
-
import { dotAnalyticsEnricherPlugin as
|
|
4
|
-
import { dotAnalyticsIdentityPlugin as
|
|
5
|
-
import { cleanupActivityTracking as
|
|
6
|
-
const f = (
|
|
7
|
-
if (!
|
|
8
|
-
return console.error('
|
|
9
|
-
if (!
|
|
10
|
-
return console.error('
|
|
11
|
-
const t =
|
|
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
|
+
import { dotAnalyticsIdentityPlugin as u } from "./plugin/identity/dot-analytics.identity.plugin.js";
|
|
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:
|
|
13
|
+
debug: i.debug,
|
|
14
14
|
plugins: [
|
|
15
|
-
|
|
15
|
+
u(i),
|
|
16
16
|
// Inject identity context (user_id, session_id, local_tz)
|
|
17
|
-
|
|
18
|
-
// Enrich with page, device, utm data
|
|
19
|
-
|
|
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
|
-
}),
|
|
23
|
-
return typeof window < "u" && (window.addEventListener("beforeunload",
|
|
22
|
+
}), r = () => a();
|
|
23
|
+
return typeof window < "u" && (window.addEventListener("beforeunload", r), window.__dotAnalyticsCleanup = r), {
|
|
24
24
|
/**
|
|
25
25
|
* Track a page view.
|
|
26
|
-
*
|
|
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: (
|
|
29
|
-
|
|
29
|
+
pageView: (n = {}) => {
|
|
30
|
+
t == null || t.page(n);
|
|
30
31
|
},
|
|
31
32
|
/**
|
|
32
33
|
* Track a custom event.
|
|
33
|
-
*
|
|
34
|
-
* @param
|
|
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: (
|
|
37
|
-
|
|
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/
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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 {
|
|
2
|
-
|
|
3
|
-
|
|
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:
|
|
6
|
+
config: a,
|
|
8
7
|
/**
|
|
9
8
|
* Initialize the plugin
|
|
10
9
|
*/
|
|
11
|
-
initialize: () => (
|
|
10
|
+
initialize: () => (n = !0, Promise.resolve()),
|
|
12
11
|
/**
|
|
13
12
|
* Track a page view event
|
|
14
|
-
*
|
|
13
|
+
* The enricher plugin has already built the complete request body
|
|
15
14
|
*/
|
|
16
|
-
page: (
|
|
17
|
-
const { config:
|
|
18
|
-
if (!
|
|
19
|
-
throw new Error("
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
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
|
-
*
|
|
27
|
+
* The enricher plugin has already built the complete request body
|
|
42
28
|
*/
|
|
43
|
-
track: (
|
|
44
|
-
const { config:
|
|
45
|
-
if (!
|
|
46
|
-
throw new Error("
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
37
|
+
return r(i, o);
|
|
70
38
|
},
|
|
71
39
|
/**
|
|
72
40
|
* Check if the plugin is loaded
|
|
73
41
|
*/
|
|
74
|
-
loaded: () =>
|
|
42
|
+
loaded: () => n
|
|
75
43
|
};
|
|
76
44
|
};
|
|
77
45
|
export {
|
|
78
|
-
|
|
46
|
+
s as dotAnalytics
|
|
79
47
|
};
|
|
@@ -1,44 +1,28 @@
|
|
|
1
|
-
import {
|
|
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_auth, user_id }
|
|
6
|
-
* This enricher plugin runs SECOND to add page/
|
|
5
|
+
* The identity plugin runs FIRST to inject context: { session_id, site_auth, user_id, device }
|
|
6
|
+
* This enricher plugin runs SECOND to add page/utm/custom data.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
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
|
-
*
|
|
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:
|
|
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
|
-
*
|
|
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:
|
|
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
|
};
|