@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
@@ -0,0 +1,63 @@
1
+ import { Analytics as c } from "analytics";
2
+ import { ANALYTICS_WINDOWS_ACTIVE_KEY as r, ANALYTICS_WINDOWS_CLEANUP_KEY as l } from "../../uve/src/internal/constants.js";
3
+ import { dotAnalyticsClickPlugin as d } from "./plugin/click/dot-analytics.click.plugin.js";
4
+ import { dotAnalyticsEnricherPlugin as m } from "./plugin/enricher/dot-analytics.enricher.plugin.js";
5
+ import { dotAnalyticsIdentityPlugin as u } from "./plugin/identity/dot-analytics.identity.plugin.js";
6
+ import { dotAnalyticsImpressionPlugin as p } from "./plugin/impression/dot-analytics.impression.plugin.js";
7
+ import { dotAnalytics as y } from "./plugin/main/dot-analytics.plugin.js";
8
+ import { validateAnalyticsConfig as A, getEnhancedTrackingPlugins as f } from "./shared/utils/dot-analytics.utils.js";
9
+ import { cleanupActivityTracking as w } from "./plugin/identity/dot-analytics.identity.activity-tracker.js";
10
+ const v = (n) => {
11
+ const o = A(n);
12
+ if (o)
13
+ return console.error(
14
+ `DotCMS Analytics [Core]: Missing ${o.join(" and ")} in configuration`
15
+ ), typeof window < "u" && (window[r] = !1), null;
16
+ const a = f(
17
+ n,
18
+ p,
19
+ d
20
+ ), i = c({
21
+ app: "dotAnalytics",
22
+ debug: n.debug,
23
+ plugins: [
24
+ u(n),
25
+ // Inject identity context
26
+ ...a,
27
+ //Track content impressions & clicks (conditionally loaded)
28
+ m(),
29
+ // Enrich and clean payload with page, device, utm data and custom data
30
+ y(n)
31
+ // Send events to server
32
+ ]
33
+ }), e = () => w();
34
+ return typeof window < "u" && (window.addEventListener("beforeunload", e), window[l] = e, window[r] = !0, window.dispatchEvent(new CustomEvent("dotcms:analytics:ready"))), {
35
+ /**
36
+ * Track a page view.
37
+ * Session activity is automatically updated by the identity plugin.
38
+ * @param payload - Optional custom data to include with the page view (any valid JSON object)
39
+ */
40
+ pageView: (t = {}) => {
41
+ if (!i) {
42
+ console.warn("DotCMS Analytics [Core]: Analytics instance not initialized");
43
+ return;
44
+ }
45
+ i.page(t);
46
+ },
47
+ /**
48
+ * Track a custom event.
49
+ * @param eventName - The name of the event to track
50
+ * @param payload - Custom data to include with the event (any valid JSON object)
51
+ */
52
+ track: (t, s = {}) => {
53
+ if (!i) {
54
+ console.warn("DotCMS Analytics [Core]: Analytics instance not initialized");
55
+ return;
56
+ }
57
+ i.track(t, s);
58
+ }
59
+ };
60
+ };
61
+ export {
62
+ v as initializeContentAnalytics
63
+ };
@@ -0,0 +1,108 @@
1
+ import { DotCMSAnalyticsConfig, DotCMSContentClickPayload } from '../../shared/models';
2
+ /** Callback function for click events */
3
+ export type ClickCallback = (eventName: string, payload: DotCMSContentClickPayload) => void;
4
+ /** Subscription object with unsubscribe method */
5
+ export interface ClickSubscription {
6
+ unsubscribe: () => void;
7
+ }
8
+ /**
9
+ * Tracks content clicks using event listeners on contentlet containers.
10
+ * Detects clicks on <a> and <button> elements inside contentlets and fires events.
11
+ *
12
+ * Features:
13
+ * - Attaches event listeners to contentlet containers
14
+ * - Tracks clicks on anchor and button elements only
15
+ * - Uses MutationObserver to detect dynamically added content
16
+ * - Throttles rapid clicks to prevent duplicates (300ms)
17
+ * - Subscription-based event system for decoupling
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const tracker = new DotCMSClickTracker(config);
22
+ * const subscription = tracker.onClick((eventName, payload) => {
23
+ * console.log('Click detected:', payload);
24
+ * });
25
+ * tracker.initialize();
26
+ * // Later: subscription.unsubscribe();
27
+ * ```
28
+ */
29
+ export declare class DotCMSClickTracker {
30
+ private config;
31
+ private mutationObserver;
32
+ private lastClickTime;
33
+ private logger;
34
+ private subscribers;
35
+ private trackedElements;
36
+ private elementHandlers;
37
+ constructor(config: DotCMSAnalyticsConfig);
38
+ /**
39
+ * Subscribe to click events
40
+ * @param callback - Function called when click is detected
41
+ * @returns Subscription object with unsubscribe method
42
+ */
43
+ onClick(callback: ClickCallback): ClickSubscription;
44
+ /**
45
+ * Notifies all subscribers of a click event
46
+ * @param eventName - Name of the event (e.g., 'content_click')
47
+ * @param payload - Click event payload with content and element data
48
+ */
49
+ private notifySubscribers;
50
+ /**
51
+ * Initialize click tracking system
52
+ *
53
+ * Performs the following:
54
+ * - Validates browser environment
55
+ * - Scans for existing contentlets after a delay (100ms)
56
+ * - Sets up MutationObserver for dynamic content
57
+ *
58
+ * The delay allows React/Next.js to finish initial rendering
59
+ * before attaching listeners.
60
+ */
61
+ initialize(): void;
62
+ /**
63
+ * Attach click listener to a contentlet container
64
+ *
65
+ * Skips if element already has a listener attached.
66
+ * The listener delegates to handleContentletClick which:
67
+ * - Finds clicked anchor/button elements
68
+ * - Extracts contentlet and element data
69
+ * - Applies throttling (300ms)
70
+ * - Notifies subscribers
71
+ *
72
+ * @param element - Contentlet container element to track
73
+ */
74
+ private attachClickListener;
75
+ /**
76
+ * Find and attach listeners to all contentlet elements in the DOM
77
+ *
78
+ * Scans the entire document for elements with the
79
+ * `.dotcms-analytics-contentlet` class and attaches click
80
+ * listeners if not already tracked.
81
+ *
82
+ * Called during initialization and whenever DOM mutations are detected.
83
+ */
84
+ private findAndAttachListeners;
85
+ /**
86
+ * Initialize MutationObserver to detect new contentlet containers
87
+ * Uses same simple strategy as impression tracker - no complex filtering
88
+ */
89
+ private initializeMutationObserver;
90
+ /**
91
+ * Remove all click listeners from tracked contentlets
92
+ *
93
+ * Iterates through all contentlet elements and removes their
94
+ * click event handlers, cleaning up WeakMap references.
95
+ */
96
+ private removeAllListeners;
97
+ /**
98
+ * Cleanup all resources used by the click tracker
99
+ *
100
+ * Performs:
101
+ * - Removes all event listeners from contentlets
102
+ * - Disconnects MutationObserver
103
+ * - Clears internal references
104
+ *
105
+ * Should be called when the plugin is disabled or on page unload.
106
+ */
107
+ cleanup(): void;
108
+ }
@@ -0,0 +1,144 @@
1
+ import { handleContentletClick as c } from "./dot-analytics.click.utils.js";
2
+ import { DEFAULT_CLICK_THROTTLE_MS as d } from "../../shared/constants/dot-analytics.constants.js";
3
+ import { createPluginLogger as h, isBrowser as l, INITIAL_SCAN_DELAY_MS as g, findContentlets as r, createContentletObserver as u } from "../../shared/utils/dot-analytics.utils.js";
4
+ class C {
5
+ constructor(t) {
6
+ this.config = t, this.mutationObserver = null, this.lastClickTime = { value: 0 }, this.subscribers = /* @__PURE__ */ new Set(), this.trackedElements = /* @__PURE__ */ new WeakSet(), this.elementHandlers = /* @__PURE__ */ new WeakMap(), this.logger = h("Click", t);
7
+ }
8
+ /**
9
+ * Subscribe to click events
10
+ * @param callback - Function called when click is detected
11
+ * @returns Subscription object with unsubscribe method
12
+ */
13
+ onClick(t) {
14
+ return this.subscribers.add(t), {
15
+ unsubscribe: () => {
16
+ this.subscribers.delete(t);
17
+ }
18
+ };
19
+ }
20
+ /**
21
+ * Notifies all subscribers of a click event
22
+ * @param eventName - Name of the event (e.g., 'content_click')
23
+ * @param payload - Click event payload with content and element data
24
+ */
25
+ notifySubscribers(t, e) {
26
+ this.subscribers.forEach((i) => i(t, e));
27
+ }
28
+ /**
29
+ * Initialize click tracking system
30
+ *
31
+ * Performs the following:
32
+ * - Validates browser environment
33
+ * - Scans for existing contentlets after a delay (100ms)
34
+ * - Sets up MutationObserver for dynamic content
35
+ *
36
+ * The delay allows React/Next.js to finish initial rendering
37
+ * before attaching listeners.
38
+ */
39
+ initialize() {
40
+ if (!l()) {
41
+ this.logger.warn("No document, skipping");
42
+ return;
43
+ }
44
+ this.logger.debug("Plugin initializing"), typeof window < "u" && setTimeout(() => {
45
+ this.logger.debug("Running initial scan after timeout..."), this.findAndAttachListeners();
46
+ }, g), this.initializeMutationObserver(), this.logger.info("Plugin initialized");
47
+ }
48
+ /**
49
+ * Attach click listener to a contentlet container
50
+ *
51
+ * Skips if element already has a listener attached.
52
+ * The listener delegates to handleContentletClick which:
53
+ * - Finds clicked anchor/button elements
54
+ * - Extracts contentlet and element data
55
+ * - Applies throttling (300ms)
56
+ * - Notifies subscribers
57
+ *
58
+ * @param element - Contentlet container element to track
59
+ */
60
+ attachClickListener(t) {
61
+ if (this.trackedElements.has(t)) {
62
+ const n = t.dataset.dotAnalyticsIdentifier || "unknown";
63
+ this.logger.debug(`Element ${n} already has listener, skipping`);
64
+ return;
65
+ }
66
+ if (!t.dataset.dotAnalyticsDomIndex) {
67
+ const n = r();
68
+ t.dataset.dotAnalyticsDomIndex = String(n.indexOf(t));
69
+ }
70
+ const e = (n) => {
71
+ this.logger.debug("Click handler triggered on contentlet"), c(
72
+ n,
73
+ t,
74
+ (a, s) => {
75
+ const o = Date.now();
76
+ o - this.lastClickTime.value < d || (this.lastClickTime.value = o, this.notifySubscribers(a, s), this.logger.info(
77
+ `Fired click event for ${s.content.identifier}`,
78
+ s
79
+ ));
80
+ },
81
+ this.logger
82
+ );
83
+ };
84
+ t.addEventListener("click", e), this.trackedElements.add(t), this.elementHandlers.set(t, e);
85
+ const i = t.dataset.dotAnalyticsIdentifier || "unknown";
86
+ this.logger.log(`Attached listener to contentlet ${i}`, t);
87
+ }
88
+ /**
89
+ * Find and attach listeners to all contentlet elements in the DOM
90
+ *
91
+ * Scans the entire document for elements with the
92
+ * `.dotcms-analytics-contentlet` class and attaches click
93
+ * listeners if not already tracked.
94
+ *
95
+ * Called during initialization and whenever DOM mutations are detected.
96
+ */
97
+ findAndAttachListeners() {
98
+ this.logger.debug("findAndAttachListeners called");
99
+ const t = r();
100
+ this.logger.debug(`Scanning... found ${t.length} contentlets`);
101
+ let e = 0;
102
+ t.forEach((i) => {
103
+ const n = !this.trackedElements.has(i);
104
+ this.attachClickListener(i), n && this.trackedElements.has(i) && e++;
105
+ }), e > 0 && this.logger.info(`Attached ${e} new click listeners`);
106
+ }
107
+ /**
108
+ * Initialize MutationObserver to detect new contentlet containers
109
+ * Uses same simple strategy as impression tracker - no complex filtering
110
+ */
111
+ initializeMutationObserver() {
112
+ l() && (this.mutationObserver = u(() => {
113
+ this.findAndAttachListeners();
114
+ }), this.logger.info("MutationObserver enabled for click tracking"));
115
+ }
116
+ /**
117
+ * Remove all click listeners from tracked contentlets
118
+ *
119
+ * Iterates through all contentlet elements and removes their
120
+ * click event handlers, cleaning up WeakMap references.
121
+ */
122
+ removeAllListeners() {
123
+ r().forEach((e) => {
124
+ const i = this.elementHandlers.get(e);
125
+ i && (e.removeEventListener("click", i), this.elementHandlers.delete(e));
126
+ });
127
+ }
128
+ /**
129
+ * Cleanup all resources used by the click tracker
130
+ *
131
+ * Performs:
132
+ * - Removes all event listeners from contentlets
133
+ * - Disconnects MutationObserver
134
+ * - Clears internal references
135
+ *
136
+ * Should be called when the plugin is disabled or on page unload.
137
+ */
138
+ cleanup() {
139
+ this.removeAllListeners(), this.mutationObserver && (this.mutationObserver.disconnect(), this.mutationObserver = null), this.logger.info("Click tracking cleaned up");
140
+ }
141
+ }
142
+ export {
143
+ C as DotCMSClickTracker
144
+ };
@@ -0,0 +1,36 @@
1
+ import { AnalyticsInstance } from 'analytics';
2
+ import { DotCMSAnalyticsConfig } from '../../shared/models';
3
+ /**
4
+ * Click Plugin for DotAnalytics
5
+ * Handles automatic tracking of clicks on content elements.
6
+ *
7
+ * This plugin initializes the click tracker which:
8
+ * - Uses MutationObserver to detect contentlet containers
9
+ * - Attaches click listeners to each .dotcms-analytics-contentlet element
10
+ * - Filters for clicks on <a> or <button> elements inside tracked contentlets
11
+ * - Extracts contentlet data and element metadata
12
+ * - Throttles clicks to prevent duplicates
13
+ * - Fires 'content_click' events via subscription callback
14
+ *
15
+ * Note: This plugin is only registered if config.clicks is enabled.
16
+ * See getEnhancedTrackingPlugins() for conditional loading logic.
17
+ *
18
+ * @param {DotCMSAnalyticsConfig} config - Configuration with clicks settings
19
+ * @returns {Object} Plugin object with lifecycle methods
20
+ */
21
+ export declare const dotAnalyticsClickPlugin: (config: DotCMSAnalyticsConfig) => {
22
+ name: string;
23
+ /**
24
+ * Initialize click tracking
25
+ * Called when Analytics.js initializes the plugin with instance context
26
+ * @param instance - Analytics.js instance with track method
27
+ */
28
+ initialize: ({ instance }: {
29
+ instance: AnalyticsInstance;
30
+ }) => Promise<void>;
31
+ /**
32
+ * Setup cleanup handlers when plugin is loaded
33
+ * Called after Analytics.js completes plugin loading
34
+ */
35
+ loaded: () => boolean;
36
+ };
@@ -0,0 +1,27 @@
1
+ import { DotCMSClickTracker as o } from "./dot-analytics.click-tracker.js";
2
+ import { createPluginLogger as u, isBrowser as a, setupPluginCleanup as s } from "../../shared/utils/dot-analytics.utils.js";
3
+ const g = (n) => {
4
+ let i = null, l = null;
5
+ const e = u("Click", n);
6
+ return {
7
+ name: "dot-analytics-click",
8
+ /**
9
+ * Initialize click tracking
10
+ * Called when Analytics.js initializes the plugin with instance context
11
+ * @param instance - Analytics.js instance with track method
12
+ */
13
+ initialize: ({ instance: r }) => (i = new o(n), l = i.onClick((c, t) => {
14
+ r.track(c, t);
15
+ }), i.initialize(), e.info("Click tracking plugin initialized"), Promise.resolve()),
16
+ /**
17
+ * Setup cleanup handlers when plugin is loaded
18
+ * Called after Analytics.js completes plugin loading
19
+ */
20
+ loaded: () => (a() && i && s(() => {
21
+ l && (l.unsubscribe(), l = null), i && (i.cleanup(), i = null, e.info("Click tracking cleaned up on page unload"));
22
+ }), !0)
23
+ };
24
+ };
25
+ export {
26
+ g as dotAnalyticsClickPlugin
27
+ };
@@ -0,0 +1,12 @@
1
+ import { DotCMSContentClickPayload } from '../../shared/models';
2
+ import { createPluginLogger } from '../../shared/utils/dot-analytics.utils';
3
+ /**
4
+ * Handles click events on elements within a contentlet.
5
+ * The contentlet element is already known since we attach listeners to contentlets.
6
+ *
7
+ * @param event - The mouse event
8
+ * @param contentletElement - The contentlet container element
9
+ * @param trackCallback - Callback to execute if the click is valid
10
+ * @param logger - Logger instance for debug messages
11
+ */
12
+ export declare const handleContentletClick: (event: MouseEvent, contentletElement: HTMLElement, trackCallback: (eventName: string, payload: DotCMSContentClickPayload) => void, logger: ReturnType<typeof createPluginLogger>) => void;
@@ -0,0 +1,55 @@
1
+ import { CLICKABLE_ELEMENTS_SELECTOR as l, CLICK_EVENT_TYPE as m } from "../../shared/constants/dot-analytics.constants.js";
2
+ import { extractContentletData as p } from "../../shared/utils/dot-analytics.utils.js";
3
+ import { getViewportMetrics as b } from "../impression/dot-analytics.impression.utils.js";
4
+ const _ = (r, o, c, e) => {
5
+ const a = r.target;
6
+ e.debug("Click detected on:", a);
7
+ const t = a.closest(l);
8
+ if (!t) {
9
+ e.debug("No <a> or <button> found in click path");
10
+ return;
11
+ }
12
+ if (!o.contains(t)) {
13
+ e.debug("Click was outside contentlet boundary");
14
+ return;
15
+ }
16
+ e.debug("Found clickable element:", t);
17
+ const n = p(o);
18
+ if (!n.identifier) {
19
+ e.debug("Contentlet has no identifier");
20
+ return;
21
+ }
22
+ e.debug("Contentlet data:", n);
23
+ const d = b(o), s = [];
24
+ for (const i of t.attributes)
25
+ !i.name.startsWith("data-dot-analytics") && i.name !== "class" && i.name !== "id" && i.name !== "href" && s.push(`${i.name}:${i.value}`);
26
+ const f = parseInt(o.dataset.dotAnalyticsDomIndex || "-1", 10), u = {
27
+ content: {
28
+ identifier: n.identifier,
29
+ inode: n.inode,
30
+ title: n.title,
31
+ content_type: n.contentType
32
+ },
33
+ position: {
34
+ viewport_offset_pct: d.offsetPercentage,
35
+ dom_index: f
36
+ },
37
+ element: {
38
+ text: (t.innerText || t.textContent || "").trim().substring(0, 100),
39
+ // Limit length
40
+ type: t.tagName.toLowerCase(),
41
+ id: t.id || "",
42
+ // Required by backend, empty string if not present
43
+ class: t.className || "",
44
+ // Required by backend, empty string if not present
45
+ href: t.getAttribute("href") || "",
46
+ // Path as written in HTML (relative), empty string for buttons
47
+ attributes: s
48
+ // Additional attributes (data-*, aria-*, target, etc.)
49
+ }
50
+ };
51
+ c(m, u);
52
+ };
53
+ export {
54
+ _ as handleContentletClick
55
+ };
@@ -1,44 +1,32 @@
1
- import { DotCMSAnalyticsPayload } from '../../shared/dot-content-analytics.model';
1
+ import { AnalyticsBasePayloadWithContext, AnalyticsTrackPayloadWithContext, EnrichedAnalyticsPayload, EnrichedTrackPayload } from '../../shared/models';
2
2
  /**
3
- * Plugin that enriches the analytics payload data based on the event type.
4
- * Uses Analytics.js lifecycle events to inject context before processing.
5
- * The identity plugin runs FIRST to inject context: { session_id, site_key, user_id }
6
- * This enricher plugin runs SECOND to add page/device/utm data.
3
+ * Plugin that enriches the analytics payload data with page, UTM, and custom data.
4
+ * Uses Analytics.js lifecycle events to inject enriched data before the main plugin processes it.
7
5
  *
8
- * OPTIMIZED: Uses existing payload.properties data to avoid duplication
6
+ * The identity plugin runs FIRST to inject context: { session_id, site_auth, user_id, device }
7
+ * This enricher plugin runs SECOND to add page/utm/custom data.
8
+ * The main plugin runs THIRD to structure events and send to server.
9
+ *
10
+ * This plugin is ONLY responsible for data enrichment - NOT for event structuring or business logic.
9
11
  */
