@dotcms/analytics 1.1.1-next.1 → 1.1.1-next.3

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 (35) hide show
  1. package/README.md +220 -65
  2. package/lib/core/dot-content-analytics.d.ts +1 -1
  3. package/lib/core/dot-content-analytics.js +26 -24
  4. package/lib/core/plugin/dot-analytics.plugin.d.ts +3 -3
  5. package/lib/core/plugin/dot-analytics.plugin.js +25 -57
  6. package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.d.ts +11 -27
  7. package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.js +38 -15
  8. package/lib/core/plugin/identity/dot-analytics.identity.plugin.d.ts +11 -11
  9. package/lib/core/plugin/identity/dot-analytics.identity.plugin.js +13 -11
  10. package/lib/core/plugin/identity/dot-analytics.identity.utils.d.ts +7 -6
  11. package/lib/core/shared/{dot-content-analytics.constants.d.ts → constants/dot-content-analytics.constants.d.ts} +22 -5
  12. package/lib/core/shared/constants/dot-content-analytics.constants.js +28 -0
  13. package/lib/core/shared/constants/index.d.ts +4 -0
  14. package/lib/core/shared/dot-content-analytics.activity-tracker.d.ts +1 -1
  15. package/lib/core/shared/dot-content-analytics.activity-tracker.js +1 -1
  16. package/lib/core/shared/dot-content-analytics.http.d.ts +2 -2
  17. package/lib/core/shared/dot-content-analytics.http.js +10 -9
  18. package/lib/core/shared/dot-content-analytics.utils.d.ts +82 -44
  19. package/lib/core/shared/dot-content-analytics.utils.js +86 -73
  20. package/lib/core/shared/models/data.model.d.ts +101 -0
  21. package/lib/core/shared/models/event.model.d.ts +66 -0
  22. package/lib/core/shared/models/index.d.ts +12 -0
  23. package/lib/core/shared/models/library.model.d.ts +176 -0
  24. package/lib/core/shared/models/request.model.d.ts +24 -0
  25. package/lib/react/components/DotContentAnalytics.d.ts +1 -1
  26. package/lib/react/hook/useContentAnalytics.d.ts +43 -15
  27. package/lib/react/hook/useContentAnalytics.js +18 -21
  28. package/lib/react/hook/useRouterTracker.d.ts +1 -1
  29. package/lib/react/internal/utils.d.ts +1 -1
  30. package/lib/react/internal/utils.js +2 -2
  31. package/lib/react/public-api.d.ts +1 -1
  32. package/lib/standalone.d.ts +2 -2
  33. package/package.json +1 -1
  34. package/lib/core/shared/dot-content-analytics.constants.js +0 -14
  35. package/lib/core/shared/dot-content-analytics.model.d.ts +0 -351
