@dotcms/analytics 1.0.6 → 1.1.1
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 +46 -22
- package/lib/{dotAnalytics → core}/shared/dot-content-analytics.constants.d.ts +4 -0
- package/lib/{dotAnalytics → core}/shared/dot-content-analytics.utils.d.ts +11 -4
- package/lib/react/components/DotContentAnalytics.d.ts +1 -1
- package/lib/react/hook/useContentAnalytics.d.ts +1 -1
- package/lib/react/hook/useRouterTracker.d.ts +1 -1
- package/lib/react/internal/utils.d.ts +1 -1
- package/lib/react/internal/utils.js +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/{dotAnalytics → core}/dot-content-analytics.d.ts +0 -0
- /package/lib/{dotAnalytics → core}/dot-content-analytics.js +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.d.ts +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/lib/{dotAnalytics → core}/shared/dot-content-analytics.model.d.ts +0 -0
- /package/lib/{dotAnalytics → core}/shared/dot-content-analytics.utils.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_KEY"
|
|
14
|
+
data-analytics-auto-page-view="true"
|
|
15
|
+
data-analytics-debug="false"></script>
|
|
17
16
|
```
|
|
18
17
|
|
|
19
18
|
**npm (ES Module)**
|
|
@@ -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
|
siteKey: 'SITE_KEY',
|
|
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
|
-
| `siteKey` | `string`
|
|
82
|
-
| `server` | `string`
|
|
83
|
-
| `debug` | `boolean`
|
|
84
|
-
| `autoPageView` | `boolean`
|
|
85
|
-
| `redirectFn` | `function` | ❌ | - | Custom handler for redirects |
|
|
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` | ❌ | React: `true` / Standalone: `false` | Auto track page views on route changes |
|
|
86
85
|
|
|
87
86
|
## 🛠️ Usage Examples
|
|
88
87
|
|
|
@@ -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
|
+
siteKey: 'SITE_KEY',
|
|
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
|
+
siteKey: 'SITE_KEY',
|
|
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
|
+
siteKey: 'SITE_KEY',
|
|
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
|
|
@@ -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";
|
|
@@ -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
|
*/
|
|
@@ -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.
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import { initializeContentAnalytics as r } from "../../
|
|
1
|
+
import { initializeContentAnalytics as r } from "../../core/dot-content-analytics.js";
|
|
2
2
|
let e, t;
|
|
3
3
|
const s = (i) => (t && (t.server !== i.server || t.siteKey !== i.siteKey) && (e = void 0), e !== void 0 || (t = i, e = r(i)), e);
|
|
4
4
|
export {
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|