@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.
Files changed (57) hide show
  1. package/README.md +516 -2
  2. package/decision.cjs.js +108 -0
  3. package/decision.esm.js +92 -0
  4. package/index.cjs.default.js +1 -0
  5. package/index.cjs.js +3674 -0
  6. package/index.cjs.mjs +2 -0
  7. package/index.d.ts +1 -0
  8. package/index.esm.js +3672 -0
  9. package/markup.cjs.default.js +1 -0
  10. package/markup.cjs.js +161 -0
  11. package/markup.cjs.mjs +2 -0
  12. package/markup.d.ts +1 -0
  13. package/markup.esm.js +159 -0
  14. package/package.json +77 -4
  15. package/react.cjs.default.js +1 -0
  16. package/react.cjs.js +39 -0
  17. package/react.cjs.mjs +2 -0
  18. package/react.d.ts +1 -0
  19. package/react.esm.js +37 -0
  20. package/src/index.d.ts +8 -0
  21. package/src/lib/clicks/constants.d.ts +14 -0
  22. package/src/lib/clicks/plugin.d.ts +35 -0
  23. package/src/lib/clicks/tracker.d.ts +42 -0
  24. package/src/lib/clicks/utils.d.ts +13 -0
  25. package/src/lib/contentlets/constants.d.ts +36 -0
  26. package/src/lib/contentlets/utils.d.ts +64 -0
  27. package/src/lib/contentlets/viewport.d.ts +23 -0
  28. package/src/lib/events.d.ts +17 -0
  29. package/src/lib/experiments/api.d.ts +9 -0
  30. package/src/lib/experiments/boot.d.ts +53 -0
  31. package/src/lib/experiments/constants.d.ts +46 -0
  32. package/src/lib/experiments/decision.d.ts +53 -0
  33. package/src/lib/experiments/dom.d.ts +62 -0
  34. package/src/lib/experiments/engine.d.ts +66 -0
  35. package/src/lib/experiments/markup.d.ts +17 -0
  36. package/src/lib/experiments/models.d.ts +62 -0
  37. package/src/lib/experiments/plugin.d.ts +27 -0
  38. package/src/lib/experiments/store.d.ts +54 -0
  39. package/src/lib/impressions/constants.d.ts +28 -0
  40. package/src/lib/impressions/plugin.d.ts +38 -0
  41. package/src/lib/impressions/tracker.d.ts +67 -0
  42. package/src/lib/impressions/utils.d.ts +10 -0
  43. package/src/lib/models.d.ts +130 -0
  44. package/src/lib/pipeline/constants.d.ts +88 -0
  45. package/src/lib/pipeline/enricher/plugin.d.ts +32 -0
  46. package/src/lib/pipeline/identity/activity.d.ts +19 -0
  47. package/src/lib/pipeline/identity/plugin.d.ts +60 -0
  48. package/src/lib/pipeline/logger.d.ts +74 -0
  49. package/src/lib/pipeline/models.d.ts +588 -0
  50. package/src/lib/pipeline/navigation.d.ts +21 -0
  51. package/src/lib/pipeline/sender/http.d.ts +9 -0
  52. package/src/lib/pipeline/sender/plugin.d.ts +47 -0
  53. package/src/lib/pipeline/sender/queue.d.ts +33 -0
  54. package/src/lib/pipeline/utils.d.ts +119 -0
  55. package/src/lib/react/DotCMSExperiment.d.ts +36 -0
  56. package/src/markup.d.ts +7 -0
  57. package/src/react.d.ts +8 -0