10
12
  export declare const dotAnalyticsEnricherPlugin: () => {
11
13
  name: string;
12
14
  /**
13
15
  * PAGE VIEW ENRICHMENT - Runs after identity context injection
14
- * Uses optimized enrichment that leverages analytics.js payload data
16
+ * Returns enriched payload with page, utm, and custom data added
17
+ * @returns {EnrichedAnalyticsPayload} Enriched payload ready for event creation
15
18
  */
16
19
  'page:dot-analytics': ({ payload }: {
17
- payload: DotCMSAnalyticsPayload;
18
- }) => {
19
- local_time: string;
20
- utm?: import('../../shared/dot-content-analytics.model').DotCMSUtmData;
21
- page: import('../../shared/dot-content-analytics.model').DotCMSPageData;
22
- device: import('../../shared/dot-content-analytics.model').DotCMSDeviceData;
23
- event: string;
24
- properties: Record<string, unknown>;
25
- options: Record<string, unknown>;
26
- context?: import('../../shared/dot-content-analytics.model').DotCMSAnalyticsContext;
27
- };
20
+ payload: AnalyticsBasePayloadWithContext;
21
+ }) => EnrichedAnalyticsPayload;
28
22
  /**
29
23
  * TRACK EVENT ENRICHMENT - Runs after identity context injection
30
- * Creates structured track events with pre-injected context
24
+ * Adds page data and timestamp for predefined content events.
25
+ * For custom events, only adds timestamp.
26
+ *
27
+ * @returns {EnrichedTrackPayload} Enriched payload ready for event structuring
31
28
  */
