@dotcms/analytics 0.0.1-beta.9 → 1.0.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.
Files changed (36) hide show
  1. package/README.md +167 -100
  2. package/lib/dotAnalytics/dot-content-analytics.d.ts +5 -5
  3. package/lib/dotAnalytics/dot-content-analytics.js +28 -9
  4. package/lib/dotAnalytics/plugin/dot-analytics.plugin.d.ts +9 -7
  5. package/lib/dotAnalytics/plugin/dot-analytics.plugin.js +55 -31
  6. package/lib/dotAnalytics/plugin/enricher/dot-analytics.enricher.plugin.d.ts +45 -0
  7. package/lib/dotAnalytics/plugin/enricher/dot-analytics.enricher.plugin.js +34 -0
  8. package/lib/dotAnalytics/plugin/identity/dot-analytics.identity.plugin.d.ts +80 -0
  9. package/lib/dotAnalytics/plugin/identity/dot-analytics.identity.plugin.js +40 -0
  10. package/lib/dotAnalytics/plugin/identity/dot-analytics.identity.utils.d.ts +24 -0
  11. package/lib/dotAnalytics/shared/dot-content-analytics.activity-tracker.d.ts +29 -0
  12. package/lib/dotAnalytics/shared/dot-content-analytics.activity-tracker.js +86 -0
  13. package/lib/dotAnalytics/shared/dot-content-analytics.constants.d.ts +28 -8
  14. package/lib/dotAnalytics/shared/dot-content-analytics.constants.js +12 -8
  15. package/lib/dotAnalytics/shared/dot-content-analytics.http.d.ts +5 -5
  16. package/lib/dotAnalytics/shared/dot-content-analytics.http.js +19 -12
  17. package/lib/dotAnalytics/shared/dot-content-analytics.model.d.ts +303 -88
  18. package/lib/dotAnalytics/shared/dot-content-analytics.utils.d.ts +86 -29
  19. package/lib/dotAnalytics/shared/dot-content-analytics.utils.js +118 -41
  20. package/lib/react/components/DotContentAnalyticsProvider.d.ts +4 -4
  21. package/lib/react/components/DotContentAnalyticsProvider.js +5 -2
  22. package/lib/react/contexts/DotContentAnalyticsContext.d.ts +3 -3
  23. package/lib/react/hook/useContentAnalytics.d.ts +36 -6
  24. package/lib/react/hook/useContentAnalytics.js +22 -24
  25. package/lib/react/hook/useRouterTracker.d.ts +3 -3
  26. package/lib/react/hook/useRouterTracker.js +8 -7
  27. package/lib/standalone.d.ts +2 -2
  28. package/package.json +5 -4
  29. package/types/src/lib/editor/public.js +5 -0
  30. package/types/src/lib/events/internal.js +4 -0
  31. package/uve/src/internal/constants.js +3 -0
  32. package/uve/src/internal/events.js +108 -0
  33. package/uve/src/lib/core/core.utils.js +21 -0
  34. package/uve/src/lib/dom/dom.utils.js +81 -0
  35. package/lib/dotAnalytics/plugin/dot-analytics.enricher.plugin.d.ts +0 -31
  36. 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
- `@dotcms/analytics` is the official dotCMS JavaScript library for Content Analytics that helps track events and analytics in your webapps. Available for both browser and React applications.
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
- ## Features
5
+ ## 🚀 Quick Start
6
6
 
7
- - **Simple Browser Integration**: Easy to implement via script tags using IIFE implementation
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
- ## Installation
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
- Or include the script in your HTML page:
25
+ ```javascript
26
+ import { initializeContentAnalytics } from '@dotcms/analytics';
20
27
 
21
- ```html
22
- <script src="ca.min.js"></script>
23
- ```
28
+ const analytics = initializeContentAnalytics({
29
+ siteKey: 'SITE_KEY',
30
+ server: 'https://demo.dotcms.com'
31
+ });
24
32
 
25
- ## React Integration
33
+ analytics.track('page-loaded');
34
+ ```
26
35
 
27
- ### Provider Setup
36
+ ### React
28
37
 
29
- First, import the provider:
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
- Wrap your application with the `DotContentAnalyticsProvider`:
36
-
37
- ```tsx
38
- // Example configuration
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
- function App() {
45
- return (
46
- <DotContentAnalyticsProvider config={analyticsConfig}>
47
- <YourApp />
48
- </DotContentAnalyticsProvider>
49
- );
50
- }
51
+ <DotContentAnalyticsProvider config={config}>
52
+ <App />
53
+ </DotContentAnalyticsProvider>;
51
54
  ```
52
55
 
53
- ### Tracking Custom Events
56
+ ## 📘 Core Concepts
54
57
 
55
- Use the `useContentAnalytics` hook to track custom events:
58
+ ### Events
56
59
 
57
- ```tsx
58
- import { useContentAnalytics } from '@dotcms/analytics/react';
60
+ Track any user action as an event using `track('event-name', { payload })`.
59
61
 
60
- function Activity({ title, urlTitle }) {
61
- const { track } = useContentAnalytics();
62
+ ### Page Views
62
63
 
63
- // First parameter: custom event name to identify the action
64
- // Second parameter: object with properties you want to track
64
+ Tracked automatically (or manually) on route changes.
65
65
 
66
- return <button onClick={() => track('btn-click', { title, urlTitle })}>See Details →</button>;
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
- ### Manual Page View Tracking
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
- To manually track page views, first disable automatic tracking in your config:
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 analyticsConfig = {
76
- apiKey: 'your-api-key-from-dotcms-analytics-app',
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
- Then use the `useContentAnalytics` hook in your layout component:
126
+ **Manual Page View**
83
127
 
84
128
  ```tsx
