@dotcms/analytics
Version:
Official JavaScript library for Content Analytics with DotCMS.
178 lines (177 loc) • 6.38 kB
TypeScript
export declare const ANALYTICS_WINDOWS_KEY = "dotAnalytics";
export declare const ANALYTICS_SOURCE_TYPE = "dotAnalytics";
export declare const ANALYTICS_ENDPOINT = "/api/v1/analytics/content/event";
/**
* Structured event types - events with predefined data shapes
* These events have specific data structures and validation
*/
export declare const DotCMSPredefinedEventType: {
readonly PAGEVIEW: "pageview";
readonly CONTENT_IMPRESSION: "content_impression";
readonly CONTENT_CLICK: "content_click";
readonly CONVERSION: "conversion";
};
/**
* Type for structured events
*/
export type DotCMSPredefinedEventType = (typeof DotCMSPredefinedEventType)[keyof typeof DotCMSPredefinedEventType];
/**
* Custom event type - any string except predefined event types
* These events have flexible data structures defined by the user
*/
export type DotCMSCustomEventType = Exclude<string, DotCMSPredefinedEventType>;
/**
* Union type for all possible event types
*/
export type DotCMSEventType = DotCMSPredefinedEventType | DotCMSCustomEventType;
/**
* Expected UTM parameter keys for campaign tracking
*/
export declare const EXPECTED_UTM_KEYS: readonly ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
/**
* Session configuration constants
*/
export declare const DEFAULT_SESSION_TIMEOUT_MINUTES = 30;
/**
* Session storage key for session ID
*/
export declare const SESSION_STORAGE_KEY = "dot_analytics_session_id";
/**
* Session storage key for session start time
*/
export declare const SESSION_START_KEY = "dot_analytics_session_start";
/**
* Session storage key for session UTM data
*/
export declare const SESSION_UTM_KEY = "dot_analytics_session_utm";
/**
* User ID configuration constants
*/
export declare const USER_ID_KEY = "dot_analytics_user_id";
/**
* Activity tracking configuration
* Events used to detect user activity for session management
* - click: Detects real user interaction with minimal performance impact
* - visibilitychange: Handled separately to detect tab changes
*/
export declare const ACTIVITY_EVENTS: readonly ["click"];
/**
* Default queue configuration for event batching
*/
export declare const DEFAULT_QUEUE_CONFIG: {
readonly eventBatchSize: 15;
readonly flushInterval: 5000;
};
/**
* The name of the analytics minified script.
*/
export declare const ANALYTICS_MINIFIED_SCRIPT_NAME = "ca.min.js";
/**
* Default properties that Analytics.js adds automatically
* These should be filtered out to only keep user-provided properties
*/
export declare const ANALYTICS_JS_DEFAULT_PROPERTIES: readonly ["title", "url", "path", "hash", "search", "width", "height", "referrer"];
/**
* Impression tracking configuration constants
*/
/**
* Default minimum percentage of element that must be visible (0.0 to 1.0)
*/
export declare const DEFAULT_IMPRESSION_VISIBILITY_THRESHOLD = 0.5;
/**
* Default minimum time in milliseconds element must be visible
*/
export declare const DEFAULT_IMPRESSION_DWELL_MS = 750;
/**
* Default maximum number of elements to track (performance limit)
*/
export declare const DEFAULT_IMPRESSION_MAX_NODES = 100;
/**
* Default throttle time in milliseconds for intersection callbacks
*/
export declare const DEFAULT_IMPRESSION_THROTTLE_MS = 100;
/**
* Default debounce time in milliseconds for MutationObserver
*/
export declare const DEFAULT_IMPRESSION_MUTATION_OBSERVER_DEBOUNCE_MS = 250;
/**
* Default impression tracking configuration
*/
export declare const DEFAULT_IMPRESSION_CONFIG: {
readonly visibilityThreshold: 0.5;
readonly dwellMs: 750;
readonly maxNodes: 100;
readonly throttleMs: 100;
};
/**
* Event type for content impressions
* Must match DotCMSPredefinedEventType.CONTENT_IMPRESSION
*/
export declare const IMPRESSION_EVENT_TYPE = "content_impression";
/**
* Event type for content clicks
* Must match DotCMSPredefinedEventType.CONTENT_CLICK
*/
export declare const CLICK_EVENT_TYPE = "content_click";
/**
* Default debounce time in milliseconds for clicks
*/
export declare const DEFAULT_CLICK_THROTTLE_MS = 300;
/**
* CSS selector for clickable elements to track
* Only clicks on <a> and <button> elements are tracked
*/
export declare const CLICKABLE_ELEMENTS_SELECTOR = "a, button";
/**
* Session storage key for tracked impressions (deduplication)
*/
export declare const IMPRESSION_SESSION_KEY = "dot_analytics_impressions";
/**
* Window property key for analytics active state
* Used to track if analytics is initialized and active
*/
export declare const ANALYTICS_WINDOWS_ACTIVE_KEY = "__dotAnalyticsActive__";
/**
* Window property key for analytics cleanup function
* Used to store the cleanup function for analytics instance
*/
export declare const ANALYTICS_WINDOWS_CLEANUP_KEY = "__dotAnalyticsCleanup__";
/**
* CSS class selector for contentlet elements
*
* @important This constant is intentionally duplicated in @dotcms/react SDK
* (core-web/libs/sdk/react/src/lib/next/components/Contentlet/Contentlet.tsx).
* Both constants MUST have the same value ('dotcms-contentlet') for analytics
* tracking to work correctly with React-rendered contentlets.
*
* This duplication is intentional to maintain SDK independence:
* - @dotcms/analytics can be used standalone without React
* - @dotcms/react can be used without analytics
* - When both are used together, they must share the same class name
*
* If you need to change this value, you MUST update it in both locations:
* 1. This file (analytics SDK)
* 2. Contentlet.tsx in React SDK
*
* @see core-web/libs/sdk/react/src/lib/next/components/Contentlet/Contentlet.tsx
*/
export declare const CONTENTLET_CLASS = "dotcms-contentlet";
/**
* Queue persistence configuration constants
* Used for storing events in sessionStorage for traditional page navigations
*/
/**
* Session storage key for persistent tab ID
* This ID remains constant across page navigations within the same browser tab
*/
export declare const TAB_ID_STORAGE_KEY = "dot_analytics_tab_id";
/**
* Prefix for queue storage key in sessionStorage
* Full key format: dot_analytics_queue_{tabId}
*/
export declare const QUEUE_STORAGE_KEY_PREFIX = "dot_analytics_queue";
/**
* Maximum age in milliseconds for persisted events
* Events older than this will be discarded (24 hours)
*/
export declare const MAX_EVENT_AGE_MS: number;