@@ -1,9 +1,9 @@
1
- import { SESSION_STORAGE_KEY as h, DEFAULT_SESSION_TIMEOUT_MINUTES as S, USER_ID_KEY as m } from "./dot-content-analytics.constants.js";
2
- let d = null;
3
- const u = (t) => {
4
- const e = Date.now(), n = Math.random().toString(36).substr(2, 9), o = Math.random().toString(36).substr(2, 9);
5
- return `${t}_${e}_${n}${o}`;
6
- }, l = {
1
+ import { ANALYTICS_JS_DEFAULT_PROPERTIES as _, SESSION_STORAGE_KEY as S, DEFAULT_SESSION_TIMEOUT_MINUTES as f, USER_ID_KEY as l, EXPECTED_UTM_KEYS as w } from "./constants/dot-content-analytics.constants.js";
2
+ let g = null, u = null;
3
+ const d = (t) => {
4
+ const e = Date.now(), s = Math.random().toString(36).substr(2, 9), n = Math.random().toString(36).substr(2, 9);
5
+ return `${t}_${e}_${s}${n}`;
6
+ }, m = {
7
7
  getItem: (t) => {
8
8
  try {
9
9
  return localStorage.getItem(t);
@@ -15,109 +15,122 @@ const u = (t) => {
15
15
  try {
16
16
  localStorage.setItem(t, e);
17
17
  } catch {
18
- console.warn(`DotAnalytics: Could not save ${t} to localStorage`);
18
+ console.warn(`DotCMS Analytics: Could not save ${t} to localStorage`);
19
19
  }
20
20
  }
21
- }, f = () => {
22
- let t = l.getItem(m);
23
- return t || (t = u("user"), l.setItem(m, t)), t;
24
- }, _ = (t) => {
25
- const e = new Date(t), n = /* @__PURE__ */ new Date(), o = new Date(
21
+ }, p = () => {
22
+ let t = m.getItem(l);
23
+ return t || (t = d("user"), m.setItem(l, t)), t;
24
+ }, T = (t) => {
25
+ const e = new Date(t), s = /* @__PURE__ */ new Date(), n = new Date(
26
26
  e.getUTCFullYear(),
27
27
  e.getUTCMonth(),
28
28
  e.getUTCDate()
29
- ), s = new Date(n.getUTCFullYear(), n.getUTCMonth(), n.getUTCDate());
30
- return o.getTime() !== s.getTime();
31
- }, p = () => {
29
+ ), o = new Date(s.getUTCFullYear(), s.getUTCMonth(), s.getUTCDate());
30
+ return n.getTime() !== o.getTime();
31
+ }, D = () => {
32
32
  const t = Date.now();
33
33
  if (typeof window > "u")
34
- return u("session_fallback");
34
+ return d("session_fallback");
35
35
  try {
36
- const e = sessionStorage.getItem(h);
36
+ const e = sessionStorage.getItem(S);
37
37
  if (e) {
38
- const { sessionId: s, startTime: c, lastActivity: i } = JSON.parse(e), g = !_(c), a = t - i < S * 60 * 1e3;
39
- if (g && a)
38
+ const { sessionId: o, startTime: r, lastActivity: a } = JSON.parse(e), c = !T(r), i = t - a < f * 60 * 1e3;
39
+ if (c && i)
40
40
  return sessionStorage.setItem(
41
- h,
41
+ S,
42
42
  JSON.stringify({
43
- sessionId: s,
44
- startTime: c,
43
+ sessionId: o,
44
+ startTime: r,
45
45
  lastActivity: t
46
46
  })
47
- ), s;
47
+ ), o;
48
48
  }
49
- const n = u("session"), o = {
50
- sessionId: n,
49
+ const s = d("session"), n = {
50
+ sessionId: s,
51
51
  startTime: t,
52
52
  lastActivity: t
53
53
  };
54
- return sessionStorage.setItem(h, JSON.stringify(o)), n;
54
+ return sessionStorage.setItem(S, JSON.stringify(n)), s;
55
55
  } catch {
56
- return u("session_fallback");
56
+ return d("session_fallback");
57
57
  }
58
- }, T = (t) => {
59
- const e = p(), n = f();
60
- return t.debug && console.warn("DotAnalytics Identity Context:", {
58
+ }, $ = (t) => {
59
+ const e = D(), s = p();
60
+ return t.debug && console.warn("DotCMS Analytics Identity Context:", {
61
61
  sessionId: e,
62
- userId: n
62
+ userId: s
63
63
  }), {
64
- site_key: t.siteKey,
64
+ site_auth: t.siteAuth,
65
65
  session_id: e,
66
- user_id: n
66
+ user_id: s
67
67
  };
68
- }, w = () => d || (d = {
69
- user_language: navigator.language || void 0,
70
- doc_encoding: document.characterSet || document.charset || void 0,
71
- screen_resolution: typeof screen < "u" && screen.width && screen.height ? `${screen.width}x${screen.height}` : void 0
72
- }, d), I = () => {
68
+ }, I = () => g || (g = {
69
+ user_language: navigator.language,
70
+ doc_encoding: document.characterSet || document.charset,
71
+ screen_resolution: typeof screen < "u" && screen.width && screen.height ? `${screen.width}x${screen.height}` : ""
72
+ }, g), y = (t) => {
73
+ const e = t.search;
74
+ if (u && u.search === e)
75
+ return u.params;
76
+ const s = new URLSearchParams(e), n = {};
77
+ return w.forEach((o) => {
78
+ const r = s.get(o);
79
+ if (r) {
80
+ const a = o.replace("utm_", "");
81
+ n[a] = r;
82
+ }
83
+ }), u = { search: e, params: n }, n;
84
+ }, E = () => {
73
85
  try {
74
- const t = (/* @__PURE__ */ new Date()).getTimezoneOffset(), e = t > 0 ? "-" : "+", n = Math.abs(t), o = Math.floor(n / 60), s = n % 60;
75
- return `${e}${o.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`;
86
+ const t = (/* @__PURE__ */ new Date()).getTimezoneOffset(), e = t > 0 ? "-" : "+", s = Math.abs(t), n = Math.floor(s / 60), o = s % 60;
87
+ return `${e}${n.toString().padStart(2, "0")}:${o.toString().padStart(2, "0")}`;
76
88
  } catch {
77
89
  return "+00:00";
78
90
  }
79
- }, D = () => {
91
+ }, O = () => {
80
92
  try {
81
- const t = /* @__PURE__ */ new Date(), e = I(), n = t.getFullYear(), o = (t.getMonth() + 1).toString().padStart(2, "0"), s = t.getDate().toString().padStart(2, "0"), c = t.getHours().toString().padStart(2, "0"), i = t.getMinutes().toString().padStart(2, "0"), g = t.getSeconds().toString().padStart(2, "0");
82
- return `${n}-${o}-${s}T${c}:${i}:${g}${e}`;
93
+ const t = /* @__PURE__ */ new Date(), e = E(), s = t.getFullYear(), n = (t.getMonth() + 1).toString().padStart(2, "0"), o = t.getDate().toString().padStart(2, "0"), r = t.getHours().toString().padStart(2, "0"), a = t.getMinutes().toString().padStart(2, "0"), c = t.getSeconds().toString().padStart(2, "0");
94
+ return `${s}-${n}-${o}T${r}:${a}:${c}${e}`;
83
95
  } catch {
84
96
  return (/* @__PURE__ */ new Date()).toISOString();
85
97
  }
86
- }, $ = (t, e = typeof window < "u" ? window.location : {}) => {
87
- const n = D(), o = w(), { properties: s } = t, { utm: c } = s, i = {
88
- url: s.url ?? e.href,
89
- doc_encoding: o.doc_encoding,
90
- doc_hash: s.hash ?? e.hash ?? "",
98
+ }, C = (t, e = typeof window < "u" ? window.location : {}) => {
99
+ const s = O(), n = I(), { properties: o } = t, r = {};
100
+ Object.keys(o).forEach((h) => {
101
+ _.includes(h) || (r[h] = o[h]);
102
+ });
103
+ const a = {
104
+ url: e.href,
105
+ doc_encoding: n.doc_encoding,
106
+ doc_hash: e.hash,
91
107
  doc_protocol: e.protocol,
92
- doc_search: s.search ?? e.search ?? "",
108
+ doc_search: e.search,
93
109
  doc_host: e.hostname,
94
- doc_path: s.path ?? e.pathname,
95
- title: s.title ?? (document == null ? void 0 : document.title),
96
- language_id: void 0,
97
- persona: void 0
98
- }, g = {
99
- screen_resolution: o.screen_resolution,
100
- language: o.user_language,
101
- viewport_width: String(s.width),
102
- viewport_height: String(s.height)
103
- }, a = {};
104
- if (c && typeof c == "object") {
105
- const r = c;
106
- r.medium && (a.medium = r.medium), r.source && (a.source = r.source), r.campaign && (a.campaign = r.campaign), r.term && (a.term = r.term), r.content && (a.content = r.content);
107
- }
110
+ doc_path: e.pathname,
111
+ title: o.title ?? (document == null ? void 0 : document.title)
112
+ }, c = {
113
+ screen_resolution: n.screen_resolution ?? "",
114
+ language: n.user_language ?? "",
115
+ viewport_width: String(o.width),
116
+ viewport_height: String(o.height)
117
+ }, i = y(e);
108
118
  return {
109
119
  ...t,
110
- page: i,
111
- device: g,
112
- ...Object.keys(a).length > 0 && { utm: a },
113
- local_time: n
120
+ page: a,
121
+ device: c,
122
+ ...Object.keys(i).length > 0 && { utm: i },
123
+ // Only include custom if there are user-provided properties
124
+ ...Object.keys(r).length > 0 && { custom: r },
125
+ local_time: s
114
126
  };
115
127
  };
116
128
  export {
117
- $ as enrichPagePayloadOptimized,
118
- u as generateSecureId,
119
- T as getAnalyticsContext,
120
- D as getLocalTime,
121
- p as getSessionId,
122
- f as getUserId
129
+ C as enrichPagePayloadOptimized,
130
+ y as extractUTMParameters,
131
+ d as generateSecureId,
132
+ $ as getAnalyticsContext,
133
+ O as getLocalTime,
134
+ D as getSessionId,
135
+ p as getUserId
123
136
  };
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Data models for DotCMS Analytics
3
+ * Contains interfaces for data structures used in analytics events
4
+ */
5
+ /**
6
+ * Browser event data collected from the user's session in DotCMS.
7
+ * Contains comprehensive information about the user's browser environment,
8
+ * page context, and session details for analytics tracking.
9
+ *
10
+ * This is an internal type used by utility functions.
11
+ */
12
+ export interface DotCMSBrowserData {
13
+ /** UTC timestamp when the event occurred */
14
+ utc_time: string;
15
+ /** Local timezone offset in minutes */
16
+ local_tz_offset: number;
17
+ /** Screen resolution as a string (e.g., "1920x1080") */
18
+ screen_resolution: string;
19
+ /** Viewport size as a string (e.g., "1200x800") */
20
+ vp_size: string;
21
+ /** User's preferred language */
22
+ user_language: string;
23
+ /** Document encoding */
24
+ doc_encoding: string;
25
+ /** Document path */
26
+ doc_path: string;
27
+ /** Document host */
28
+ doc_host: string;
29
+ /** Document protocol (http/https) */
30
+ doc_protocol: string;
31
+ /** Document hash fragment */
32
+ doc_hash: string;
33
+ /** Document search parameters */
34
+ doc_search: string;
35
+ /** Referrer URL */
36
+ referrer: string;
37
+ /** Page title */
38
+ page_title: string;
39
+ /** Current page URL */
40
+ url: string;
41
+ /** UTM parameters for campaign tracking */
42
+ utm: DotCMSEventUtmData;
43
+ }
44
+ /**
45
+ * Analytics context shared across all events in DotCMS.
46
+ * Contains session and user identification data that provides
47
+ * continuity across multiple analytics events.
48
+ */
49
+ export interface DotCMSAnalyticsEventContext {
50
+ /** The site key for the DotCMS instance */
51
+ site_auth: string;
52
+ /** Unique session identifier */
53
+ session_id: string;
54
+ /** Unique user identifier */
55
+ user_id: string;
56
+ }
57
+ /**
58
+ * Device and browser information for DotCMS analytics tracking.
59
+ * Contains technical details about the user's device and browser environment.
60
+ */
61
+ export interface DotCMSEventDeviceData {
62
+ /** Screen resolution as a string (e.g., "1920x1080") */
63
+ screen_resolution: string;
64
+ /** User's preferred language */
65
+ language: string;
66
+ /** Viewport width in pixels */
67
+ viewport_width: string;
68
+ /** Viewport height in pixels */
69
+ viewport_height: string;
70
+ }
71
+ /**
72
+ * UTM (Urchin Tracking Module) parameters for DotCMS campaign tracking.
73
+ * Contains marketing campaign attribution data extracted from URL parameters.
74
+ */
75
+ export interface DotCMSEventUtmData {
76
+ /** The marketing medium (e.g., email, social, cpc) */
77
+ medium?: string;
78
+ /** The traffic source (e.g., google, newsletter) */
79
+ source?: string;
80
+ /** The campaign name */
81
+ campaign?: string;
82
+ /** The campaign term or keyword */
83
+ term?: string;
84
+ /** The campaign content or ad variation */
85
+ content?: string;
86
+ /** The campaign ID for tracking specific campaigns */
87
+ id?: string;
88
+ }
89
+ /**
90
+ * Page data structure for DotCMS analytics.
91
+ * Contains comprehensive information about the current page and its context
92
+ * within the DotCMS environment.
93
+ */
94
+ export type DotCMSEventPageData = Pick<DotCMSBrowserData, 'url' | 'doc_path' | 'doc_hash' | 'doc_search' | 'doc_host' | 'doc_protocol' | 'doc_encoding'> & {
95
+ /** Page title */
96
+ title: string | undefined;
97
+ /** Language identifier */
98
+ language_id?: string;
99
+ /** Persona identifier */
100
+ persona?: string;
101
+ };
@@ -0,0 +1,66 @@
1
+ import { DotCMSEventDeviceData, DotCMSEventPageData, DotCMSEventUtmData } from './data.model';
2
+ import { DotCMSCustomEventType, DotCMSEventType, DotCMSPredefinedEventType } from '../constants/dot-content-analytics.constants';
3
+ /**
4
+ * JSON value type for analytics custom data.
5
+ * Represents any valid JSON value that can be serialized and sent to the analytics server.
6
+ */
7
+ export type JsonValue = string | number | boolean | null | undefined | JsonObject | JsonArray;
8
+ /**
9
+ * JSON object type for analytics custom data.
10
+ */
11
+ export type JsonObject = {
12
+ [key: string]: JsonValue;
13
+ };
14
+ /**
15
+ * JSON array type for analytics custom data.
16
+ */
17
+ export type JsonArray = JsonValue[];
18
+ /**
19
+ * Generic base event structure for DotCMS Analytics.
20
+ * All events share this base structure with customizable event type and data.
21
+ *
22
+ * @template TEventType - The type of the event (pageview, custom event name, etc.)
23
+ * @template TData - The data structure for the event
24
+ */
25
+ export interface DotCMSEventBase<TEventType extends DotCMSEventType, TData> {
26
+ /** The type of event being tracked */
27
+ event_type: TEventType;
28
+ /** Local timestamp when the event occurred */
29
+ local_time: string;
30
+ /** Event-specific data with structured format */
31
+ data: TData;
32
+ }
33
+ /**
34
+ * Data structure for pageview events.
35
+ * Contains page, device, and optional UTM/custom data.
36
+ */
37
+ export type DotCMSPageViewEventData = {
38
+ /** Page data associated with the event */
39
+ page: DotCMSEventPageData;
40
+ /** Device and browser information */
41
+ device: DotCMSEventDeviceData;
42
+ /** UTM parameters for campaign tracking (optional) */
43
+ utm?: DotCMSEventUtmData;
44
+ /** Custom data associated with the event (any valid JSON) */
45
+ custom?: JsonObject;
46
+ };
47
+ /**
48
+ * Data structure for custom events.
49
+ * Contains user-defined custom data.
50
+ */
51
+ export type DotCMSCustomEventData = {
52
+ /** Custom data associated with the event (any valid JSON) */
53
+ custom: JsonObject;
54
+ };
55
+ /**
56
+ * Pageview event structure.
57
+ */
58
+ export type DotCMSPageViewEvent = DotCMSEventBase<typeof DotCMSPredefinedEventType.PAGEVIEW, DotCMSPageViewEventData>;
59
+ /**
60
+ * Custom event structure.
61
+ */
62
+ export type DotCMSCustomEvent = DotCMSEventBase<DotCMSCustomEventType, DotCMSCustomEventData>;
63
+ /**
64
+ * Union type for all possible analytics events.
65
+ */
66
+ export type DotCMSEvent = DotCMSPageViewEvent | DotCMSCustomEvent;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Central export point for all DotCMS Analytics models
3
+ */
4
+ export * from './data.model';
5
+ export * from './event.model';
6
+ export * from './request.model';
7
+ export * from './library.model';
8
+ declare global {
9
+ interface Window {
10
+ __dotAnalyticsCleanup?: () => void;
11
+ }
12
+ }
@@ -0,0 +1,176 @@
1
+ import { DotCMSAnalyticsEventContext, DotCMSEventDeviceData, DotCMSEventPageData, DotCMSEventUtmData } from './data.model';
2
+ import { JsonObject } from './event.model';
3
+ import { DotCMSAnalyticsRequestBody } from './request.model';
4
+ import { DotCMSCustomEventType } from '../constants';
5
+ /**
6
+ * Main interface for the DotCMS Analytics SDK.
7
+ * Provides the core methods for tracking page views and custom events.
8
+ */
9
+ export interface DotCMSAnalytics {
10
+ /**
11
+ * Track a page view event.
12
+ * @param payload - Optional custom data to include with the page view (any valid JSON object)
13
+ */
14
+ pageView: (payload?: JsonObject) => void;
15
+ /**
16
+ * Track a custom event.
17
+ * @param eventName - The name/type of the event to track
18
+ * @param payload - Custom data to include with the event (any valid JSON object)
19
+ */
20
+ track: (eventName: string, payload: JsonObject) => void;
21
+ }
22
+ /**
23
+ * Configuration interface for DotCMS Analytics SDK.
24
+ * Contains all necessary settings for initializing and configuring the analytics client.
25
+ */
26
+ export interface DotCMSAnalyticsConfig {
27
+ /**
28
+ * The URL of the Analytics server endpoint.
29
+ */
30
+ server: string;
31
+ /**
32
+ * Enable debug mode to get additional logging information.
33
+ */
34
+ debug: boolean;
35
+ /**
36
+ * Automatically track page views when set to true.
37
+ */
38
+ autoPageView?: boolean;
39
+ /**
40
+ * The site auth for authenticating with the Analytics service.
41
+ */
42
+ siteAuth: string;
43
+ }
44
+ /**
45
+ * Track event payload with context.
46
+ * This is the payload for custom track events after the identity plugin adds context.
47
+ * Used in the track:dot-analytics enricher plugin.
48
+ */
49
+ export interface AnalyticsTrackPayloadWithContext extends AnalyticsBasePayload {
50
+ /** The custom event name (any string except 'pageview') */
51
+ event: DotCMSCustomEventType;
52
+ /** Analytics context added by identity plugin */
53
+ context: DotCMSAnalyticsEventContext;
54
+ }
55
+ /**
56
+ * Parameters passed to DotCMS Analytics plugin methods (after enrichment).
57
+ * The payload is the complete request body ready to send to the server.
58
+ */
59
+ export interface DotCMSAnalyticsParams {
60
+ /** Configuration for the analytics client */
61
+ config: DotCMSAnalyticsConfig;
62
+ /** The complete request body */
63
+ payload: DotCMSAnalyticsRequestBody;
64
+ }
65
+ type AnalyticsBasePayloadType = 'page' | 'track';
66
+ /**
67
+ * Analytics.js hook parameter types for DotCMS.
68
+ * Represents the payload structure used by Analytics.js lifecycle hooks
69
+ * for intercepting and modifying analytics events.
70
+ */
71
+ export interface AnalyticsBasePayload {
72
+ /** The type of analytics event */
73
+ type: AnalyticsBasePayloadType;
74
+ /** Properties associated with the event */
75
+ properties: {
76
+ /** Page title */
77
+ title: string;
78
+ /** Page URL */
79
+ url: string;
80
+ /** Page path */
81
+ path: string;
82
+ /** URL hash fragment */
83
+ hash: string;
84
+ /** URL search parameters */
85
+ search: string;
86
+ /** Viewport width */
87
+ width: number;
88
+ /** Viewport height */
89
+ height: number;
90
+ /** Referrer URL */
91
+ referrer?: string;
92
+ };
93
+ /** Configuration options for the event */
94
+ options: Record<string, unknown>;
95
+ /** User identifier */
96
+ userId: string;
97
+ /** Anonymous user identifier */
98
+ anonymousId: string;
99
+ /** Metadata about the event */
100
+ meta: {
101
+ /** Request identifier */
102
+ rid: string;
103
+ /** Timestamp */
104
+ ts: number;
105
+ /** Whether the event has a callback function */
106
+ hasCallback: boolean;
107
+ };
108
+ }
109
+ /**
110
+ * Analytics.js payload with context.
111
+ * This is the result of enriching the base Analytics.js payload
112
+ * with context data added by the identity plugin.
113
+ */
114
+ export interface AnalyticsBasePayloadWithContext extends AnalyticsBasePayload {
115
+ context: DotCMSAnalyticsEventContext;
116
+ }
117
+ /**
118
+ * Enriched analytics payload with DotCMS-specific data.
119
+ * This is the result of enriching the base Analytics.js payload with context (from identity plugin)
120
+ * and then adding page, device, UTM, and custom data (from enricher plugin).
121
+ */
122
+ export type EnrichedAnalyticsPayload = AnalyticsBasePayloadWithContext & {
123
+ /** Page data for the current page */
124
+ page: DotCMSEventPageData;
125
+ /** Device and browser information */
126
+ device: DotCMSEventDeviceData;
127
+ /** UTM parameters for campaign tracking */
128
+ utm?: DotCMSEventUtmData;
129
+ /** Custom data associated with the event (any valid JSON) */
130
+ custom?: JsonObject;
131
+ /** Local timestamp when the event occurred */
132
+ local_time: string;
133
+ };
134
+ /**
135
+ * Analytics.js instance structure for DotCMS.
136
+ * Represents the internal structure of an Analytics.js instance,
137
+ * providing access to plugins, storage, and event configuration.
138
+ */
139
+ export interface DotCMSAnalyticsInstance {
140
+ /** Available plugins and their configurations */
141
+ plugins: Record<string, unknown>;
142
+ /** Storage mechanisms for analytics data */
143
+ storage: Record<string, unknown>;
144
+ /** Event configuration */
145
+ events: {
146
+ /** Core event types */
147
+ core: string[];
148
+ /** Plugin-specific event types */
149
+ plugins: string[];
150
+ };
151
+ }
152
+ /**
153
+ * Base parameters structure passed by Analytics.js to plugin hooks.
154
+ * Contains all the context and data needed for Analytics.js lifecycle hooks
155
+ * to process and modify analytics events.
156
+ */
157
+ export interface AnalyticsBaseParams {
158
+ /** The event payload data */
159
+ payload: AnalyticsBasePayload;
160
+ /** The analytics instance */
161
+ instance: DotCMSAnalyticsInstance;
162
+ /** Global configuration settings */
163
+ config: Record<string, unknown>;
164
+ /** Available plugins and their status */
165
+ plugins: Record<string, {
166
+ /** Whether the plugin is enabled */
167
+ enabled: boolean;
168
+ /** Whether the plugin is initialized */
169
+ initialized: boolean;
170
+ /** Whether the plugin is loaded */
171
+ loaded: boolean;
172
+ /** Plugin-specific configuration */
173
+ config: Record<string, unknown>;
174
+ }>;
175
+ }
176
+ export {};
@@ -0,0 +1,24 @@
1
+ import { DotCMSAnalyticsEventContext } from './data.model';
2
+ import { DotCMSCustomEvent, DotCMSEvent, DotCMSPageViewEvent } from './event.model';
3
+ /**
4
+ * Analytics request body for DotCMS Analytics.
5
+ * Generic structure sent to the DotCMS analytics server.
6
+ */
7
+ export interface DotCMSRequestBody<T extends DotCMSEvent> {
8
+ /** Context information shared across all events */
9
+ context: DotCMSAnalyticsEventContext;
10
+ /** Array of analytics events to be tracked */
11
+ events: T[];
12
+ }
13
+ /**
14
+ * Specific request body type for PageView events
15
+ */
16
+ export type DotCMSPageViewRequestBody = DotCMSRequestBody<DotCMSPageViewEvent>;
17
+ /**
18
+ * Specific request body type for Custom events
19
+ */
20
+ export type DotCMSCustomEventRequestBody = DotCMSRequestBody<DotCMSCustomEvent>;
21
+ /**
22
+ * Union type for all possible request bodies
23
+ */
24
+ export type DotCMSAnalyticsRequestBody = DotCMSPageViewRequestBody | DotCMSCustomEventRequestBody;
@@ -1,5 +1,5 @@
1
1
  import { ReactElement } from 'react';
2
- import { DotCMSAnalyticsConfig } from '../../core/shared/dot-content-analytics.model';
2
+ import { DotCMSAnalyticsConfig } from '../../core/shared/models';
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,29 +1,57 @@
1
- import { DotCMSAnalytics, DotCMSAnalyticsConfig } from '../../core/shared/dot-content-analytics.model';
1
+ import { DotCMSAnalytics, DotCMSAnalyticsConfig } from '../../core/shared/models';
2
2
  /**
3
- * Custom hook that handles analytics tracking for anonymous users.
4
- * Provides methods to track events and page views with automatic timestamp injection.
5
- * Automatically disables tracking when inside the UVE editor.
3
+ * React hook for tracking user interactions and page views in your DotCMS application.
4
+ *
5
+ * Use this hook to add analytics tracking to your React components. It automatically
6
+ * handles user sessions, device information, and UTM campaign parameters.
7
+ *
8
+ * **Important:** Tracking is automatically disabled when editing content in DotCMS to avoid
9
+ * polluting your analytics data with editor activity.
6
10
  *
7
11
  * @example
12
+ * Basic usage - Track custom events
8
13
  * ```tsx
9
- * function Button({ title, urlTitle }) {
14
+ * function ProductCard({ title, price }) {
10
15
  * const { track } = useContentAnalytics({
11
16
  * server: 'https://demo.dotcms.com',
12
- * siteKey: 'my-site-key',
17
+ * siteAuth: 'my-site-auth',
13
18
  * debug: false
14
19
  * });
15
20
  *
16
- * // Track button click with custom properties
17
- * return (
18
- * <button onClick={() => track('btn-click', { title, urlTitle })}>
19
- * See Details →
20
- * </button>
21
- * );
21
+ * const handleAddToCart = () => {
22
+ * track('add-to-cart', {
23
+ * product: title,
24
+ * price: price
25
+ * });
26
+ * };
27
+ *
28
+ * return <button onClick={handleAddToCart}>Add to Cart</button>;
29
+ * }
30
+ * ```
31
+ *
32
+ * @example
33
+ * Track page views manually
34
+ * ```tsx
35
+ * function ArticlePage({ article }) {
36
+ * const { pageView } = useContentAnalytics({
37
+ * server: 'https://demo.dotcms.com',
38
+ * siteKey: 'your-site-key'
39
+ * });
40
+ *
41
+ * useEffect(() => {
42
+ * pageView({
43
+ * category: article.category,
44
+ * author: article.author
45
+ * });
46
+ * }, [article.id]);
22
47
  * }
23
48
  * ```
24
49
  *
25
- * @param {DotCMSAnalyticsConfig} config - Required configuration object for analytics initialization
26
- * @returns {DotCMSAnalytics} The analytics instance with tracking capabilities
27
- * @throws {Error} When analytics initialization fails due to invalid configuration
50
+ * @param config - Configuration object with server URL and site key
51
+ * @param config.server - The URL of your DotCMS Analytics server
52
+ * @param config.siteKey - Your unique site key for authentication
53
+ * @param config.debug - Optional. Set to true to see analytics events in the console
54
+ * @returns Object with `track()` and `pageView()` methods for analytics tracking
55
+ * @throws {Error} If the configuration is invalid (missing server or siteKey)
28
56
  */
29
57
  export declare const useContentAnalytics: (config: DotCMSAnalyticsConfig) => DotCMSAnalytics;