@dotcms/analytics 0.0.1-beta.9 → 1.0.0-next.2
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 +167 -100
- package/lib/dotAnalytics/dot-content-analytics.d.ts +5 -5
- package/lib/dotAnalytics/dot-content-analytics.js +28 -9
- package/lib/dotAnalytics/plugin/dot-analytics.plugin.d.ts +9 -7
- package/lib/dotAnalytics/plugin/dot-analytics.plugin.js +55 -31
- package/lib/dotAnalytics/plugin/enricher/dot-analytics.enricher.plugin.d.ts +45 -0
- package/lib/dotAnalytics/plugin/enricher/dot-analytics.enricher.plugin.js +34 -0
- package/lib/dotAnalytics/plugin/identity/dot-analytics.identity.plugin.d.ts +80 -0
- package/lib/dotAnalytics/plugin/identity/dot-analytics.identity.plugin.js +40 -0
- package/lib/dotAnalytics/plugin/identity/dot-analytics.identity.utils.d.ts +24 -0
- package/lib/dotAnalytics/shared/dot-content-analytics.activity-tracker.d.ts +29 -0
- package/lib/dotAnalytics/shared/dot-content-analytics.activity-tracker.js +86 -0
- package/lib/dotAnalytics/shared/dot-content-analytics.constants.d.ts +28 -8
- package/lib/dotAnalytics/shared/dot-content-analytics.constants.js +12 -8
- package/lib/dotAnalytics/shared/dot-content-analytics.http.d.ts +5 -5
- package/lib/dotAnalytics/shared/dot-content-analytics.http.js +19 -12
- package/lib/dotAnalytics/shared/dot-content-analytics.model.d.ts +303 -88
- package/lib/dotAnalytics/shared/dot-content-analytics.utils.d.ts +86 -29
- package/lib/dotAnalytics/shared/dot-content-analytics.utils.js +118 -41
- package/lib/react/components/DotContentAnalyticsProvider.d.ts +4 -4
- package/lib/react/components/DotContentAnalyticsProvider.js +5 -2
- package/lib/react/contexts/DotContentAnalyticsContext.d.ts +3 -3
- package/lib/react/hook/useContentAnalytics.d.ts +36 -6
- package/lib/react/hook/useContentAnalytics.js +22 -24
- package/lib/react/hook/useRouterTracker.d.ts +3 -3
- package/lib/react/hook/useRouterTracker.js +8 -7
- package/lib/standalone.d.ts +2 -2
- package/package.json +5 -4
- package/types/src/lib/editor/public.js +5 -0
- package/types/src/lib/events/internal.js +4 -0
- package/uve/src/internal/constants.js +3 -0
- package/uve/src/internal/events.js +108 -0
- package/uve/src/lib/core/core.utils.js +21 -0
- package/uve/src/lib/dom/dom.utils.js +81 -0
- package/lib/dotAnalytics/plugin/dot-analytics.enricher.plugin.d.ts +0 -31
- package/lib/dotAnalytics/plugin/dot-analytics.enricher.plugin.js +0 -28
package/README.md
CHANGED
|
@@ -1,159 +1,226 @@
|
|
|
1
|
-
# @dotcms/analytics
|
|
1
|
+
# dotCMS Content Analytics SDK (@dotcms/analytics)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lightweight JavaScript SDK for tracking content-aware events in dotCMS. Works in vanilla JS and React apps. Angular & Vue support coming soon.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 🚀 Quick Start
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- **React Support**: Built-in React components and hooks for seamless integration
|
|
9
|
-
- **Event Tracking**: Simple API to track custom events with additional properties
|
|
10
|
-
- **Automatic PageView**: Option to automatically track page views
|
|
11
|
-
- **Debug Mode**: Optional debug logging for development
|
|
7
|
+
### Vanilla JavaScript
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
**CDN (Script Tag - Auto Page View)**
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<script
|
|
13
|
+
src="ca.min.js"
|
|
14
|
+
data-analytics-server="https://demo.dotcms.com"
|
|
15
|
+
data-analytics-key="SITE_KEY"
|
|
16
|
+
data-analytics-auto-page-view></script>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**npm (ES Module)**
|
|
14
20
|
|
|
15
21
|
```bash
|
|
16
22
|
npm install @dotcms/analytics
|
|
17
23
|
```
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
```javascript
|
|
26
|
+
import { initializeContentAnalytics } from '@dotcms/analytics';
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
const analytics = initializeContentAnalytics({
|
|
29
|
+
siteKey: 'SITE_KEY',
|
|
30
|
+
server: 'https://demo.dotcms.com'
|
|
31
|
+
});
|
|
24
32
|
|
|
25
|
-
|
|
33
|
+
analytics.track('page-loaded');
|
|
34
|
+
```
|
|
26
35
|
|
|
27
|
-
###
|
|
36
|
+
### React
|
|
28
37
|
|
|
29
|
-
|
|
38
|
+
```bash
|
|
39
|
+
npm install @dotcms/analytics
|
|
40
|
+
```
|
|
30
41
|
|
|
31
42
|
```tsx
|
|
32
43
|
import { DotContentAnalyticsProvider } from '@dotcms/analytics/react';
|
|
33
|
-
```
|
|
34
44
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
const analyticsConfig = {
|
|
40
|
-
apiKey: 'your-api-key-from-dotcms-analytics-app',
|
|
41
|
-
server: 'https://your-dotcms-instance.com'
|
|
45
|
+
const config = {
|
|
46
|
+
siteKey: 'SITE_KEY',
|
|
47
|
+
server: 'https://demo.dotcms.com',
|
|
48
|
+
autoPageView: true // Optional, default is true
|
|
42
49
|
};
|
|
43
50
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
<YourApp />
|
|
48
|
-
</DotContentAnalyticsProvider>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
+
<DotContentAnalyticsProvider config={config}>
|
|
52
|
+
<App />
|
|
53
|
+
</DotContentAnalyticsProvider>;
|
|
51
54
|
```
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
## 📘 Core Concepts
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
### Events
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
import { useContentAnalytics } from '@dotcms/analytics/react';
|
|
60
|
+
Track any user action as an event using `track('event-name', { payload })`.
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
const { track } = useContentAnalytics();
|
|
62
|
+
### Page Views
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
// Second parameter: object with properties you want to track
|
|
64
|
+
Tracked automatically (or manually) on route changes.
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
### Sessions
|
|
67
|
+
|
|
68
|
+
- 30-minute timeout
|
|
69
|
+
- Resets at midnight UTC
|
|
70
|
+
- New session if UTM campaign changes
|
|
71
|
+
|
|
72
|
+
### Identity
|
|
73
|
+
|
|
74
|
+
- Anonymous user ID persisted across sessions
|
|
75
|
+
- Stored in `dot_analytics_user_id`
|
|
76
|
+
|
|
77
|
+
## ⚙️ Configuration Options
|
|
78
|
+
|
|
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` | ❌ | `true` | Auto track page views on route changes |
|
|
85
|
+
| `redirectFn` | `function` | ❌ | - | Custom handler for redirects |
|
|
86
|
+
|
|
87
|
+
## 🛠️ Usage Examples
|
|
88
|
+
|
|
89
|
+
### Vanilla JavaScript
|
|
90
|
+
|
|
91
|
+
**Manual Page View & Events**
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
// After init with the <script> tag the dotAnalytics is added to the window.
|
|
95
|
+
window.dotAnalytics.track('cta-click', { button: 'Buy Now' });
|
|
96
|
+
window.dotAnalytics.pageView();
|
|
68
97
|
```
|
|
69
98
|
|
|
70
|
-
|
|
99
|
+
**Advanced: Manual Init with Custom Properties**
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
const analytics = initializeContentAnalytics({
|
|
103
|
+
siteKey: 'abc123',
|
|
104
|
+
server: 'https://your-dotcms.com',
|
|
105
|
+
debug: true,
|
|
106
|
+
autoPageView: false
|
|
107
|
+
});
|
|
71
108
|
|
|
72
|
-
|
|
109
|
+
analytics.track('custom-event', {
|
|
110
|
+
category: 'Marketing',
|
|
111
|
+
value: 'Banner Clicked'
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
analytics.pageView();
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### React
|
|
118
|
+
|
|
119
|
+
**Track Events**
|
|
73
120
|
|
|
74
121
|
```tsx
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
server: 'https://your-dotcms-instance.com',
|
|
78
|
-
autoPageView: false // Disable automatic tracking
|
|
79
|
-
};
|
|
122
|
+
const { track } = useContentAnalytics();
|
|
123
|
+
track('cta-click', { label: 'Download PDF' });
|
|
80
124
|
```
|
|
81
125
|
|
|
82
|
-
|
|
126
|
+
**Manual Page View**
|
|
83
127
|
|
|
84
128
|
```tsx
|
|
85
|
-
|
|
129
|
+
const { pageView } = useContentAnalytics();
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
pageView();
|
|
132
|
+
}, []);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Advanced: Manual Tracking with Router**
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
import { useLocation } from 'react-router-dom';
|
|
139
|
+
const { pageView } = useContentAnalytics();
|
|
140
|
+
const location = useLocation();
|
|
86
141
|
|
|
87
|
-
|
|
88
|
-
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
pageView();
|
|
144
|
+
}, [location]);
|
|
145
|
+
```
|
|
89
146
|
|
|
90
|
-
|
|
91
|
-
pageView({
|
|
92
|
-
// Add any custom properties you want to track
|
|
93
|
-
myCustomValue: '2'
|
|
94
|
-
});
|
|
95
|
-
}, []);
|
|
147
|
+
## API Reference
|
|
96
148
|
|
|
97
|
-
|
|
149
|
+
```typescript
|
|
150
|
+
interface DotCMSAnalytics {
|
|
151
|
+
track: (eventName: string, payload?: Record<string, unknown>) => void;
|
|
152
|
+
pageView: () => void;
|
|
98
153
|
}
|
|
99
154
|
```
|
|
100
155
|
|
|
101
|
-
|
|
156
|
+
**Enriched AnalyticsEvent includes:**
|
|
102
157
|
|
|
103
|
-
|
|
158
|
+
- `context`: siteKey, sessionId, userId
|
|
159
|
+
- `page`: URL, title, referrer, path
|
|
160
|
+
- `device`: screen size, language, viewport
|
|
161
|
+
- `utm`: source, medium, campaign, term, etc.
|
|
104
162
|
|
|
105
|
-
|
|
106
|
-
- **data-analytics-debug**: Enables debug logging
|
|
107
|
-
- **data-analytics-auto-page-view**: Recommended for IIFE implementation. Enables automatic page view tracking
|
|
108
|
-
- **data-analytics-key**: **(Required)** API key for authentication
|
|
163
|
+
## Under the Hood
|
|
109
164
|
|
|
110
|
-
|
|
111
|
-
<!-- Example configuration -->
|
|
112
|
-
<script
|
|
113
|
-
src="ca.min.js"
|
|
114
|
-
data-analytics-server="http://localhost:8080"
|
|
115
|
-
data-analytics-key="dev-key-123"
|
|
116
|
-
data-analytics-auto-page-view
|
|
117
|
-
data-analytics-debug></script>
|
|
165
|
+
### Storage Keys
|
|
118
166
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
167
|
+
- `dot_analytics_user_id`
|
|
168
|
+
- `dot_analytics_session_id`
|
|
169
|
+
- `dot_analytics_session_utm`
|
|
170
|
+
- `dot_analytics_session_start`
|
|
171
|
+
|
|
172
|
+
### Editor Detection
|
|
173
|
+
|
|
174
|
+
Analytics are disabled when inside the dotCMS editor.
|
|
175
|
+
|
|
176
|
+
## Debugging & Troubleshooting
|
|
177
|
+
|
|
178
|
+
**Not seeing events?**
|
|
179
|
+
|
|
180
|
+
- Ensure `siteKey` & `server` are correct
|
|
181
|
+
- Enable debug mode
|
|
182
|
+
- Check network requests to: `https://your-server/api/v1/analytics/content/event`
|
|
183
|
+
- Avoid using inside dotCMS editor (auto-disabled)
|
|
126
184
|
|
|
127
185
|
## Roadmap
|
|
128
186
|
|
|
129
|
-
|
|
187
|
+
- Scroll depth & file download tracking
|
|
188
|
+
- Form interaction analytics
|
|
189
|
+
- Angular & Vue support
|
|
190
|
+
- Realtime dashboard
|
|
191
|
+
|
|
192
|
+
## dotCMS Support
|
|
193
|
+
|
|
194
|
+
We offer multiple channels to get help with the dotCMS React SDK:
|
|
130
195
|
|
|
131
|
-
|
|
132
|
-
|
|
196
|
+
- **GitHub Issues**: For bug reports and feature requests, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository.
|
|
197
|
+
- **Community Forum**: Join our [community discussions](https://community.dotcms.com/) to ask questions and share solutions.
|
|
198
|
+
- **Stack Overflow**: Use the tag `dotcms-react` when posting questions.
|
|
199
|
+
- **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://helpdesk.dotcms.com/support/).
|
|
133
200
|
|
|
134
|
-
|
|
201
|
+
When reporting issues, please include:
|
|
135
202
|
|
|
136
|
-
|
|
203
|
+
- SDK version you're using
|
|
204
|
+
- React version
|
|
205
|
+
- Minimal reproduction steps
|
|
206
|
+
- Expected vs. actual behavior
|
|
137
207
|
|
|
138
|
-
##
|
|
208
|
+
## How To Contribute
|
|
139
209
|
|
|
140
|
-
|
|
210
|
+
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:
|
|
141
211
|
|
|
142
|
-
|
|
212
|
+
1. Fork the repository [dotCMS/core](https://github.com/dotCMS/core)
|
|
213
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
214
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
215
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
216
|
+
5. Open a Pull Request
|
|
143
217
|
|
|
144
|
-
|
|
218
|
+
Please ensure your code follows the existing style and includes appropriate tests.
|
|
145
219
|
|
|
146
|
-
##
|
|
220
|
+
## Licensing Information
|
|
147
221
|
|
|
148
|
-
|
|
222
|
+
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).
|
|
149
223
|
|
|
150
|
-
|
|
224
|
+
This SDK is part of dotCMS's dual-licensed platform (GPL 3.0 for Community, commercial license for Enterprise).
|
|
151
225
|
|
|
152
|
-
|
|
153
|
-
| --------------- | ------------------------------------------------------------------- |
|
|
154
|
-
| Installation | [Installation](https://dotcms.com/docs/latest/installation) |
|
|
155
|
-
| Documentation | [Documentation](https://dotcms.com/docs/latest/table-of-contents) |
|
|
156
|
-
| Videos | [Helpful Videos](http://dotcms.com/videos/) |
|
|
157
|
-
| Forums/Listserv | [via Google Groups](https://groups.google.com/forum/#!forum/dotCMS) |
|
|
158
|
-
| Twitter | @dotCMS |
|
|
159
|
-
| Main Site | [dotCMS.com](https://dotcms.com/) |
|
|
226
|
+
[Learn more ](https://www.dotcms.com)at [dotcms.com](https://www.dotcms.com).
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotCMSAnalytics, DotCMSAnalyticsConfig } from './shared/dot-content-analytics.model';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Creates an analytics instance.
|
|
4
|
+
* Creates an analytics instance for content analytics tracking.
|
|
5
5
|
*
|
|
6
|
-
* @param {
|
|
7
|
-
* @returns {
|
|
6
|
+
* @param {DotCMSAnalyticsConfig} config - The configuration object for the analytics instance.
|
|
7
|
+
* @returns {DotCMSAnalytics} - The analytics instance.
|
|
8
8
|
*/
|
|
9
|
-
export declare const initializeContentAnalytics: (config:
|
|
9
|
+
export declare const initializeContentAnalytics: (config: DotCMSAnalyticsConfig) => DotCMSAnalytics | null;
|
|
@@ -1,24 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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";
|
|
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({
|
|
12
|
+
app: "dotAnalytics",
|
|
13
|
+
debug: n.debug,
|
|
14
|
+
plugins: [
|
|
15
|
+
u(n),
|
|
16
|
+
// Inject identity context (user_id, session_id, local_tz)
|
|
17
|
+
a(),
|
|
18
|
+
// Enrich with page, device, utm data
|
|
19
|
+
l(n)
|
|
20
|
+
// Send events to server
|
|
21
|
+
]
|
|
22
|
+
}), e = () => c();
|
|
23
|
+
return typeof window < "u" && (window.addEventListener("beforeunload", e), window.__dotAnalyticsCleanup = e), {
|
|
5
24
|
/**
|
|
6
25
|
* Track a page view.
|
|
7
26
|
* @param {Record<string, unknown>} payload - The payload to track.
|
|
8
27
|
*/
|
|
9
|
-
pageView: (
|
|
10
|
-
t == null || t.page(
|
|
28
|
+
pageView: (i = {}) => {
|
|
29
|
+
o(), t == null || t.page(i);
|
|
11
30
|
},
|
|
12
31
|
/**
|
|
13
32
|
* Track a custom event.
|
|
14
33
|
* @param {string} eventName - The name of the event to track.
|
|
15
34
|
* @param {Record<string, unknown>} payload - The payload to track.
|
|
16
35
|
*/
|
|
17
|
-
track: (
|
|
18
|
-
t == null || t.track(
|
|
36
|
+
track: (i, r = {}) => {
|
|
37
|
+
o(), t == null || t.track(i, r);
|
|
19
38
|
}
|
|
20
39
|
};
|
|
21
40
|
};
|
|
22
41
|
export {
|
|
23
|
-
|
|
42
|
+
f as initializeContentAnalytics
|
|
24
43
|
};
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotCMSAnalyticsConfig, DotCMSAnalyticsParams } from '../shared/dot-content-analytics.model';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Analytics plugin for tracking page views and custom events in DotCMS applications.
|
|
5
5
|
* This plugin handles sending analytics data to the DotCMS server, managing initialization,
|
|
6
6
|
* and processing both automatic and manual tracking events.
|
|
7
7
|
*
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {DotCMSAnalyticsConfig} config - Configuration object containing API key, server URL,
|
|
9
9
|
* debug mode and auto page view settings
|
|
10
10
|
* @returns {Object} Plugin object with methods for initialization and event tracking
|
|
11
11
|
*/
|
|
12
|
-
export declare const dotAnalytics: (config:
|
|
12
|
+
export declare const dotAnalytics: (config: DotCMSAnalyticsConfig) => {
|
|
13
13
|
name: string;
|
|
14
|
-
config:
|
|
14
|
+
config: DotCMSAnalyticsConfig;
|
|
15
15
|
/**
|
|
16
16
|
* Initialize the plugin
|
|
17
17
|
*/
|
|
18
|
-
initialize: (
|
|
18
|
+
initialize: () => Promise<void>;
|
|
19
19
|
/**
|
|
20
20
|
* Track a page view event
|
|
21
|
+
* Takes enriched data from properties and creates final structured event
|
|
21
22
|
*/
|
|
22
|
-
page: (params:
|
|
23
|
+
page: (params: DotCMSAnalyticsParams) => Promise<void>;
|
|
23
24
|
/**
|
|
24
25
|
* Track a custom event
|
|
26
|
+
* Takes enriched data and sends it to the analytics server
|
|
25
27
|
*/
|
|
26
|
-
track: (params:
|
|
28
|
+
track: (params: DotCMSAnalyticsParams) => Promise<void>;
|
|
27
29
|
/**
|
|
28
30
|
* Check if the plugin is loaded
|
|
29
31
|
*/
|
|
@@ -1,55 +1,79 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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;
|
|
4
5
|
return {
|
|
5
6
|
name: "dot-analytics",
|
|
6
|
-
config:
|
|
7
|
+
config: v,
|
|
7
8
|
/**
|
|
8
9
|
* Initialize the plugin
|
|
9
10
|
*/
|
|
10
|
-
initialize: (
|
|
11
|
-
const { config: i, payload: t } = o;
|
|
12
|
-
if (i.debug && console.warn("DotAnalytics: Initialized with config", i), n = !0, i.autoPageView) {
|
|
13
|
-
const e = {
|
|
14
|
-
...t.properties,
|
|
15
|
-
key: i.apiKey
|
|
16
|
-
};
|
|
17
|
-
return r(e, i);
|
|
18
|
-
}
|
|
19
|
-
return Promise.resolve();
|
|
20
|
-
},
|
|
11
|
+
initialize: () => (r = !0, Promise.resolve()),
|
|
21
12
|
/**
|
|
22
13
|
* Track a page view event
|
|
14
|
+
* Takes enriched data from properties and creates final structured event
|
|
23
15
|
*/
|
|
24
|
-
page: (
|
|
25
|
-
const { config:
|
|
26
|
-
if (!
|
|
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)
|
|
27
19
|
throw new Error("DotAnalytics: Plugin not initialized");
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
]
|
|
31
35
|
};
|
|
32
|
-
return
|
|
36
|
+
return t.debug && console.warn("DotAnalytics: Pageview event to send:", d), c(d, t);
|
|
33
37
|
},
|
|
38
|
+
// TODO: Fix this when we haver the final design for the track event
|
|
34
39
|
/**
|
|
35
40
|
* Track a custom event
|
|
41
|
+
* Takes enriched data and sends it to the analytics server
|
|
36
42
|
*/
|
|
37
|
-
track: (
|
|
38
|
-
const { config:
|
|
39
|
-
if (!
|
|
43
|
+
track: (a) => {
|
|
44
|
+
const { config: t, payload: e } = a;
|
|
45
|
+
if (!r)
|
|
40
46
|
throw new Error("DotAnalytics: Plugin not initialized");
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
]
|
|
44
68
|
};
|
|
45
|
-
return
|
|
69
|
+
return t.debug && console.warn("DotAnalytics: Track event to send (fallback):", n), c(n, t);
|
|
46
70
|
},
|
|
47
71
|
/**
|
|
48
72
|
* Check if the plugin is loaded
|
|
49
73
|
*/
|
|
50
|
-
loaded: () =>
|
|
74
|
+
loaded: () => r
|
|
51
75
|
};
|
|
52
76
|
};
|
|
53
77
|
export {
|
|
54
|
-
|
|
78
|
+
p as dotAnalytics
|
|
55
79
|
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { DotCMSAnalyticsPayload } from '../../shared/dot-content-analytics.model';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Plugin that enriches the analytics payload data based on the event type.
|
|
5
|
+
* Uses Analytics.js lifecycle events to inject context before processing.
|
|
6
|
+
* The identity plugin runs FIRST to inject context: { session_id, site_key, user_id }
|
|
7
|
+
* This enricher plugin runs SECOND to add page/device/utm data.
|
|
8
|
+
*
|
|
9
|
+
* OPTIMIZED: Uses existing payload.properties data to avoid duplication
|
|
10
|
+
*/
|
|
11
|
+
export declare const dotAnalyticsEnricherPlugin: () => {
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* PAGE VIEW ENRICHMENT - Runs after identity context injection
|
|
15
|
+
* Uses optimized enrichment that leverages analytics.js payload data
|
|
16
|
+
*/
|
|
17
|
+
'page:dot-analytics': ({ payload }: {
|
|
18
|
+
payload: DotCMSAnalyticsPayload;
|
|
19
|
+
}) => {
|
|
20
|
+
local_time: string;
|
|
21
|
+
utm?: import('../../shared/dot-content-analytics.model').DotCMSUtmData | undefined;
|
|
22
|
+
page: import('../../shared/dot-content-analytics.model').DotCMSPageData;
|
|
23
|
+
device: import('../../shared/dot-content-analytics.model').DotCMSDeviceData;
|
|
24
|
+
event: string;
|
|
25
|
+
properties: Record<string, unknown>;
|
|
26
|
+
options: Record<string, unknown>;
|
|
27
|
+
context?: import('../../shared/dot-content-analytics.model').DotCMSAnalyticsContext | undefined;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* TRACK EVENT ENRICHMENT - Runs after identity context injection
|
|
31
|
+
* Creates structured track events with pre-injected context
|
|
32
|
+
*/
|
|
33
|
+
'track:dot-analytics': ({ payload }: {
|
|
34
|
+
payload: DotCMSAnalyticsPayload;
|
|
35
|
+
}) => {
|
|
36
|
+
events: {
|
|
37
|
+
event_type: "track";
|
|
38
|
+
local_time: string;
|
|
39
|
+
data: {
|
|
40
|
+
src: string;
|
|
41
|
+
event: string;
|
|
42
|
+
};
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ANALYTICS_SOURCE_TYPE as n, EVENT_TYPES as r } from "../../shared/dot-content-analytics.constants.js";
|
|
2
|
+
import { getLocalTime as a, enrichPagePayloadOptimized as i } from "../../shared/dot-content-analytics.utils.js";
|
|
3
|
+
const l = () => ({
|
|
4
|
+
name: "enrich-dot-analytics",
|
|
5
|
+
/**
|
|
6
|
+
* PAGE VIEW ENRICHMENT - Runs after identity context injection
|
|
7
|
+
* Uses optimized enrichment that leverages analytics.js payload data
|
|
8
|
+
*/
|
|
9
|
+
"page:dot-analytics": ({ payload: e }) => i(e),
|
|
10
|
+
// TODO: Fix this when we haver the final design for the track event
|
|
11
|
+
/**
|
|
12
|
+
* TRACK EVENT ENRICHMENT - Runs after identity context injection
|
|
13
|
+
* Creates structured track events with pre-injected context
|
|
14
|
+
*/
|
|
15
|
+
"track:dot-analytics": ({ payload: e }) => {
|
|
16
|
+
const t = a();
|
|
17
|
+
return {
|
|
18
|
+
events: [
|
|
19
|
+
{
|
|
20
|
+
event_type: r.TRACK,
|
|
21
|
+
local_time: t,
|
|
22
|
+
data: {
|
|
23
|
+
event: e.event,
|
|
24
|
+
...e.properties,
|
|
25
|
+
src: n
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export {
|
|
33
|
+
l as dotAnalyticsEnricherPlugin
|
|
34
|
+
};
|