32
29
  'track:dot-analytics': ({ payload }: {
33
- payload: DotCMSAnalyticsPayload;
34
- }) => {
35
- events: {
36
- event_type: "track";
37
- local_time: string;
38
- data: {
39
- src: string;
40
- event: string;
41
- };
42
- }[];
43
- };
30
+ payload: AnalyticsTrackPayloadWithContext;
31
+ }) => EnrichedTrackPayload;
44
32
  };
@@ -1,31 +1,41 @@
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";
1
+ import { DotCMSPredefinedEventType as n } from "../../shared/constants/dot-analytics.constants.js";
2
+ import { getLocalTime as i, enrichPagePayloadOptimized as o } from "../../shared/utils/dot-analytics.utils.js";
3
3
  const l = () => ({
4
4
  name: "enrich-dot-analytics",
5
5
  /**
6
6
  * PAGE VIEW ENRICHMENT - Runs after identity context injection
7
- * Uses optimized enrichment that leverages analytics.js payload data
7
+ * Returns enriched payload with page, utm, and custom data added
8
+ * @returns {EnrichedAnalyticsPayload} Enriched payload ready for event creation
8
9
  */
9
- "page:dot-analytics": ({ payload: e }) => i(e),
10
- // TODO: Fix this when we haver the final design for the track event
10
+ "page:dot-analytics": ({
11
+ payload: t
12
+ }) => {
13
+ const e = o(t);
14
+ if (!e.page)
15
+ throw new Error("DotCMS Analytics: Missing required page data");
16
+ return e;
17
+ },
11
18
  /**
12
19
  * TRACK EVENT ENRICHMENT - Runs after identity context injection
13
- * Creates structured track events with pre-injected context
20
+ * Adds page data and timestamp for predefined content events.
21
+ * For custom events, only adds timestamp.
22
+ *
23
+ * @returns {EnrichedTrackPayload} Enriched payload ready for event structuring
14
24
  */
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
- ]
25
+ "track:dot-analytics": ({
26
+ payload: t
27
+ }) => {
28
+ const { event: e } = t, r = i();
29
+ return e === n.CONTENT_IMPRESSION || e === n.CONTENT_CLICK ? {
30
+ ...t,
31
+ page: {
32
+ title: document.title,
33
+ url: window.location.href
34
+ },
35
+ local_time: r
36
+ } : {
37
+ ...t,
38
+ local_time: r
29
39
  };
30
40
  }
31
41
  });
@@ -0,0 +1,20 @@
1
+ import { ANALYTICS_WINDOWS_ACTIVE_KEY, ANALYTICS_WINDOWS_CLEANUP_KEY } from '../../../../../../uve/src/internal.ts';
2
+ import { DotCMSAnalyticsConfig } from '../../shared/models';
3
+ declare global {
4
+ interface Window {
5
+ [ANALYTICS_WINDOWS_CLEANUP_KEY]?: () => void;
6
+ [ANALYTICS_WINDOWS_ACTIVE_KEY]?: boolean;
7
+ }
8
+ }
9
+ /**
10
+ * Updates session activity with throttling
11
+ */
12
+ export declare const updateSessionActivity: () => void;
13
+ /**
14
+ * Initializes activity tracking
15
+ */
16
+ export declare const initializeActivityTracking: (config: DotCMSAnalyticsConfig) => void;
17
+ /**
18
+ * Cleans up activity tracking listeners and resets analytics state
19
+ */
20
+ export declare const cleanupActivityTracking: () => void;