@dotcms/analytics 1.0.6 → 1.1.1-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 +49 -25
- package/lib/{dotAnalytics → core}/dot-content-analytics.js +6 -6
- package/lib/{dotAnalytics → core}/plugin/enricher/dot-analytics.enricher.plugin.d.ts +1 -1
- package/lib/{dotAnalytics → core}/shared/dot-content-analytics.constants.d.ts +4 -0
- package/lib/{dotAnalytics → core}/shared/dot-content-analytics.model.d.ts +4 -4
- package/lib/{dotAnalytics → core}/shared/dot-content-analytics.utils.d.ts +11 -4
- package/lib/{dotAnalytics → core}/shared/dot-content-analytics.utils.js +3 -3
- package/lib/react/components/DotContentAnalytics.d.ts +1 -1
- package/lib/react/hook/useContentAnalytics.d.ts +2 -2
- package/lib/react/hook/useContentAnalytics.js +3 -3
- package/lib/react/hook/useRouterTracker.d.ts +1 -1
- package/lib/react/internal/utils.d.ts +1 -1
- package/lib/react/internal/utils.js +3 -3
- package/lib/react/public-api.d.ts +1 -1
- package/lib/standalone.d.ts +2 -2
- package/package.json +1 -1
- /package/lib/{dotAnalytics → core}/dot-content-analytics.d.ts +0 -0
- /package/lib/{dotAnalytics → core}/plugin/dot-analytics.plugin.d.ts +0 -0
- /package/lib/{dotAnalytics → core}/plugin/dot-analytics.plugin.js +0 -0
- /package/lib/{dotAnalytics → core}/plugin/enricher/dot-analytics.enricher.plugin.js +0 -0
- /package/lib/{dotAnalytics → core}/plugin/identity/dot-analytics.identity.plugin.d.ts +0 -0
- /package/lib/{dotAnalytics → core}/plugin/identity/dot-analytics.identity.plugin.js +0 -0
- /package/lib/{dotAnalytics → core}/plugin/identity/dot-analytics.identity.utils.d.ts +0 -0
- /package/lib/{dotAnalytics → core}/shared/dot-content-analytics.activity-tracker.d.ts +0 -0
- /package/lib/{dotAnalytics → core}/shared/dot-content-analytics.activity-tracker.js +0 -0
- /package/lib/{dotAnalytics → core}/shared/dot-content-analytics.constants.js +0 -0
- /package/lib/{dotAnalytics → core}/shared/dot-content-analytics.http.d.ts +0 -0
- /package/lib/{dotAnalytics → core}/shared/dot-content-analytics.http.js +0 -0
package/README.md
CHANGED
|
@@ -4,16 +4,15 @@ Lightweight JavaScript SDK for tracking content-aware events in dotCMS. Works in
|
|
|
4
4
|
|
|
5
5
|
## 🚀 Quick Start
|
|
6
6
|
|
|
7
|
-
###
|
|
8
|
-
|
|
9
|
-
**CDN (Script Tag - Auto Page View)**
|
|
7
|
+
### Standalone (Script Tag)
|
|
10
8
|
|
|
11
9
|
```html
|
|
12
10
|
<script
|
|
13
11
|
src="ca.min.js"
|
|
14
|
-
data-server="https://demo.dotcms.com"
|
|
15
|
-
data-
|
|
16
|
-
data-auto-page-view
|
|
12
|
+
data-analytics-server="https://demo.dotcms.com"
|
|
13
|
+
data-analytics-auth="SITE_AUTH"
|
|
14
|
+
data-analytics-auto-page-view="true"
|
|
15
|
+
data-analytics-debug="false"></script>
|
|
17
16
|
```
|
|
18
17
|
|
|
19
18
|
**npm (ES Module)**
|
|
@@ -26,7 +25,7 @@ npm install @dotcms/analytics
|
|
|
26
25
|
import { initializeContentAnalytics } from '@dotcms/analytics';
|
|
27
26
|
|
|
28
27
|
const analytics = initializeContentAnalytics({
|
|
29
|
-
|
|
28
|
+
siteAuth: 'SITE_AUTH',
|
|
30
29
|
server: 'https://demo.dotcms.com'
|
|
31
30
|
});
|
|
32
31
|
|
|
@@ -40,17 +39,17 @@ npm install @dotcms/analytics
|
|
|
40
39
|
```
|
|
41
40
|
|
|
42
41
|
```tsx
|
|
43
|
-
import {
|
|
42
|
+
import { DotContentAnalytics } from '@dotcms/analytics/react';
|
|
44
43
|
|
|
45
44
|
const config = {
|
|
46
|
-
|
|
45
|
+
siteAuth: 'SITE_AUTH',
|
|
47
46
|
server: 'https://demo.dotcms.com',
|
|
48
|
-
autoPageView: true // Optional, default is true
|
|
47
|
+
autoPageView: true // Optional, default is true in React
|
|
49
48
|
};
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
<
|
|
53
|
-
|
|
50
|
+
export function AppRoot() {
|
|
51
|
+
return <DotContentAnalytics config={config} />;
|
|
52
|
+
}
|
|
54
53
|
```
|
|
55
54
|
|
|
56
55
|
## 📘 Core Concepts
|
|
@@ -61,7 +60,8 @@ Track any user action as an event using `track('event-name', { payload })`.
|
|
|
61
60
|
|
|
62
61
|
### Page Views
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
- React: Automatically tracked on route changes when using `DotContentAnalytics`.
|
|
64
|
+
- Standalone: Auto-tracked only if `data-analytics-auto-page-view="true"`; otherwise call `window.dotAnalytics.pageView()`.
|
|
65
65
|
|
|
66
66
|
### Sessions
|
|
67
67
|
|
|
@@ -76,13 +76,12 @@ Tracked automatically (or manually) on route changes.
|
|
|
76
76
|
|
|
77
77
|
## ⚙️ Configuration Options
|
|
78
78
|
|
|
79
|
-
| Option | Type
|
|
80
|
-
| -------------- |
|
|
81
|
-
| `
|
|
82
|
-
| `server` | `string`
|
|
83
|
-
| `debug` | `boolean`
|
|
84
|
-
| `autoPageView` | `boolean`
|
|
85
|
-
| `redirectFn` | `function` | ❌ | - | Custom handler for redirects |
|
|
79
|
+
| Option | Type | Required | Default | Description |
|
|
80
|
+
| -------------- | --------- | -------- | ----------------------------------- | -------------------------------------- |
|
|
81
|
+
| `siteAuth` | `string` | ✅ | - | Site auth from dotCMS Analytics app |
|
|
82
|
+
| `server` | `string` | ✅ | - | Your dotCMS server URL |
|
|
83
|
+
| `debug` | `boolean` | ❌ | `false` | Enable verbose logging |
|
|
84
|
+
| `autoPageView` | `boolean` | ❌ | React: `true` / Standalone: `false` | Auto track page views on route changes |
|
|
86
85
|
|
|
87
86
|
## 🛠️ Usage Examples
|
|
88
87
|
|
|
@@ -100,7 +99,7 @@ window.dotAnalytics.pageView();
|
|
|
100
99
|
|
|
101
100
|
```javascript
|
|
102
101
|
const analytics = initializeContentAnalytics({
|
|
103
|
-
|
|
102
|
+
siteAuth: 'abc123',
|
|
104
103
|
server: 'https://your-dotcms.com',
|
|
105
104
|
debug: true,
|
|
106
105
|
autoPageView: false
|
|
@@ -119,14 +118,25 @@ analytics.pageView();
|
|
|
119
118
|
**Track Events**
|
|
120
119
|
|
|
121
120
|
```tsx
|
|
122
|
-
|
|
121
|
+
import { useContentAnalytics } from '@dotcms/analytics/react';
|
|
122
|
+
|
|
123
|
+
const { track } = useContentAnalytics({
|
|
124
|
+
siteAuth: 'SITE_AUTH',
|
|
125
|
+
server: 'https://demo.dotcms.com'
|
|
126
|
+
});
|
|
127
|
+
|
|
123
128
|
track('cta-click', { label: 'Download PDF' });
|
|
124
129
|
```
|
|
125
130
|
|
|
126
131
|
**Manual Page View**
|
|
127
132
|
|
|
128
133
|
```tsx
|
|
129
|
-
|
|
134
|
+
import { useContentAnalytics } from '@dotcms/analytics/react';
|
|
135
|
+
|
|
136
|
+
const { pageView } = useContentAnalytics({
|
|
137
|
+
siteAuth: 'SITE_AUTH',
|
|
138
|
+
server: 'https://demo.dotcms.com'
|
|
139
|
+
});
|
|
130
140
|
useEffect(() => {
|
|
131
141
|
pageView();
|
|
132
142
|
}, []);
|
|
@@ -135,8 +145,15 @@ useEffect(() => {
|
|
|
135
145
|
**Advanced: Manual Tracking with Router**
|
|
136
146
|
|
|
137
147
|
```tsx
|
|
148
|
+
// Next.js App Router is automatically tracked by <DotContentAnalytics />
|
|
149
|
+
// For other routers, you can call pageView on location change
|
|
138
150
|
import { useLocation } from 'react-router-dom';
|
|
139
|
-
|
|
151
|
+
import { useContentAnalytics } from '@dotcms/analytics/react';
|
|
152
|
+
|
|
153
|
+
const { pageView } = useContentAnalytics({
|
|
154
|
+
siteAuth: 'SITE_AUTH',
|
|
155
|
+
server: 'https://demo.dotcms.com'
|
|
156
|
+
});
|
|
140
157
|
const location = useLocation();
|
|
141
158
|
|
|
142
159
|
useEffect(() => {
|
|
@@ -182,6 +199,13 @@ Analytics are disabled when inside the dotCMS editor.
|
|
|
182
199
|
- Check network requests to: `https://your-server/api/v1/analytics/content/event`
|
|
183
200
|
- Avoid using inside dotCMS editor (auto-disabled)
|
|
184
201
|
|
|
202
|
+
Standalone attributes to verify:
|
|
203
|
+
|
|
204
|
+
- `data-analytics-auth` (required)
|
|
205
|
+
- `data-analytics-server` (optional, defaults to current origin)
|
|
206
|
+
- `data-analytics-auto-page-view` (`true` to enable)
|
|
207
|
+
- `data-analytics-debug` (`true` to enable)
|
|
208
|
+
|
|
185
209
|
## Roadmap
|
|
186
210
|
|
|
187
211
|
- Scroll depth & file download tracking
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { Analytics as s } from "analytics";
|
|
2
2
|
import { dotAnalytics as l } from "./plugin/dot-analytics.plugin.js";
|
|
3
|
-
import { dotAnalyticsEnricherPlugin as
|
|
4
|
-
import { dotAnalyticsIdentityPlugin as
|
|
3
|
+
import { dotAnalyticsEnricherPlugin as u } from "./plugin/enricher/dot-analytics.enricher.plugin.js";
|
|
4
|
+
import { dotAnalyticsIdentityPlugin as a } from "./plugin/identity/dot-analytics.identity.plugin.js";
|
|
5
5
|
import { cleanupActivityTracking as c, updateSessionActivity as o } from "./shared/dot-content-analytics.activity-tracker.js";
|
|
6
6
|
const f = (n) => {
|
|
7
|
-
if (!n.
|
|
8
|
-
return console.error('DotContentAnalytics: Missing "
|
|
7
|
+
if (!n.siteAuth)
|
|
8
|
+
return console.error('DotContentAnalytics: Missing "siteAuth" in configuration'), null;
|
|
9
9
|
if (!n.server)
|
|
10
10
|
return console.error('DotContentAnalytics: Missing "server" in configuration'), null;
|
|
11
11
|
const t = s({
|
|
12
12
|
app: "dotAnalytics",
|
|
13
13
|
debug: n.debug,
|
|
14
14
|
plugins: [
|
|
15
|
-
|
|
15
|
+
a(n),
|
|
16
16
|
// Inject identity context (user_id, session_id, local_tz)
|
|
17
|
-
|
|
17
|
+
u(),
|
|
18
18
|
// Enrich with page, device, utm data
|
|
19
19
|
l(n)
|
|
20
20
|
// Send events to server
|
|
@@ -2,7 +2,7 @@ import { DotCMSAnalyticsPayload } from '../../shared/dot-content-analytics.model
|
|
|
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,
|
|
5
|
+
* The identity plugin runs FIRST to inject context: { session_id, site_auth, user_id }
|
|
6
6
|
* This enricher plugin runs SECOND to add page/device/utm data.
|
|
7
7
|
*
|
|
8
8
|
* OPTIMIZED: Uses existing payload.properties data to avoid duplication
|
|
@@ -31,3 +31,7 @@ export declare const USER_ID_KEY = "dot_analytics_user_id";
|
|
|
31
31
|
* - visibilitychange: Handled separately to detect tab changes
|
|
32
32
|
*/
|
|
33
33
|
export declare const ACTIVITY_EVENTS: readonly ["click"];
|
|
34
|
+
/**
|
|
35
|
+
* The name of the analytics minified script.
|
|
36
|
+
*/
|
|
37
|
+
export declare const ANALYTICS_MINIFIED_SCRIPT_NAME = "ca.min.js";
|
|
@@ -22,9 +22,9 @@ export interface DotCMSAnalyticsConfig {
|
|
|
22
22
|
*/
|
|
23
23
|
autoPageView?: boolean;
|
|
24
24
|
/**
|
|
25
|
-
* The site
|
|
25
|
+
* The site auth for authenticating with the Analytics service.
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
siteAuth: string;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Supported event types in DotCMS Analytics.
|
|
@@ -198,8 +198,8 @@ export interface DotCMSAnalytics {
|
|
|
198
198
|
* continuity across multiple analytics events.
|
|
199
199
|
*/
|
|
200
200
|
export interface DotCMSAnalyticsContext {
|
|
201
|
-
/** The site
|
|
202
|
-
|
|
201
|
+
/** The site auth for the DotCMS instance */
|
|
202
|
+
site_auth: string;
|
|
203
203
|
/** Unique session identifier */
|
|
204
204
|
session_id: string;
|
|
205
205
|
/** Unique user identifier */
|
|
@@ -31,13 +31,20 @@ export declare const getSessionId: () => string;
|
|
|
31
31
|
*/
|
|
32
32
|
export declare const getAnalyticsContext: (config: DotCMSAnalyticsConfig) => DotCMSAnalyticsContext;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* Configuration result with warnings for analytics setup
|
|
35
35
|
*/
|
|
36
|
-
export
|
|
36
|
+
export interface AnalyticsConfigResult {
|
|
37
|
+
config: DotCMSAnalyticsConfig;
|
|
38
|
+
warnings?: string[];
|
|
39
|
+
missingAttributes?: string[];
|
|
40
|
+
hasIssues: boolean;
|
|
41
|
+
}
|
|
37
42
|
/**
|
|
38
|
-
* Gets
|
|
43
|
+
* Gets analytics configuration, always returns a config (with defaults if needed)
|
|
44
|
+
* - If no data-analytics-server attribute is found, uses the current domain as the server endpoint
|
|
45
|
+
* - Both debug and autoPageView default to false (must be explicitly set to "true")
|
|
39
46
|
*/
|
|
40
|
-
export declare const
|
|
47
|
+
export declare const getAnalyticsConfig: () => DotCMSAnalyticsConfig;
|
|
41
48
|
/**
|
|
42
49
|
* Retrieves the browser event data - optimized but accurate.
|
|
43
50
|
*/
|
|
@@ -55,13 +55,13 @@ const u = (t) => {
|
|
|
55
55
|
} catch {
|
|
56
56
|
return u("session_fallback");
|
|
57
57
|
}
|
|
58
|
-
},
|
|
58
|
+
}, y = (t) => {
|
|
59
59
|
const e = p(), n = f();
|
|
60
60
|
return t.debug && console.warn("DotAnalytics Identity Context:", {
|
|
61
61
|
sessionId: e,
|
|
62
62
|
userId: n
|
|
63
63
|
}), {
|
|
64
|
-
|
|
64
|
+
site_auth: t.siteAuth,
|
|
65
65
|
session_id: e,
|
|
66
66
|
user_id: n
|
|
67
67
|
};
|
|
@@ -116,7 +116,7 @@ const u = (t) => {
|
|
|
116
116
|
export {
|
|
117
117
|
$ as enrichPagePayloadOptimized,
|
|
118
118
|
u as generateSecureId,
|
|
119
|
-
|
|
119
|
+
y as getAnalyticsContext,
|
|
120
120
|
D as getLocalTime,
|
|
121
121
|
p as getSessionId,
|
|
122
122
|
f as getUserId
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { DotCMSAnalyticsConfig } from '../../
|
|
2
|
+
import { DotCMSAnalyticsConfig } from '../../core/shared/dot-content-analytics.model';
|
|
3
3
|
/**
|
|
4
4
|
* Client bootstrapper for dotCMS Analytics in React/Next.
|
|
5
5
|
* - No UI: initializes the analytics singleton from props or env config.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DotCMSAnalytics, DotCMSAnalyticsConfig } from '../../
|
|
1
|
+
import { DotCMSAnalytics, DotCMSAnalyticsConfig } from '../../core/shared/dot-content-analytics.model';
|
|
2
2
|
/**
|
|
3
3
|
* Custom hook that handles analytics tracking for anonymous users.
|
|
4
4
|
* Provides methods to track events and page views with automatic timestamp injection.
|
|
@@ -9,7 +9,7 @@ import { DotCMSAnalytics, DotCMSAnalyticsConfig } from '../../dotAnalytics/share
|
|
|
9
9
|
* function Button({ title, urlTitle }) {
|
|
10
10
|
* const { track } = useContentAnalytics({
|
|
11
11
|
* server: 'https://demo.dotcms.com',
|
|
12
|
-
*
|
|
12
|
+
* siteAuth: 'my-site-auth',
|
|
13
13
|
* debug: false
|
|
14
14
|
* });
|
|
15
15
|
*
|
|
@@ -2,11 +2,11 @@ import { useRef as l, useCallback as n } from "react";
|
|
|
2
2
|
import { getUVEState as r } from "../../../uve/src/lib/core/core.utils.js";
|
|
3
3
|
import "../../../uve/src/internal/constants.js";
|
|
4
4
|
import { initializeAnalytics as f } from "../internal/utils.js";
|
|
5
|
-
const
|
|
5
|
+
const h = (o) => {
|
|
6
6
|
const t = f(o), i = l(null);
|
|
7
7
|
if (!t)
|
|
8
8
|
throw new Error(
|
|
9
|
-
"Failed to initialize DotContentAnalytics. Please verify the required configuration (server and
|
|
9
|
+
"Failed to initialize DotContentAnalytics. Please verify the required configuration (server and siteAuth)."
|
|
10
10
|
);
|
|
11
11
|
const a = n(
|
|
12
12
|
(e, s = {}) => {
|
|
@@ -28,5 +28,5 @@ const g = (o) => {
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
export {
|
|
31
|
-
|
|
31
|
+
h as useContentAnalytics
|
|
32
32
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DotCMSAnalytics } from '../../
|
|
1
|
+
import { DotCMSAnalytics } from '../../core/shared/dot-content-analytics.model';
|
|
2
2
|
/**
|
|
3
3
|
* Tracks page views on route changes using Next.js App Router signals.
|
|
4
4
|
* - Fires a single pageView per unique path+search.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DotCMSAnalytics, DotCMSAnalyticsConfig } from '../../
|
|
1
|
+
import { DotCMSAnalytics, DotCMSAnalyticsConfig } from '../../core/shared/dot-content-analytics.model';
|
|
2
2
|
/**
|
|
3
3
|
* Initializes analytics with explicit configuration.
|
|
4
4
|
* Resets singleton if config changes.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { initializeContentAnalytics as r } from "../../
|
|
2
|
-
let
|
|
3
|
-
const s = (
|
|
1
|
+
import { initializeContentAnalytics as r } from "../../core/dot-content-analytics.js";
|
|
2
|
+
let t, i;
|
|
3
|
+
const s = (e) => (i && (i.server !== e.server || i.siteAuth !== e.siteAuth) && (t = void 0), t !== void 0 || (i = e, t = r(e)), t);
|
|
4
4
|
export {
|
|
5
5
|
s as initializeAnalytics
|
|
6
6
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { DotCMSAnalyticsConfig } from '../
|
|
1
|
+
export type { DotCMSAnalyticsConfig } from '../core/shared/dot-content-analytics.model';
|
|
2
2
|
export { DotContentAnalytics } from './components/DotContentAnalytics';
|
|
3
3
|
export { useContentAnalytics } from './hook/useContentAnalytics';
|
package/lib/standalone.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ANALYTICS_WINDOWS_KEY } from './
|
|
2
|
-
import { DotCMSAnalytics } from './
|
|
1
|
+
import { ANALYTICS_WINDOWS_KEY } from './core/shared/dot-content-analytics.constants';
|
|
2
|
+
import { DotCMSAnalytics } from './core/shared/dot-content-analytics.model';
|
|
3
3
|
declare global {
|
|
4
4
|
interface Window {
|
|
5
5
|
[ANALYTICS_WINDOWS_KEY]: DotCMSAnalytics | null;
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|