85
- import { useContentAnalytics } from '@dotcms/analytics/react';
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
- function Layout({ children }) {
88
- const { pageView } = useContentAnalytics();
142
+ useEffect(() => {
143
+ pageView();
144
+ }, [location]);
145
+ ```
89
146
 
90
- useEffect(() => {
91
- pageView({
92
- // Add any custom properties you want to track
93
- myCustomValue: '2'
94
- });
95
- }, []);
147
+ ## API Reference
96
148
 
97
- return <div>{children}</div>;
149
+ ```typescript
150
+ interface DotCMSAnalytics {
151
+ track: (eventName: string, payload?: Record<string, unknown>) => void;
152
+ pageView: () => void;
98
153
  }
99
154
  ```
100
155
 
101
- ## Browser Configuration
156
+ **Enriched AnalyticsEvent includes:**
102
157
 
103
- The script can be configured using data attributes:
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
- - **data-analytics-server**: URL of the server where events will be sent. If not provided, the current domain will be used
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
- ```html
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
- <!-- Without automatic tracking - events must be sent manually -->
120
- <script
121
- src="ca.min.js"
122
- data-analytics-server="http://localhost:8080"
123
- data-analytics-debug
124
- data-analytics-key="dev-key-123"></script>
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
- The following features are planned for future releases:
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
- 2. **Headless Support**
132
- - Angular integration for event tracking
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
- ## Contributing
201
+ When reporting issues, please include:
135
202
 
136
- GitHub pull requests are the preferred method to contribute code to dotCMS. Before any pull requests can be accepted, an automated tool will ask you to agree to the [dotCMS Contributor's Agreement](https://gist.github.com/wezell/85ef45298c48494b90d92755b583acb3).
203
+ - SDK version you're using
204
+ - React version
205
+ - Minimal reproduction steps
206
+ - Expected vs. actual behavior
137
207
 
138
- ## Licensing
208
+ ## How To Contribute
139
209
 
140
- 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 a number of enterprise features and is available via a supported, indemnified commercial license from dotCMS. For the differences between the editions, see [the feature page](http://dotcms.com/cms-platform/features).
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
- ## Support
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
- If you need help or have any questions, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository.
218
+ Please ensure your code follows the existing style and includes appropriate tests.
145
219
 
146
- ## Documentation
220
+ ## Licensing Information
147
221
 
148
- Always refer to the official [DotCMS documentation](https://www.dotcms.com/docs/latest/) for comprehensive guides and API references.
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
- ## Getting Help
224
+ This SDK is part of dotCMS's dual-licensed platform (GPL 3.0 for Community, commercial license for Enterprise).
151
225
 
152
- | Source | Location |
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 { DotAnalytics, DotContentAnalyticsConfig } from './shared/dot-content-analytics.model';
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 {DotContentAnalyticsConfig} config - The configuration object for the analytics instance.
7
- * @returns {DotAnalytics} - The analytics instance.
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: DotContentAnalyticsConfig) => DotAnalytics;
9
+ export declare const initializeContentAnalytics: (config: DotCMSAnalyticsConfig) => DotCMSAnalytics | null;
@@ -1,24 +1,43 @@
1
- import { createAnalyticsInstance as o } from "./shared/dot-content-analytics.utils.js";
2
- const i = (r) => {
3
- const t = o(r);
4
- return {
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: (e = {}) => {
10
- t == null || t.page(e);
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: (e, n = {}) => {
18
- t == null || t.track(e, n);
36
+ track: (i, r = {}) => {
37
+ o(), t == null || t.track(i, r);
19
38
  }
20
39
  };
21
40
  };
22
41
  export {
23
- i as initializeContentAnalytics
42
+ f as initializeContentAnalytics
24
43
  };
@@ -1,29 +1,31 @@
1
- import { DotAnalyticsParams, DotContentAnalyticsConfig } from '../shared/dot-content-analytics.model';
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 {DotAnalyticsConfig} config - Configuration object containing API key, server URL,
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: DotContentAnalyticsConfig) => {
12
+ export declare const dotAnalytics: (config: DotCMSAnalyticsConfig) => {
13
13
  name: string;
14
- config: DotContentAnalyticsConfig;
14
+ config: DotCMSAnalyticsConfig;
15
15
  /**
16
16
  * Initialize the plugin
17
17
  */
18
- initialize: (params: DotAnalyticsParams) => Promise<void>;
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: DotAnalyticsParams) => Promise<void>;
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: DotAnalyticsParams) => Promise<void>;
28
+ track: (params: DotCMSAnalyticsParams) => Promise<void>;
27
29
  /**
28
30
  * Check if the plugin is loaded
29
31
  */
@@ -1,55 +1,79 @@
1
- import { sendAnalyticsEventToServer as r } from "../shared/dot-content-analytics.http.js";
2
- const s = (a) => {
3
- let n = !1;
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: a,
7
+ config: v,
7
8
  /**
8
9
  * Initialize the plugin
9
10
  */
10
- initialize: (o) => {
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: (o) => {
25
- const { config: i, payload: t } = o;
26
- if (!n)
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
- const e = {
29
- ...t.properties,
30
- key: i.apiKey
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 r(e, i);
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: (o) => {
38
- const { config: i, payload: t } = o;
39
- if (!n)
43
+ track: (a) => {
44
+ const { config: t, payload: e } = a;
45
+ if (!r)
40
46
  throw new Error("DotAnalytics: Plugin not initialized");
41
- const e = {
42
- ...t.properties,
43
- key: i.apiKey
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 r(e, i);
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: () => n
74
+ loaded: () => r
51
75
  };
52
76
  };
53
77
  export {
54
- s as dotAnalytics
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
+ };