@dotcms/analytics 1.1.1 → 1.2.0-next.10

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 (64) hide show
  1. package/README.md +475 -72
  2. package/lib/core/{dot-content-analytics.d.ts → dot-analytics.content.d.ts} +8 -1
  3. package/lib/core/dot-analytics.content.js +63 -0
  4. package/lib/core/plugin/click/dot-analytics.click-tracker.d.ts +108 -0
  5. package/lib/core/plugin/click/dot-analytics.click-tracker.js +144 -0
  6. package/lib/core/plugin/click/dot-analytics.click.plugin.d.ts +36 -0
  7. package/lib/core/plugin/click/dot-analytics.click.plugin.js +27 -0
  8. package/lib/core/plugin/click/dot-analytics.click.utils.d.ts +12 -0
  9. package/lib/core/plugin/click/dot-analytics.click.utils.js +55 -0
  10. package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.d.ts +18 -30
  11. package/lib/core/plugin/enricher/dot-analytics.enricher.plugin.js +30 -20
  12. package/lib/core/plugin/identity/dot-analytics.identity.activity-tracker.d.ts +20 -0
  13. package/lib/core/{shared/dot-content-analytics.activity-tracker.js → plugin/identity/dot-analytics.identity.activity-tracker.js} +19 -38
  14. package/lib/core/plugin/identity/dot-analytics.identity.plugin.d.ts +13 -31
  15. package/lib/core/plugin/identity/dot-analytics.identity.plugin.js +14 -12
  16. package/lib/core/plugin/identity/dot-analytics.identity.utils.d.ts +7 -22
  17. package/lib/core/plugin/impression/dot-analytics.impression-tracker.d.ts +62 -0
  18. package/lib/core/plugin/impression/dot-analytics.impression-tracker.js +200 -0
  19. package/lib/core/plugin/impression/dot-analytics.impression.plugin.d.ts +40 -0
  20. package/lib/core/plugin/impression/dot-analytics.impression.plugin.js +27 -0
  21. package/lib/core/plugin/impression/dot-analytics.impression.utils.d.ts +26 -0
  22. package/lib/core/plugin/impression/dot-analytics.impression.utils.js +27 -0
  23. package/lib/core/plugin/impression/index.d.ts +2 -0
  24. package/lib/core/plugin/main/dot-analytics.plugin.d.ts +46 -0
  25. package/lib/core/plugin/main/dot-analytics.plugin.js +114 -0
  26. package/lib/core/shared/constants/dot-analytics.constants.d.ts +131 -0
  27. package/lib/core/shared/constants/dot-analytics.constants.js +52 -0
  28. package/lib/core/shared/constants/index.d.ts +4 -0
  29. package/lib/core/shared/dot-analytics.logger.d.ts +85 -0
  30. package/lib/core/shared/dot-analytics.logger.js +90 -0
  31. package/lib/core/shared/http/dot-analytics.http.d.ts +9 -0
  32. package/lib/core/shared/http/dot-analytics.http.js +34 -0
  33. package/lib/core/shared/models/data.model.d.ts +141 -0
  34. package/lib/core/shared/models/event.model.d.ts +135 -0
  35. package/lib/core/shared/models/index.d.ts +7 -0
  36. package/lib/core/shared/models/library.model.d.ts +243 -0
  37. package/lib/core/shared/models/request.model.d.ts +32 -0
  38. package/lib/core/shared/queue/dot-analytics.queue.utils.d.ts +28 -0
  39. package/lib/core/shared/queue/dot-analytics.queue.utils.js +80 -0
  40. package/lib/core/shared/queue/index.d.ts +1 -0
  41. package/lib/core/shared/utils/dot-analytics.utils.d.ts +260 -0
  42. package/lib/core/shared/utils/dot-analytics.utils.js +202 -0
  43. package/lib/react/components/DotContentAnalytics.d.ts +1 -1
  44. package/lib/react/hook/useContentAnalytics.d.ts +43 -15
  45. package/lib/react/hook/useContentAnalytics.js +18 -21
  46. package/lib/react/hook/useRouterTracker.d.ts +1 -1
  47. package/lib/react/hook/useRouterTracker.js +4 -4
  48. package/lib/react/internal/utils.d.ts +1 -1
  49. package/lib/react/internal/utils.js +3 -3
  50. package/lib/react/public-api.d.ts +1 -1
  51. package/lib/standalone.d.ts +2 -2
  52. package/package.json +7 -5
  53. package/uve/src/internal/constants.js +8 -3
  54. package/lib/core/dot-content-analytics.js +0 -43
  55. package/lib/core/plugin/dot-analytics.plugin.d.ts +0 -32
  56. package/lib/core/plugin/dot-analytics.plugin.js +0 -79
  57. package/lib/core/shared/dot-content-analytics.activity-tracker.d.ts +0 -28
  58. package/lib/core/shared/dot-content-analytics.constants.d.ts +0 -37
  59. package/lib/core/shared/dot-content-analytics.constants.js +0 -14
  60. package/lib/core/shared/dot-content-analytics.http.d.ts +0 -8
  61. package/lib/core/shared/dot-content-analytics.http.js +0 -29
  62. package/lib/core/shared/dot-content-analytics.model.d.ts +0 -351
  63. package/lib/core/shared/dot-content-analytics.utils.d.ts +0 -111
  64. package/lib/core/shared/dot-content-analytics.utils.js +0 -123
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/analytics",
3
- "version": "1.1.1",
3
+ "version": "1.2.0-next.10",
4
4
  "description": "Official JavaScript library for Content Analytics with DotCMS.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,19 +20,21 @@
