Skip to content

feat(analytics): disable all tracking inside UVE editor#34633

Open
oidacra wants to merge 2 commits intomainfrom
34618-disable-analytics-inside-uve
Open

feat(analytics): disable all tracking inside UVE editor#34633
oidacra wants to merge 2 commits intomainfrom
34618-disable-analytics-inside-uve

Conversation

@oidacra
Copy link
Member

@oidacra oidacra commented Feb 12, 2026

Summary

Disable all analytics initialization and tracking when running inside the DotCMS Universal Visual Editor (UVE) to eliminate unnecessary overhead (observers, listeners, DOM scanning, network requests) and prevent interference with the editor.

Changes Made

Frontend (SDK Analytics)

Core - Single entry point guard:

  • Added early getUVEState() check in initializeContentAnalytics() that returns null before any plugin is created (dot-analytics.content.ts:58-66)
  • This prevents initialization of all plugins (Identity, Click, Impression, Enricher, Main), event queues, observers, listeners, and network requests
  • Sets __dotAnalyticsActive__ window flag to false when inside UVE

Impression Tracker - Removed redundant check:

  • Removed getUVEState() check and @dotcms/uve import from DotCMSImpressionTracker.initialize() (dot-analytics.impression-tracker.ts) — no longer needed since the entire system is disabled upstream

React Hook (useContentAnalytics) - Graceful degradation:

  • Replaced throw new Error() with no-op analytics functions (NOOP_ANALYTICS) when instance is null, preventing app crashes inside UVE
  • Moved warning/error logging inside useMemo so it fires once (not on every re-render)
  • Distinguishes between UVE context (warns) and config errors (errors) in console messages
  • Removed redundant per-method isInUVE checks from track(), pageView(), and conversion() callbacks

Router Tracker (useRouterTracker) - Cleanup:

  • Removed redundant getUVEState() check and @dotcms/uve import — the if (!analytics) return guard already handles the null instance from UVE

Tests

  • Added test: initializeContentAnalytics returns null and skips all plugins when inside UVE editor
  • Added test: useContentAnalytics returns no-op functions and warns when inside UVE
  • Added test: useContentAnalytics logs error when initialization fails outside UVE (config error)
  • Removed test: DotCMSImpressionTracker UVE editor mode check (moved upstream)
  • Removed tests: per-method UVE skip checks in useContentAnalytics (no longer needed)

Technical Details

Previously, only the Impression Tracker checked for UVE state — all other plugins (Activity Tracker, Click Tracker, Identity, Queue, Enricher) still initialized fully inside the editor, attaching MutationObservers, IntersectionObservers, click listeners, DOM scanning, and session management. The fix centralizes the UVE check at the single entry point (initializeContentAnalytics), ensuring zero analytics code runs inside UVE regardless of mode (edit, preview, or live).

Breaking Changes

  • useContentAnalytics no longer throws when analytics fails to initialize — it returns no-op functions instead. This is intentionally less strict to support the UVE use case without crashing React apps. Config errors are now logged via console.error rather than thrown.

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • E2E tests added/updated (if applicable)

Related Issues

Closes #34618

@oidacra oidacra force-pushed the 34618-disable-analytics-inside-uve branch from 014f27f to 4d2229b Compare February 13, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[DEFECT] UVE detection mechanism fails causing incorrect analytics activation

1 participant