@dotcms/events 0.0.0-stage → 26.10.5-1-next.2827
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 +516 -2
- package/decision.cjs.js +108 -0
- package/decision.esm.js +92 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +3674 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +1 -0
- package/index.esm.js +3672 -0
- package/markup.cjs.default.js +1 -0
- package/markup.cjs.js +161 -0
- package/markup.cjs.mjs +2 -0
- package/markup.d.ts +1 -0
- package/markup.esm.js +159 -0
- package/package.json +77 -4
- package/react.cjs.default.js +1 -0
- package/react.cjs.js +39 -0
- package/react.cjs.mjs +2 -0
- package/react.d.ts +1 -0
- package/react.esm.js +37 -0
- package/src/index.d.ts +8 -0
- package/src/lib/clicks/constants.d.ts +14 -0
- package/src/lib/clicks/plugin.d.ts +35 -0
- package/src/lib/clicks/tracker.d.ts +42 -0
- package/src/lib/clicks/utils.d.ts +13 -0
- package/src/lib/contentlets/constants.d.ts +36 -0
- package/src/lib/contentlets/utils.d.ts +64 -0
- package/src/lib/contentlets/viewport.d.ts +23 -0
- package/src/lib/events.d.ts +17 -0
- package/src/lib/experiments/api.d.ts +9 -0
- package/src/lib/experiments/boot.d.ts +53 -0
- package/src/lib/experiments/constants.d.ts +46 -0
- package/src/lib/experiments/decision.d.ts +53 -0
- package/src/lib/experiments/dom.d.ts +62 -0
- package/src/lib/experiments/engine.d.ts +66 -0
- package/src/lib/experiments/markup.d.ts +17 -0
- package/src/lib/experiments/models.d.ts +62 -0
- package/src/lib/experiments/plugin.d.ts +27 -0
- package/src/lib/experiments/store.d.ts +54 -0
- package/src/lib/impressions/constants.d.ts +28 -0
- package/src/lib/impressions/plugin.d.ts +38 -0
- package/src/lib/impressions/tracker.d.ts +67 -0
- package/src/lib/impressions/utils.d.ts +10 -0
- package/src/lib/models.d.ts +130 -0
- package/src/lib/pipeline/constants.d.ts +88 -0
- package/src/lib/pipeline/enricher/plugin.d.ts +32 -0
- package/src/lib/pipeline/identity/activity.d.ts +19 -0
- package/src/lib/pipeline/identity/plugin.d.ts +60 -0
- package/src/lib/pipeline/logger.d.ts +74 -0
- package/src/lib/pipeline/models.d.ts +588 -0
- package/src/lib/pipeline/navigation.d.ts +21 -0
- package/src/lib/pipeline/sender/http.d.ts +9 -0
- package/src/lib/pipeline/sender/plugin.d.ts +47 -0
- package/src/lib/pipeline/sender/queue.d.ts +33 -0
- package/src/lib/pipeline/utils.d.ts +119 -0
- package/src/lib/react/DotCMSExperiment.d.ts +36 -0
- package/src/markup.d.ts +7 -0
- package/src/react.d.ts +8 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { PipelineConfig, DotCMSContentImpressionPayload } from '../pipeline/models';
|
|
2
|
+
/** Callback function for impression events */
|
|
3
|
+
export type ImpressionCallback = (eventName: string, payload: DotCMSContentImpressionPayload) => void;
|
|
4
|
+
/** Subscription object with unsubscribe method */
|
|
5
|
+
export interface ImpressionSubscription {
|
|
6
|
+
unsubscribe: () => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Tracks content impressions using IntersectionObserver and dwell time.
|
|
10
|
+
* Emits events through subscriptions when impressions are detected.
|
|
11
|
+
*/
|
|
12
|
+
export declare class DotCMSImpressionTracker {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(config: PipelineConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Subscribe to impression events
|
|
17
|
+
* @param callback - Function called when impression is detected
|
|
18
|
+
* @returns Subscription object with unsubscribe method
|
|
19
|
+
*/
|
|
20
|
+
onImpression(callback: ImpressionCallback): ImpressionSubscription;
|
|
21
|
+
/** Notifies all subscribers of an impression */
|
|
22
|
+
private notifySubscribers;
|
|
23
|
+
/**
|
|
24
|
+
* Merges user config with defaults. IntersectionObserver throws on a visibility threshold
|
|
25
|
+
* outside 0 to 1, so one outside that range is clamped to it, with a warning
|
|
26
|
+
*/
|
|
27
|
+
private resolveImpressionConfig;
|
|
28
|
+
/** Initializes tracking: sets up observers, finds contentlets, handles visibility/navigation */
|
|
29
|
+
initialize(): void;
|
|
30
|
+
/** Sets up IntersectionObserver with configured visibility threshold */
|
|
31
|
+
private initializeIntersectionObserver;
|
|
32
|
+
/** Finds contentlets in DOM, validates them, and starts observing (respects maxNodes limit) */
|
|
33
|
+
private findAndObserveContentletElements;
|
|
34
|
+
/**
|
|
35
|
+
* Watches for contentlets added to the DOM, and for contentlets receiving their
|
|
36
|
+
* identifier, which the renderers print after hydration (throttled for performance)
|
|
37
|
+
*/
|
|
38
|
+
private initializeDynamicContentDetector;
|
|
39
|
+
/** Cancels all timers when page is hidden (prevents false impressions) */
|
|
40
|
+
private initializePageVisibilityHandler;
|
|
41
|
+
/**
|
|
42
|
+
* Resets tracking when the visitor goes to another page, or comes back to this one from the
|
|
43
|
+
* back/forward cache. It listens through onNavigation: the browser's Navigation API where
|
|
44
|
+
* there is one, which needs no patch of `history`
|
|
45
|
+
*/
|
|
46
|
+
private initializePageNavigationHandler;
|
|
47
|
+
/** Forgets the page's impressions, timers and elements, so the next view counts its own */
|
|
48
|
+
private forgetPageImpressions;
|
|
49
|
+
/** Handles visibility changes: starts timer on enter, cancels on exit */
|
|
50
|
+
private processIntersectionChanges;
|
|
51
|
+
/** Starts dwell timer; fires impression if element still visible when timer expires */
|
|
52
|
+
private startImpressionDwellTimer;
|
|
53
|
+
/** Cancels active dwell timer (element left viewport before dwell time) */
|
|
54
|
+
private cancelImpressionDwellTimer;
|
|
55
|
+
/** Fires impression event with content & position data (page data added by enricher plugin) */
|
|
56
|
+
private trackAndSendImpression;
|
|
57
|
+
/** Returns skip reason if element is hidden/too small, null if trackable */
|
|
58
|
+
private shouldSkipElement;
|
|
59
|
+
/** Post-dwell check: verifies element still meets visibility threshold */
|
|
60
|
+
private isElementStillVisible;
|
|
61
|
+
/** Checks if impression already fired in current page session */
|
|
62
|
+
private hasBeenTrackedInSession;
|
|
63
|
+
/** Marks impression as tracked (prevents duplicates in same page session) */
|
|
64
|
+
private markImpressionAsTracked;
|
|
65
|
+
/** Cleanup: disconnects observers, clears timers and state */
|
|
66
|
+
cleanup(): void;
|
|
67
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for impression tracking
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Checks if an element meets a specific visibility threshold
|
|
6
|
+
* @param element - The HTML element to check
|
|
7
|
+
* @param threshold - The required visibility ratio (0.0 to 1.0)
|
|
8
|
+
* @returns True if the element meets or exceeds the threshold
|
|
9
|
+
*/
|
|
10
|
+
export declare function isElementMeetingVisibilityThreshold(element: HTMLElement, threshold: number): boolean;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** A value in a pageview's custom data. */
|
|
2
|
+
export type DotCMSEventsJsonValue = string | number | boolean | null | undefined | DotCMSEventsJsonObject | DotCMSEventsJsonValue[];
|
|
3
|
+
/** The custom data a pageview carries. */
|
|
4
|
+
export type DotCMSEventsJsonObject = {
|
|
5
|
+
[key: string]: DotCMSEventsJsonValue;
|
|
6
|
+
};
|
|
7
|
+
/** Minimum level for the analytics core's console logs. */
|
|
8
|
+
export type DotCMSEventsLogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
9
|
+
/**
|
|
10
|
+
* Options for content impressions.
|
|
11
|
+
*/
|
|
12
|
+
export interface DotCMSEventsImpressionsConfig {
|
|
13
|
+
/** Share of the contentlet that must be in the viewport, from 0 to 1. Defaults to 0.5. */
|
|
14
|
+
visibilityThreshold?: number;
|
|
15
|
+
/** How long, in milliseconds, the contentlet must stay in view. Defaults to 750. */
|
|
16
|
+
dwellMs?: number;
|
|
17
|
+
/** Most contentlets tracked on a page. Defaults to 100. */
|
|
18
|
+
maxNodes?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Options for batching.
|
|
22
|
+
*/
|
|
23
|
+
export interface DotCMSEventsQueueConfig {
|
|
24
|
+
/** Most events in one batch; a full batch is sent at once. Defaults to 15. */
|
|
25
|
+
eventBatchSize?: number;
|
|
26
|
+
/** Milliseconds between sends. Defaults to 5000. */
|
|
27
|
+
flushInterval?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options for the experiments engine.
|
|
31
|
+
*/
|
|
32
|
+
export interface DotCMSEventsExperimentsConfig {
|
|
33
|
+
/**
|
|
34
|
+
* How long, in milliseconds, a pageview and the experiment's hidden rows wait for the
|
|
35
|
+
* assignment before the page is shown without it. Defaults to 3000, which is also the most:
|
|
36
|
+
* the hiding rule shows the content after 3000 ms on its own, so a longer value is reduced to
|
|
37
|
+
* 3000 rather than show the original and then replace it with the variant.
|
|
38
|
+
*/
|
|
39
|
+
timeout?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Configuration for `dotEvents.init()`.
|
|
43
|
+
*/
|
|
44
|
+
export interface DotCMSEventsConfig {
|
|
45
|
+
/** The dotCMS origin, the same value `createDotCMSClient` takes. */
|
|
46
|
+
dotcmsUrl: string;
|
|
47
|
+
/** The site's Site Auth, from the Content Analytics app. */
|
|
48
|
+
siteAuth: string;
|
|
49
|
+
/** A pageview on load and on every History change. Defaults to `true`. */
|
|
50
|
+
autoPageView?: boolean;
|
|
51
|
+
/** Content impressions. Off by default. */
|
|
52
|
+
impressions?: DotCMSEventsImpressionsConfig | boolean;
|
|
53
|
+
/** Content clicks. Off by default. */
|
|
54
|
+
clicks?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Experiments: `isUserIncluded`, the pageview hold, the redirect and
|
|
57
|
+
* `context.experiments`. On by default; `false` turns every part off.
|
|
58
|
+
*/
|
|
59
|
+
experiments?: boolean | DotCMSEventsExperimentsConfig;
|
|
60
|
+
/** Batching, as in today's analytics config. */
|
|
61
|
+
queue?: DotCMSEventsQueueConfig | boolean;
|
|
62
|
+
/** Logs what the SDK does to the console. */
|
|
63
|
+
debug?: boolean;
|
|
64
|
+
/** Minimum log level for the analytics core. */
|
|
65
|
+
logLevel?: DotCMSEventsLogLevel;
|
|
66
|
+
/**
|
|
67
|
+
* Called when something fails where the page cannot see it: dotCMS rejects events, an events
|
|
68
|
+
* request gets no answer, or the experiments check fails. Nothing is retried, and an error
|
|
69
|
+
* this handler throws is ignored.
|
|
70
|
+
*/
|
|
71
|
+
onError?: (error: DotCMSEventsError) => void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* What failed, for `onError`:
|
|
75
|
+
* - `REJECTED`: dotCMS answered an events request with an error, or accepted it but failed
|
|
76
|
+
* some of its events; `status` and `detail` (its error list) say why.
|
|
77
|
+
* - `NETWORK`: an events request got no answer.
|
|
78
|
+
* - `EXPERIMENTS`: `isUserIncluded` failed; a 403 means experiments are off for the site.
|
|
79
|
+
*/
|
|
80
|
+
export type DotCMSEventsErrorCode = 'REJECTED' | 'NETWORK' | 'EXPERIMENTS';
|
|
81
|
+
/** A failure reported to `onError`. */
|
|
82
|
+
export interface DotCMSEventsError {
|
|
83
|
+
code: DotCMSEventsErrorCode;
|
|
84
|
+
message: string;
|
|
85
|
+
/** The HTTP status, when dotCMS answered. */
|
|
86
|
+
status?: number;
|
|
87
|
+
/** What dotCMS said about the failure, for `REJECTED`. */
|
|
88
|
+
detail?: unknown;
|
|
89
|
+
/** How many events the failed request carried, for `REJECTED` and `NETWORK`. */
|
|
90
|
+
events?: number;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The events object. There is one per page: every import gets the same instance.
|
|
94
|
+
*/
|
|
95
|
+
export interface DotCMSEvents {
|
|
96
|
+
/** Starts the SDK. Calling it again with the same config does nothing. */
|
|
97
|
+
init(config: DotCMSEventsConfig): void;
|
|
98
|
+
/** Sends a conversion. dotCMS records its name and the page it happened on, nothing else. */
|
|
99
|
+
conversion(name: string): void;
|
|
100
|
+
/** Sends a pageview by hand, for apps that set `autoPageView: false`. */
|
|
101
|
+
pageView(data?: DotCMSEventsJsonObject): void;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The page fields `experimentMarkup` and `DotCMSExperiment` read. A dotCMS page asset fits,
|
|
105
|
+
* requested for the variant in the URL's `variantName`.
|
|
106
|
+
*/
|
|
107
|
+
export interface DotCMSEventsExperimentPage {
|
|
108
|
+
/** The experiment running on the page, if any. */
|
|
109
|
+
runningExperimentId?: string | null;
|
|
110
|
+
/** `variantId` is the variant the server rendered; `DEFAULT` when absent. */
|
|
111
|
+
viewAs?: {
|
|
112
|
+
variantId?: string | null;
|
|
113
|
+
} | null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* What a page prints so its experiment runs, from `experimentMarkup`. The style and the
|
|
117
|
+
* script go before the element that wraps what the experiment varies, in the HTML the server
|
|
118
|
+
* sends: the script decides the visitor's variant while that HTML is parsed.
|
|
119
|
+
*/
|
|
120
|
+
export interface DotCMSEventsExperimentMarkup {
|
|
121
|
+
/** Attributes for the element that wraps what the experiment varies. */
|
|
122
|
+
attributes: {
|
|
123
|
+
'data-dot-experiment': string;
|
|
124
|
+
'data-dot-variant': string;
|
|
125
|
+
};
|
|
126
|
+
/** The rule that keeps that element hidden until the variant is decided. */
|
|
127
|
+
style: string;
|
|
128
|
+
/** The boot script's source, for an inline script element. */
|
|
129
|
+
script: string;
|
|
130
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** The window property that traditional pages and plain scripts reach `dotEvents` through. */
|
|
2
|
+
export declare const EVENTS_WINDOW_KEY = "dotEvents";
|
|
3
|
+
/**
|
|
4
|
+
* The Analytics.js name of the sender plugin. The enricher keys its hooks with it
|
|
5
|
+
* (`page:<name>`, `track:<name>`), so they run for the sender's calls only.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SENDER_PLUGIN_NAME = "dot-events-sender";
|
|
8
|
+
export declare const ANALYTICS_ENDPOINT = "/api/v1/analytics/content/event";
|
|
9
|
+
/**
|
|
10
|
+
* The event types dotCMS accepts, each with its own schema. It rejects any other type, so the
|
|
11
|
+
* SDK sends no custom events.
|
|
12
|
+
*/
|
|
13
|
+
export declare const DotCMSPredefinedEventType: {
|
|
14
|
+
readonly PAGEVIEW: "pageview";
|
|
15
|
+
readonly CONTENT_IMPRESSION: "content_impression";
|
|
16
|
+
readonly CONTENT_CLICK: "content_click";
|
|
17
|
+
readonly CONVERSION: "conversion";
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Type for structured events
|
|
21
|
+
*/
|
|
22
|
+
export type DotCMSPredefinedEventType = (typeof DotCMSPredefinedEventType)[keyof typeof DotCMSPredefinedEventType];
|
|
23
|
+
/**
|
|
24
|
+
* Expected UTM parameter keys for campaign tracking
|
|
25
|
+
*/
|
|
26
|
+
export declare const EXPECTED_UTM_KEYS: readonly ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
|
|
27
|
+
/**
|
|
28
|
+
* Session configuration constants
|
|
29
|
+
*/
|
|
30
|
+
export declare const DEFAULT_SESSION_TIMEOUT_MINUTES = 30;
|
|
31
|
+
/**
|
|
32
|
+
* Session storage key for session ID
|
|
33
|
+
*/
|
|
34
|
+
export declare const SESSION_STORAGE_KEY = "dot_events_session_id";
|
|
35
|
+
/**
|
|
36
|
+
* User ID configuration constants
|
|
37
|
+
*/
|
|
38
|
+
export declare const USER_ID_KEY = "dot_events_user_id";
|
|
39
|
+
/**
|
|
40
|
+
* Activity tracking configuration
|
|
41
|
+
* Events used to detect user activity for session management
|
|
42
|
+
* - click: Detects real user interaction with minimal performance impact
|
|
43
|
+
* - visibilitychange: Handled separately to detect tab changes
|
|
44
|
+
*/
|
|
45
|
+
export declare const ACTIVITY_EVENTS: readonly ["click"];
|
|
46
|
+
/**
|
|
47
|
+
* Default queue configuration for event batching
|
|
48
|
+
*/
|
|
49
|
+
export declare const DEFAULT_QUEUE_CONFIG: {
|
|
50
|
+
readonly eventBatchSize: 15;
|
|
51
|
+
readonly flushInterval: 5000;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Default properties that Analytics.js adds automatically
|
|
55
|
+
* These should be filtered out to only keep user-provided properties
|
|
56
|
+
*/
|
|
57
|
+
export declare const ANALYTICS_JS_DEFAULT_PROPERTIES: readonly ["title", "url", "path", "hash", "search", "width", "height", "referrer"];
|
|
58
|
+
/**
|
|
59
|
+
* Window flag that says the SDK is active on the page. Not this package's name to change:
|
|
60
|
+
* `@dotcms/uve/internal` declares it too (`ANALYTICS_ACTIVE_WINDOW_KEY`), and the React, Vue
|
|
61
|
+
* and Angular SDKs read it to print the contentlet attributes impressions and clicks need.
|
|
62
|
+
*/
|
|
63
|
+
export declare const ANALYTICS_WINDOWS_ACTIVE_KEY = "__dotAnalyticsActive__";
|
|
64
|
+
/**
|
|
65
|
+
* Window event sent once the SDK is active, so the renderers that read
|
|
66
|
+
* `ANALYTICS_WINDOWS_ACTIVE_KEY` render again. Shared with `@dotcms/uve/internal`
|
|
67
|
+
* (`ANALYTICS_READY_EVENT`) like that flag.
|
|
68
|
+
*/
|
|
69
|
+
export declare const ANALYTICS_READY_EVENT = "dotcms:analytics:ready";
|
|
70
|
+
/**
|
|
71
|
+
* Queue persistence configuration constants
|
|
72
|
+
* Used for storing events in sessionStorage for traditional page navigations
|
|
73
|
+
*/
|
|
74
|
+
/**
|
|
75
|
+
* Session storage key for persistent tab ID
|
|
76
|
+
* This ID remains constant across page navigations within the same browser tab
|
|
77
|
+
*/
|
|
78
|
+
export declare const TAB_ID_STORAGE_KEY = "dot_events_tab_id";
|
|
79
|
+
/**
|
|
80
|
+
* Prefix for queue storage key in sessionStorage
|
|
81
|
+
* Full key format: dot_events_queue_{tabId}
|
|
82
|
+
*/
|
|
83
|
+
export declare const QUEUE_STORAGE_KEY_PREFIX = "dot_events_queue";
|
|
84
|
+
/**
|
|
85
|
+
* Maximum age in milliseconds for persisted events
|
|
86
|
+
* Events older than this will be discarded (24 hours)
|
|
87
|
+
*/
|
|
88
|
+
export declare const MAX_EVENT_AGE_MS: number;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AnalyticsBasePayloadWithContext, AnalyticsTrackPayloadWithContext, EnrichedAnalyticsPayload, EnrichedTrackPayload } from '../models';
|
|
2
|
+
/**
|
|
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.
|
|
5
|
+
*
|
|
6
|
+
* The identity plugin, registered first, injects context: { session_id, site_auth, user_id, device }.
|
|
7
|
+
* This plugin, registered after the experiments, impressions and clicks plugins, adds page, UTM
|
|
8
|
+
* and custom data. The sender, registered last, structures the events and sends them.
|
|
9
|
+
*
|
|
10
|
+
* This plugin is ONLY responsible for data enrichment - NOT for event structuring or business logic.
|
|
11
|
+
*/
|
|
12
|
+
export declare const enricherPlugin: () => {
|
|
13
|
+
name: string;
|
|
14
|
+
/**
|
|
15
|
+
* PAGE VIEW ENRICHMENT - Runs after identity context injection
|
|
16
|
+
* Returns enriched payload with page, utm, and custom data added
|
|
17
|
+
* @returns {EnrichedAnalyticsPayload} Enriched payload ready for event creation
|
|
18
|
+
*/
|
|
19
|
+
"page:dot-events-sender": ({ payload }: {
|
|
20
|
+
payload: AnalyticsBasePayloadWithContext;
|
|
21
|
+
}) => EnrichedAnalyticsPayload;
|
|
22
|
+
/**
|
|
23
|
+
* TRACK EVENT ENRICHMENT - Runs after identity context injection
|
|
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
|
|
28
|
+
*/
|
|
29
|
+
"track:dot-events-sender": ({ payload }: {
|
|
30
|
+
payload: AnalyticsTrackPayloadWithContext;
|
|
31
|
+
}) => EnrichedTrackPayload;
|
|
32
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ANALYTICS_WINDOWS_ACTIVE_KEY } from '../constants';
|
|
2
|
+
import type { PipelineConfig } from '../models';
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
[ANALYTICS_WINDOWS_ACTIVE_KEY]?: boolean;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Updates session activity with throttling
|
|
10
|
+
*/
|
|
11
|
+
export declare const updateSessionActivity: () => void;
|
|
12
|
+
/**
|
|
13
|
+
* Initializes activity tracking
|
|
14
|
+
*/
|
|
15
|
+
export declare const initializeActivityTracking: (config: PipelineConfig) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Cleans up activity tracking listeners and resets analytics state
|
|
18
|
+
*/
|
|
19
|
+
export declare const cleanupActivityTracking: () => void;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { AnalyticsBaseParams, PipelineConfig } from '../models';
|
|
2
|
+
/**
|
|
3
|
+
* Identity plugin of the events pipeline.
|
|
4
|
+
* Handles user ID generation, session management, and activity tracking.
|
|
5
|
+
* This plugin provides consistent identity context across all analytics events.
|
|
6
|
+
*
|
|
7
|
+
* It runs first: events.ts registers identity, experiments, impressions, clicks, enricher and
|
|
8
|
+
* sender, in that order, and each plugin reads what the ones before it wrote.
|
|
9
|
+
*
|
|
10
|
+
* @param {PipelineConfig} config - Configuration object containing server URL, site key, and debug settings
|
|
11
|
+
* @returns {Object} Plugin object with methods for initialization and event processing
|
|
12
|
+
*/
|
|
13
|
+
export declare const identityPlugin: (config: PipelineConfig) => {
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* Initialize the identity plugin
|
|
17
|
+
* Sets up activity tracking for session management
|
|
18
|
+
*/
|
|
19
|
+
initialize: () => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Inject identity context into page events and updates session activity for session management
|
|
22
|
+
* This runs BEFORE the enricher plugin
|
|
23
|
+
*/
|
|
24
|
+
pageStart: ({ payload }: AnalyticsBaseParams) => {
|
|
25
|
+
context: import("../models").EventContext;
|
|
26
|
+
type: "page" | "track";
|
|
27
|
+
properties: Record<string, unknown>;
|
|
28
|
+
options: Record<string, unknown>;
|
|
29
|
+
userId: string;
|
|
30
|
+
anonymousId: string;
|
|
31
|
+
meta: {
|
|
32
|
+
rid: string;
|
|
33
|
+
ts: number;
|
|
34
|
+
hasCallback: boolean;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Inject identity context into track events and updates session activity for session management
|
|
39
|
+
* This runs BEFORE the enricher plugin
|
|
40
|
+
*/
|
|
41
|
+
trackStart: ({ payload }: AnalyticsBaseParams) => {
|
|
42
|
+
context: import("../models").EventContext;
|
|
43
|
+
type: "page" | "track";
|
|
44
|
+
properties: Record<string, unknown>;
|
|
45
|
+
options: Record<string, unknown>;
|
|
46
|
+
userId: string;
|
|
47
|
+
anonymousId: string;
|
|
48
|
+
meta: {
|
|
49
|
+
rid: string;
|
|
50
|
+
ts: number;
|
|
51
|
+
hasCallback: boolean;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Cleans up activity tracking when the browser discards the page. A page kept in the
|
|
56
|
+
* back/forward cache keeps it, and keeps `__dotAnalyticsActive__` set, so the
|
|
57
|
+
* renderers still print the contentlet attributes once the visitor goes back to it.
|
|
58
|
+
*/
|
|
59
|
+
loaded: () => boolean;
|
|
60
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log level type for the DotLogger
|
|
3
|
+
*/
|
|
4
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
5
|
+
/**
|
|
6
|
+
* Custom logger for DotCMS SDK
|
|
7
|
+
* Provides structured logging with context identification and configurable log level filtering
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const logger = new DotLogger('events', 'Impression', 'info');
|
|
12
|
+
* logger.debug('This will not show'); // Below threshold
|
|
13
|
+
* logger.info('Tracker initialized'); // Shows
|
|
14
|
+
* logger.error('Failed to track'); // Shows
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class DotLogger {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(packageName: string, context: string, minLevel?: LogLevel);
|
|
20
|
+
/**
|
|
21
|
+
* Creates the formatted prefix for log messages
|
|
22
|
+
* Format: [dotCMS packageName | Context] [LEVEL]
|
|
23
|
+
*/
|
|
24
|
+
private getPrefix;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a log level should be displayed based on the minimum threshold
|
|
27
|
+
*/
|
|
28
|
+
private shouldLog;
|
|
29
|
+
/**
|
|
30
|
+
* Log a DEBUG level message
|
|
31
|
+
* Used for detailed debugging information
|
|
32
|
+
*/
|
|
33
|
+
debug(...args: unknown[]): void;
|
|
34
|
+
/**
|
|
35
|
+
* Log an INFO level message
|
|
36
|
+
* Used for general informational messages
|
|
37
|
+
*/
|
|
38
|
+
info(...args: unknown[]): void;
|
|
39
|
+
/**
|
|
40
|
+
* Log a WARN level message
|
|
41
|
+
* Used for warning messages that don't prevent operation
|
|
42
|
+
*/
|
|
43
|
+
warn(...args: unknown[]): void;
|
|
44
|
+
/**
|
|
45
|
+
* Log an ERROR level message
|
|
46
|
+
* Always logs regardless of threshold for critical errors
|
|
47
|
+
*/
|
|
48
|
+
error(...args: unknown[]): void;
|
|
49
|
+
/**
|
|
50
|
+
* Create a console group for organizing related log messages
|
|
51
|
+
* Respects the minimum log level threshold
|
|
52
|
+
*/
|
|
53
|
+
group(label: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* End the current console group
|
|
56
|
+
* Respects the minimum log level threshold
|
|
57
|
+
*/
|
|
58
|
+
groupEnd(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Start a timer with the given label
|
|
61
|
+
* Useful for performance measurements
|
|
62
|
+
*/
|
|
63
|
+
time(label: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* End a timer and log the elapsed time
|
|
66
|
+
* Useful for performance measurements
|
|
67
|
+
*/
|
|
68
|
+
timeEnd(label: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Log a message (alias for info)
|
|
71
|
+
* Provided for backward compatibility
|
|
72
|
+
*/
|
|
73
|
+
log(...args: unknown[]): void;
|
|
74
|
+
}
|