20
20
  },
21
21
  "homepage": "https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/analytics/README.md",
22
22
  "dependencies": {
23
- "analytics": "^0.8.0",
24
23
  "@analytics/core": "^0.13.0",
24
+ "@analytics/queue-utils": "^0.1.3",
25
+ "@analytics/router-utils": "^0.1.1",
25
26
  "@analytics/storage-utils": "^0.4.0",
26
- "@dotcms/uve": "latest"
27
+ "@dotcms/uve": "latest",
28
+ "analytics": "^0.8.0"
27
29
  },
28
30
  "peerDependencies": {
29
31
  "react": "^18 || ^19"
30
32
  },
31
33
  "devDependencies": {
34
+ "@dotcms/types": "latest",
32
35
  "@testing-library/jest-dom": "^6.1.6",
33
36
  "@testing-library/react": "^14.0.0",
34
- "vite": "~5.0.0",
35
- "@dotcms/types": "latest"
37
+ "vite": "~5.0.0"
36
38
  },
37
39
  "main": "./index.js",
38
40
  "module": "./index.js",
@@ -1,3 +1,8 @@
1
- import { UVEEventType as n } from "../../../types/src/lib/editor/public.js";
2
- import { onContentletHovered as r, onIframeScroll as o, onRequestBounds as t, onPageReload as E, onContentChanges as u } from "./events.js";
3
- n.CONTENT_CHANGES + "", n.PAGE_RELOAD + "", n.REQUEST_BOUNDS + "", n.IFRAME_SCROLL + "", n.CONTENTLET_HOVERED + "";
1
+ import { UVEEventType as t } from "../../../types/src/lib/editor/public.js";
2
+ import { onContentletHovered as e, onIframeScroll as o, onRequestBounds as r, onPageReload as E, onContentChanges as _ } from "./events.js";
3
+ t.CONTENT_CHANGES + "", t.PAGE_RELOAD + "", t.REQUEST_BOUNDS + "", t.IFRAME_SCROLL + "", t.CONTENTLET_HOVERED + "";
4
+ const N = "__dotAnalyticsActive__", T = "__dotAnalyticsCleanup";
5
+ export {
6
+ N as ANALYTICS_WINDOWS_ACTIVE_KEY,
7
+ T as ANALYTICS_WINDOWS_CLEANUP_KEY
8
+ };
@@ -1,43 +0,0 @@
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), {
24
- /**
25
- * Track a page view.
26
- * @param {Record<string, unknown>} payload - The payload to track.
27
- */
28
- pageView: (i = {}) => {
29
- o(), t == null || t.page(i);
30
- },
31
- /**
32
- * Track a custom event.
33
- * @param {string} eventName - The name of the event to track.
34
- * @param {Record<string, unknown>} payload - The payload to track.
35
- */
36
- track: (i, r = {}) => {
37
- o(), t == null || t.track(i, r);
38
- }
39
- };
40
- };
41
- export {
42
- f as initializeContentAnalytics
43
- };
@@ -1,32 +0,0 @@
1
- import { DotCMSAnalyticsConfig, DotCMSAnalyticsParams } from '../shared/dot-content-analytics.model';
2
- /**
3
- * Analytics plugin for tracking page views and custom events in DotCMS applications.
4
- * This plugin handles sending analytics data to the DotCMS server, managing initialization,
5
- * and processing both automatic and manual tracking events.
6
- *
7
- * @param {DotCMSAnalyticsConfig} config - Configuration object containing API key, server URL,
8
- * debug mode and auto page view settings
9
- * @returns {Object} Plugin object with methods for initialization and event tracking
10
- */
11
- export declare const dotAnalytics: (config: DotCMSAnalyticsConfig) => {
12
- name: string;
13
- config: DotCMSAnalyticsConfig;
14
- /**
15
- * Initialize the plugin
16
- */
17
- initialize: () => Promise<void>;
18
- /**
19
- * Track a page view event
20
- * Takes enriched data from properties and creates final structured event
21
- */
22
- page: (params: DotCMSAnalyticsParams) => Promise<void>;
23
- /**
24
- * Track a custom event
25
- * Takes enriched data and sends it to the analytics server
26
- */
27
- track: (params: DotCMSAnalyticsParams) => Promise<void>;
28
- /**
29
- * Check if the plugin is loaded
30
- */
31
- loaded: () => boolean;
32
- };
@@ -1,79 +0,0 @@
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;
5
- return {
6
- name: "dot-analytics",
7
- config: v,
8
- /**
9
- * Initialize the plugin
10
- */
11
- initialize: () => (r = !0, Promise.resolve()),
12
- /**
13
- * Track a page view event
14
- * Takes enriched data from properties and creates final structured event
15
- */
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)
19
- throw new Error("DotAnalytics: Plugin not initialized");
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
- ]
35
- };
36
- return t.debug && console.warn("DotAnalytics: Pageview event to send:", d), c(d, t);
37
- },
38
- // TODO: Fix this when we haver the final design for the track event
39
- /**
40
- * Track a custom event
41
- * Takes enriched data and sends it to the analytics server
42
- */
43
- track: (a) => {
44
- const { config: t, payload: e } = a;
45
- if (!r)
46
- throw new Error("DotAnalytics: Plugin not initialized");
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
- ]
68
- };
69
- return t.debug && console.warn("DotAnalytics: Track event to send (fallback):", n), c(n, t);
70
- },
71
- /**
72
- * Check if the plugin is loaded
73
- */
74
- loaded: () => r
75
- };
76
- };
77
- export {
78
- p as dotAnalytics
79
- };
@@ -1,28 +0,0 @@
1
- import { DotCMSAnalyticsConfig } from './dot-content-analytics.model';
2
- /**
3
- * Updates session activity with throttling
4
- */
5
- export declare const updateSessionActivity: () => void;
6
- /**
7
- * Gets session information for debugging
8
- */
9
- export declare const getSessionInfo: () => {
10
- lastActivity: number;
11
- isActive: boolean;
12
- };
13
- /**
14
- * Initializes activity tracking
15
- */
16
- export declare const initializeActivityTracking: (config: DotCMSAnalyticsConfig) => void;
17
- /**
18
- * Cleans up activity tracking listeners
19
- */
20
- export declare const cleanupActivityTracking: () => void;
21
- /**
22
- * Checks if user has been inactive
23
- */
24
- export declare const isUserInactive: () => boolean;
25
- /**
26
- * Gets last activity time
27
- */
28
- export declare const getLastActivity: () => number;
@@ -1,37 +0,0 @@
1
- export declare const ANALYTICS_WINDOWS_KEY = "dotAnalytics";
2
- export declare const ANALYTICS_SOURCE_TYPE = "dotAnalytics";
3
- export declare const ANALYTICS_ENDPOINT = "/api/v1/analytics/content/event";
4
- /**
5
- * Event Types
6
- * Only two event types are supported in DotCMS Analytics
7
- */
8
- export declare const EVENT_TYPES: {
9
- readonly PAGEVIEW: "pageview";
10
- readonly TRACK: "track";
11
- };
12
- /**
13
- * Expected UTM parameter keys for campaign tracking
14
- */
15
- export declare const EXPECTED_UTM_KEYS: readonly ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "utm_id"];
16
- /**
17
- * Session configuration constants
18
- */
19
- export declare const DEFAULT_SESSION_TIMEOUT_MINUTES = 30;
20
- export declare const SESSION_STORAGE_KEY = "dot_analytics_session_id";
21
- export declare const SESSION_START_KEY = "dot_analytics_session_start";
22
- export declare const SESSION_UTM_KEY = "dot_analytics_session_utm";
23
- /**
24
- * User ID configuration constants
25
- */
26
- export declare const USER_ID_KEY = "dot_analytics_user_id";
27
- /**
28
- * Activity tracking configuration
29
- * Events used to detect user activity for session management
30
- * - click: Detects real user interaction with minimal performance impact
31
- * - visibilitychange: Handled separately to detect tab changes
32
- */
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";
@@ -1,14 +0,0 @@
1
- const t = "dotAnalytics", E = t, _ = "/api/v1/analytics/content/event", c = {
2
- PAGEVIEW: "pageview",
3
- TRACK: "track"
4
- }, n = 30, s = "dot_analytics_session_id", S = "dot_analytics_user_id", T = ["click"];
5
- export {
6
- T as ACTIVITY_EVENTS,
7
- _ as ANALYTICS_ENDPOINT,
8
- E as ANALYTICS_SOURCE_TYPE,
9
- t as ANALYTICS_WINDOWS_KEY,
10
- n as DEFAULT_SESSION_TIMEOUT_MINUTES,
11
- c as EVENT_TYPES,
12
- s as SESSION_STORAGE_KEY,
13
- S as USER_ID_KEY
14
- };
@@ -1,8 +0,0 @@
1
- import { DotCMSAnalyticsConfig, DotCMSAnalyticsRequestBody } from './dot-content-analytics.model';
2
- /**
3
- * Send an analytics event to the server
4
- * @param payload - The event payload data
5
- * @param config - The analytics configuration
6
- * @returns A promise that resolves when the request is complete
7
- */
8
- export declare const sendAnalyticsEventToServer: (payload: DotCMSAnalyticsRequestBody, config: DotCMSAnalyticsConfig) => Promise<void>;
@@ -1,29 +0,0 @@
1
- import { ANALYTICS_ENDPOINT as a } from "./dot-content-analytics.constants.js";
2
- const i = async (o, t) => {
3
- try {
4
- const e = await fetch(`${t.server}${a}`, {
5
- method: "POST",
6
- headers: { "Content-Type": "application/json" },
7
- body: JSON.stringify(o)
8
- });
9
- if (!e.ok) {
10
- const n = e.statusText || "Unknown Error", s = `HTTP ${e.status}: ${n}`;
11
- try {
12
- const r = await e.json();
13
- r.message ? console.warn(`DotAnalytics: ${r.message} (${s})`) : console.warn(
14
- `DotAnalytics: ${s} - No error message in response`
15
- );
16
- } catch (r) {
17
- console.warn(
18
- `DotAnalytics: ${s} - Failed to parse error response:`,
19
- r
20
- );
21
- }
22
- }
23
- } catch (e) {
24
- console.error("DotAnalytics: Error sending event:", e);
25
- }
26
- };
27
- export {
28
- i as sendAnalyticsEventToServer
29
- };
@@ -1,351 +0,0 @@
1
- import { EVENT_TYPES } from './dot-content-analytics.constants';
2
- declare global {
3
- interface Window {
4
- __dotAnalyticsCleanup?: () => void;
5
- }
6
- }
7
- /**
8
- * Configuration interface for DotCMS Analytics SDK.
9
- * Contains all necessary settings for initializing and configuring the analytics client.
10
- */
11
- export interface DotCMSAnalyticsConfig {
12
- /**
13
- * The URL of the Analytics server endpoint.
14
- */
15
- server: string;
16
- /**
17
- * Enable debug mode to get additional logging information.
18
- */
19
- debug: boolean;
20
- /**
21
- * Automatically track page views when set to true.
22
- */
23
- autoPageView?: boolean;
24
- /**
25
- * The site key for authenticating with the Analytics service.
26
- */
27
- siteKey: string;
28
- }
29
- /**
30
- * Supported event types in DotCMS Analytics.
31
- * Only two event types are supported: pageview and track.
32
- */
33
- export type DotCMSEventType = (typeof EVENT_TYPES)[keyof typeof EVENT_TYPES];
34
- /**
35
- * Base structure for all analytics events.
36
- * All events share this common structure.
37
- */
38
- export interface DotCMSEventBase {
39
- /** The type of event being tracked */
40
- event_type: DotCMSEventType;
41
- /** Local timestamp when the event occurred */
42
- local_time: string;
43
- }
44
- /**
45
- * Pageview-specific analytics event structure.
46
- * Contains data specific to page view tracking.
47
- */
48
- export interface DotCMSPageViewEvent extends DotCMSEventBase {
49
- event_type: 'pageview';
50
- /** Pageview-specific event data with structured format */
51
- data: {
52
- /** Page data associated with the event */
53
- page: DotCMSPageData;
54
- /** Device and browser information */
55
- device: DotCMSDeviceData;
56
- /** UTM parameters for campaign tracking (optional) */
57
- utm?: DotCMSUtmData;
58
- };
59
- }
60
- /**
61
- * Track-specific analytics event structure.
62
- * Contains data specific to custom event tracking.
63
- */
64
- export interface DotCMSTrackEvent extends DotCMSEventBase {
65
- event_type: 'track';
66
- /** Track-specific event data with flexible structure */
67
- data: Record<string, unknown>;
68
- }
69
- /**
70
- * Union type for all possible analytics events.
71
- */
72
- export type DotCMSEvent = DotCMSPageViewEvent | DotCMSTrackEvent;
73
- /**
74
- * Analytics request body for page view events in DotCMS.
75
- * Structure sent to the DotCMS analytics server for page tracking.
76
- */
77
- export interface DotCMSPageViewRequestBody {
78
- /** Context information shared across all events */
79
- context: DotCMSAnalyticsContext;
80
- /** Array of pageview analytics events to be tracked */
81
- events: DotCMSPageViewEvent[];
82
- }
83
- /**
84
- * Analytics request body for track events in DotCMS.
85
- * Structure sent to the DotCMS analytics server for custom event tracking.
86
- */
87
- export interface DotCMSTrackRequestBody {
88
- /** Context information shared across all events */
89
- context: DotCMSAnalyticsContext;
90
- /** Array of track analytics events to be tracked */
91
- events: DotCMSTrackEvent[];
92
- }
93
- /**
94
- * Union type for all possible request bodies.
95
- */
96
- export type DotCMSAnalyticsRequestBody = DotCMSPageViewRequestBody | DotCMSTrackRequestBody;
97
- /**
98
- * Enriched payload structure returned by the enricher plugin.
99
- * Contains pre-structured events and context for direct use in analytics requests.
100
- */
101
- export interface DotCMSEnrichedPayload {
102
- /** Analytics context shared across events */
103
- context: DotCMSAnalyticsContext;
104
- /** Array of pre-structured analytics events */
105
- events: DotCMSEvent[];
106
- }
107
- /**
108
- * Browser event data collected from the user's session in DotCMS.
109
- * Contains comprehensive information about the user's browser environment,
110
- * page context, and session details for analytics tracking.
111
- */
112
- export interface DotCMSBrowserEventData {
113
- /** UTC timestamp when the event occurred */
114
- utc_time: string;
115
- /** Local timezone offset in minutes */
116
- local_tz_offset: number;
117
- /** Screen resolution as a string (e.g., "1920x1080") */
118
- screen_resolution: string | undefined;
119
- /** Viewport size as a string (e.g., "1200x800") */
120
- vp_size: string | undefined;
121
- /** User's preferred language */
122
- user_language: string | undefined;
123
- /** Document encoding */
124
- doc_encoding: string | undefined;
125
- /** Document path */
126
- doc_path: string | undefined;
127
- /** Document host */
128
- doc_host: string | undefined;
129
- /** Document protocol (http/https) */
130
- doc_protocol: string | undefined;
131
- /** Document hash fragment */
132
- doc_hash: string;
133
- /** Document search parameters */
134
- doc_search: string;
135
- /** Referrer URL */
136
- referrer: string | undefined;
137
- /** Page title */
138
- page_title: string | undefined;
139
- /** Current page URL */
140
- url: string | undefined;
141
- /** UTM parameters for campaign tracking */
142
- utm: Record<string, string>;
143
- }
144
- /**
145
- * The payload structure for DotCMS analytics events.
146
- * This interface represents the complete data structure that flows through
147
- * the analytics pipeline, including original event data and enriched context.
148
- *
149
- * This is the internal payload used by Analytics.js and our plugins.
150
- */
151
- export interface DotCMSAnalyticsPayload {
152
- /** The event name or identifier */
153
- event: string;
154
- /** Additional properties associated with the event */
155
- properties: Record<string, unknown>;
156
- /** Configuration options for the event */
157
- options: Record<string, unknown>;
158
- /** Analytics context shared across events */
159
- context?: DotCMSAnalyticsContext;
160
- /** Page data for the current page */
161
- page?: DotCMSPageData;
162
- /** Device and browser information */
163
- device?: DotCMSDeviceData;
164
- /** UTM parameters for campaign tracking */
165
- utm?: DotCMSUtmData;
166
- /** Local timestamp when the event occurred */
167
- local_time: string;
168
- }
169
- /**
170
- * Parameters passed to DotCMS Analytics plugin methods.
171
- * Contains the configuration and payload data needed for processing analytics events.
172
- */
173
- export interface DotCMSAnalyticsParams {
174
- /** Configuration for the analytics client */
175
- config: DotCMSAnalyticsConfig;
176
- /** The event payload to be processed */
177
- payload: DotCMSAnalyticsPayload;
178
- }
179
- /**
180
- * Main interface for the DotCMS Analytics SDK.
181
- * Provides the core methods for tracking page views and custom events.
182
- */
183
- export interface DotCMSAnalytics {
184
- /**
185
- * Track a page view event.
186
- */
187
- pageView: () => void;
188
- /**
189
- * Track a custom event.
190
- * @param eventName - The name/type of the event to track
191
- * @param payload - Optional additional data to include with the event
192
- */
193
- track: (eventName: string, payload?: Record<string, unknown>) => void;
194
- }
195
- /**
196
- * Analytics context shared across all events in DotCMS.
197
- * Contains session and user identification data that provides
198
- * continuity across multiple analytics events.
199
- */
200
- export interface DotCMSAnalyticsContext {
201
- /** The site key for the DotCMS instance */
202
- site_key: string;
203
- /** Unique session identifier */
204
- session_id: string;
205
- /** Unique user identifier */
206
- user_id: string;
207
- }
208
- /**
209
- * Device and browser information for DotCMS analytics tracking.
210
- * Contains technical details about the user's device and browser environment.
211
- */
212
- export interface DotCMSDeviceData {
213
- /** Screen resolution as a string (e.g., "1920x1080") */
214
- screen_resolution: string | undefined;
215
- /** User's preferred language */
216
- language: string | undefined;
217
- /** Viewport width in pixels */
218
- viewport_width: string | undefined;
219
- /** Viewport height in pixels */
220
- viewport_height: string | undefined;
221
- }
222
- /**
223
- * UTM (Urchin Tracking Module) parameters for DotCMS campaign tracking.
224
- * Contains marketing campaign attribution data extracted from URL parameters.
225
- */
226
- export interface DotCMSUtmData {
227
- /** The marketing medium (e.g., email, social, cpc) */
228
- medium?: string;
229
- /** The traffic source (e.g., google, newsletter) */
230
- source?: string;
231
- /** The campaign name */
232
- campaign?: string;
233
- /** The campaign term or keyword */
234
- term?: string;
235
- /** The campaign content or ad variation */
236
- content?: string;
237
- /** The campaign ID for tracking specific campaigns */
238
- id?: string;
239
- }
240
- /**
241
- * Page data structure for DotCMS analytics.
242
- * Contains comprehensive information about the current page and its context
243
- * within the DotCMS environment.
244
- */
245
- export interface DotCMSPageData {
246
- /** The current page URL */
247
- url: string | undefined;
248
- /** Document encoding */
249
- doc_encoding: string | undefined;
250
- /** Document hash fragment */
251
- doc_hash: string;
252
- /** Document protocol (http/https) */
253
- doc_protocol: string | undefined;
254
- /** Document search parameters */
255
- doc_search: string;
256
- /** Document host domain */
257
- doc_host: string | undefined;
258
- /** Document path */
259
- doc_path: string | undefined;
260
- /** Page title */
261
- title: string | undefined;
262
- /** Language identifier */
263
- language_id?: string;
264
- /** Persona identifier */
265
- persona?: string;
266
- }
267
- /**
268
- * Analytics.js hook parameter types for DotCMS.
269
- * Represents the payload structure used by Analytics.js lifecycle hooks
270
- * for intercepting and modifying analytics events.
271
- */
272
- export interface DotCMSAnalyticsHookPayload {
273
- /** The type of analytics event */
274
- type: string;
275
- /** Properties associated with the event */
276
- properties: {
277
- /** Page title */
278
- title: string;
279
- /** Page URL */
280
- url: string;
281
- /** Page path */
282
- path: string;
283
- /** URL hash fragment */
284
- hash: string;
285
- /** URL search parameters */
286
- search: string;
287
- /** Viewport width */
288
- width: number;
289
- /** Viewport height */
290
- height: number;
291
- /** Referrer URL */
292
- referrer?: string;
293
- };
294
- /** Configuration options for the event */
295
- options: Record<string, unknown>;
296
- /** User identifier */
297
- userId: string | null;
298
- /** Anonymous user identifier */
299
- anonymousId: string;
300
- /** Metadata about the event */
301
- meta: {
302
- /** Request identifier */
303
- rid: string;
304
- /** Timestamp */
305
- ts: number;
306
- /** Whether the event has a callback function */
307
- hasCallback: boolean;
308
- };
309
- }
310
- /**
311
- * Analytics.js instance structure for DotCMS.
312
- * Represents the internal structure of an Analytics.js instance,
313
- * providing access to plugins, storage, and event configuration.
314
- */
315
- export interface DotCMSAnalyticsInstance {
316
- /** Available plugins and their configurations */
317
- plugins: Record<string, unknown>;
318
- /** Storage mechanisms for analytics data */
319
- storage: Record<string, unknown>;
320
- /** Event configuration */
321
- events: {
322
- /** Core event types */
323
- core: string[];
324
- /** Plugin-specific event types */
325
- plugins: string[];
326
- };
327
- }
328
- /**
329
- * Parameters passed to Analytics.js hook functions in DotCMS.
330
- * Contains all the context and data needed for Analytics.js lifecycle hooks
331
- * to process and modify analytics events.
332
- */
333
- export interface DotCMSAnalyticsHookParams {
334
- /** The event payload data */
335
- payload: DotCMSAnalyticsHookPayload;
336
- /** The analytics instance */
337
- instance: DotCMSAnalyticsInstance;
338
- /** Global configuration settings */
339
- config: Record<string, unknown>;
340
- /** Available plugins and their status */
341
- plugins: Record<string, {
342
- /** Whether the plugin is enabled */
343
- enabled: boolean;
344
- /** Whether the plugin is initialized */
345
- initialized: boolean;
346
- /** Whether the plugin is loaded */
347
- loaded: boolean;
348
- /** Plugin-specific configuration */
349
- config: Record<string, unknown>;
350
- }>;
351
- }