feat(analytics): disable all tracking inside UVE editor#34633
Open
feat(analytics): disable all tracking inside UVE editor#34633
Conversation
5 tasks
014f27f to
4d2229b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
getUVEState()check ininitializeContentAnalytics()that returnsnullbefore any plugin is created (dot-analytics.content.ts:58-66)__dotAnalyticsActive__window flag tofalsewhen inside UVEImpression Tracker - Removed redundant check:
getUVEState()check and@dotcms/uveimport fromDotCMSImpressionTracker.initialize()(dot-analytics.impression-tracker.ts) — no longer needed since the entire system is disabled upstreamReact Hook (
useContentAnalytics) - Graceful degradation:throw new Error()with no-op analytics functions (NOOP_ANALYTICS) when instance isnull, preventing app crashes inside UVEuseMemoso it fires once (not on every re-render)isInUVEchecks fromtrack(),pageView(), andconversion()callbacksRouter Tracker (
useRouterTracker) - Cleanup:getUVEState()check and@dotcms/uveimport — theif (!analytics) returnguard already handles the null instance from UVETests
initializeContentAnalyticsreturnsnulland skips all plugins when inside UVE editoruseContentAnalyticsreturns no-op functions and warns when inside UVEuseContentAnalyticslogs error when initialization fails outside UVE (config error)DotCMSImpressionTrackerUVE editor mode check (moved upstream)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
useContentAnalyticsno 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 viaconsole.errorrather than thrown.Testing
Related Issues
Closes #34618