@@ -0,0 +1,119 @@
1
+ import { DotLogger } from './logger';
2
+ import type { LogLevel } from './logger';
3
+ import type { AnalyticsBasePayloadWithContext, PipelineConfig, EventContext, DotCMSBrowserData, DotCMSEventDeviceData, DotCMSEventUtmData, EnrichedAnalyticsPayload } from './models';
4
+ export { cleanupActivityTracking, initializeActivityTracking, updateSessionActivity } from './identity/activity';
5
+ /**
6
+ * Generates a random ID from the current time and Math.random: unique enough for session and
7
+ * user ids, but not cryptographically secure.
8
+ * @internal This function is for internal use only and should not be used outside of the SDK.
9
+ * @param prefix - The prefix for the generated ID
10
+ * @returns A unique ID string with the given prefix
11
+ */
12
+ export declare const generateSecureId: (prefix: string) => string;
13
+ /**
14
+ * Safe sessionStorage wrapper with error handling
15
+ */
16
+ export declare const safeSessionStorage: {
17
+ getItem: (key: string) => string | null;
18
+ setItem: (key: string, value: string) => void;
19
+ removeItem: (key: string) => void;
20
+ };
21
+ /**
22
+ * Gets or generates a user ID from localStorage.
23
+ * @internal This function is for internal use only.
24
+ * @returns The user ID string
25
+ */
26
+ export declare const getUserId: () => string;
27
+ /**
28
+ * Gets session ID with comprehensive lifecycle management.
29
+ * Returns existing valid session ID or creates a new one if needed.
30
+ * @internal This function is for internal use only.
31
+ *
32
+ * Session validation criteria:
33
+ * 1. User is still active (< 30 min inactivity)
34
+ * 2. Session hasn't passed midnight (UTC)
35
+ *
36
+ * @returns The session ID string
37
+ */
38
+ export declare const getSessionId: () => string;
39
+ /**
40
+ * Gets analytics context with user and session identification.
41
+ * Used by the identity plugin to inject context into analytics events.
42
+ *
43
+ * @param config - The analytics configuration object
44
+ * @returns The analytics context with site_auth, session_id, user_id and device
45
+ */
46
+ export declare const getEventContext: (config: PipelineConfig) => EventContext;
47
+ /**
48
+ * Configuration result with warnings for analytics setup
49
+ */
50
+ export interface AnalyticsConfigResult {
51
+ config: PipelineConfig;
52
+ warnings?: string[];
53
+ missingAttributes?: string[];
54
+ hasIssues: boolean;
55
+ }
56
+ /**
57
+ * Gets current device data for analytics.
58
+ * Combines static browser data with dynamic viewport information.
59
+ * Used by the identity plugin to inject device data into context.
60
+ *
61
+ * @returns Device data with screen resolution, language, and viewport dimensions
62
+ */
63
+ export declare const getDeviceDataForContext: () => DotCMSEventDeviceData;
64
+ /**
65
+ * Retrieves the browser event data - optimized but accurate.
66
+ * @internal This function is for internal use only.
67
+ * @param location - The Location object to extract data from
68
+ * @returns Browser event data with all relevant information
69
+ */
70
+ export declare const getBrowserEventData: (location: Location) => DotCMSBrowserData;
71
+ /**
72
+ * Extracts and transforms UTM parameters from the URL - cached for performance.
73
+ * Returns UTM data in DotCMS format (without 'utm_' prefix).
74
+ * @internal This function is for internal use only.
75
+ * @param location - The Location object to extract UTM parameters from
76
+ * @returns DotCMSEventUtmData object with transformed UTM parameters (source, medium, campaign, etc.)
77
+ */
78
+ export declare const extractUTMParameters: (location: Location) => DotCMSEventUtmData;
79
+ /**
80
+ * Gets local time in ISO format without milliseconds.
81
+ * Used by enricher plugins to add local_time to events.
82
+ *
83
+ * @returns Local time string in ISO 8601 format with timezone offset (e.g., "2024-01-01T12:00:00-05:00")
84
+ */
85
+ export declare const getLocalTime: () => string;
86
+ /**
87
+ * Optimized payload enrichment using existing analytics.js data.
88
+ * Filters out Analytics.js default properties and only keeps user-provided properties in custom.
89
+ * Used by the enricher plugin to transform Analytics.js payload into DotCMS event format.
90
+ *
91
+ * @param payload - The Analytics.js payload with context already injected by identity plugin
92
+ * @param location - The Location object to extract page data from (defaults to window.location)
93
+ * @returns Enriched payload with page, UTM, custom data, and local_time (device is in context)
94
+ */
95
+ export declare const enrichPagePayloadOptimized: (payload: AnalyticsBasePayloadWithContext, location?: Location) => EnrichedAnalyticsPayload;
96
+ /**
97
+ * Checks if code is running in a browser environment
98
+ * @returns true if window and document are available
99
+ */
100
+ export declare const isBrowser: () => boolean;
101
+ /**
102
+ * Runs a callback when the browser discards the page. A page it keeps in the back/forward
103
+ * cache (`pagehide` with `persisted`) comes back as it was when the visitor returns, with its
104
+ * listeners and observers, so it is left alone. `beforeunload` is not used: it fires before the
105
+ * page goes into that cache too.
106
+ *
107
+ * @param discarded - Called on the `pagehide` that discards the page
108
+ */
109
+ export declare const onPageDiscard: (discarded: () => void) => void;
110
+ /**
111
+ * Creates a logger with plugin-specific prefix and configurable log level
112
+ * @param pluginName - Name of the plugin (e.g., 'Click', 'Impression')
113
+ * @param config - Analytics configuration with debug flag and optional logLevel
114
+ * @returns DotLogger instance with configured log level
115
+ */
116
+ export declare const createPluginLogger: (pluginName: string, config: {
117
+ debug: boolean;
118
+ logLevel?: LogLevel;
119
+ }) => DotLogger;
@@ -0,0 +1,36 @@
1
+ import type { DotCMSEventsExperimentPage } from '../models';
2
+ import type { ReactElement, ReactNode } from 'react';
3
+ export interface DotCMSExperimentProps {
4
+ /**
5
+ * The page asset, requested for the variant in the URL's `variantName`. The component reads
6
+ * the experiment running on it and the variant the server rendered.
7
+ */
8
+ page: DotCMSEventsExperimentPage | null | undefined;
9
+ /** Nonce for the inline style and script, on pages with a nonce-based Content-Security-Policy. */
10
+ nonce?: string;
11
+ /** Class for the element that wraps the content. */
12
+ className?: string;
13
+ /** What the experiment varies: the page's layout, or content the view renders itself. */
14
+ children: ReactNode;
15
+ }
16
+ /**
17
+ * Runs the page's experiment on its content. On a page that runs an experiment, it wraps the
18
+ * content in an element marked with the experiment and the variant the server rendered, keeps
19
+ * it hidden, and prints the script that decides the visitor's variant while the HTML loads.
20
+ * `dotEvents` then shows the content, or the page is replaced with the assigned variant. On any
21
+ * other page it renders the content alone.
22
+ *
23
+ * It has no hooks, so it also renders in a server component, which keeps the script builder
24
+ * out of the client bundle.
25
+ *
26
+ * @param props - The page asset, an optional nonce and class, and the content
27
+ * @returns The content, marked and hidden until its variant is decided on an experiment page
28
+ *
29
+ * @example
30
+ * ```tsx
31
+ * <DotCMSExperiment page={pageAsset}>
32
+ * <DotCMSLayoutBody page={pageAsset} components={pageComponents} />
33
+ * </DotCMSExperiment>
34
+ * ```
35
+ */
36
+ export declare const DotCMSExperiment: ({ page, nonce, className, children }: DotCMSExperimentProps) => ReactElement;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `@dotcms/events/markup`: what a page prints so its experiment runs, for any framework that
3
+ * renders HTML on the server. It has its own entry so the SDK, which every page loads, never
4
+ * references the boot script builder.
5
+ */
6
+ export { experimentMarkup } from './lib/experiments/markup';
7
+ export type { DotCMSEventsExperimentMarkup, DotCMSEventsExperimentPage } from './lib/models';
package/src/react.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * `@dotcms/events/react`: `DotCMSExperiment`, which prints the markup for React. The only
3
+ * entry that imports React. It brings the markup and never the SDK, which loads with
4
+ * `dotEvents.init`.
5
+ */
6
+ export { DotCMSExperiment } from './lib/react/DotCMSExperiment';
7
+ export type { DotCMSExperimentProps } from './lib/react/DotCMSExperiment';
8
+ export type { DotCMSEventsExperimentPage } from './lib/models';