You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The @dotcms/analytics SDK currently requires explicit opt-in for automatic page view tracking, and the React SDK ignores the autoPageView flag entirely:
Mode
Current behavior
Desired behavior
IIFE (ca.min.js)
autoPageView defaults to false — requires data-analytics-auto-page-view="true"
On by default — only data-analytics-auto-page-view="false" disables it
Traditional (server-rendered, auto-injected)
If the autoPageView app secret is missing, the attribute renders as "" → SDK falls back to false → page views silently off, contradicting the app config contract ("defaults to true")
On by default — empty attribute resolves to enabled; only "false" (admin toggled it off) disables
React / Next.js (<DotContentAnalytics>)
Router tracker always fires page views, autoPageView config is ignored
On by default — respects autoPageView: false to disable
Core programmatic (initializeContentAnalytics)
Manual pageView() only
Unchanged (out of scope)
The goal is that analytics works out-of-the-box: a developer who installs the script or the React provider gets page view tracking without extra configuration, and can explicitly opt out with false.
Affected code
core-web/libs/sdk/analytics/src/lib/core/shared/utils/dot-analytics.utils.ts — getAnalyticsConfig() fallback defaults (autoPageView: false in both return paths) and attribute parsing (autoPageViewAttr === 'true')
core-web/libs/sdk/analytics/src/lib/react/components/DotContentAnalytics.tsx — useRouterTracker is called unconditionally (also currently inside an if, violating rules-of-hooks)
core-web/libs/sdk/analytics/src/lib/standalone.ts — auto pageview gate (logic stays, driven by new default)
core-web/libs/sdk/analytics/src/lib/core/shared/models/library.model.ts — autoPageView?: boolean JSDoc should document the new default
Traditional injection path (reference only — no Java changes expected, the SDK fix aligns it automatically):
dotCMS/src/main/java/com/dotcms/analytics/web/AnalyticsWebAPIImpl.java — getJSCode() replaces ${autoPageView} with the app secret, or blank when the secret is missing
dotCMS/src/main/resources/ca/html/analytics_head.html — injected script tag always renders data-analytics-auto-page-view="${autoPageView}" (so a missing secret produces an empty attribute, not an absent one)
dotCMS/src/main/resources/apps/dotContentAnalytics-config.yml — app param autoPageView declares value: true and documents "If not specified, it defaults to true"
Acceptance Criteria
IIFE (standalone script)
When data-analytics-auto-page-view is not present, auto page view is enabled and a pageview event fires on DOM ready
When data-analytics-auto-page-view="false", auto page view is disabled (existing "Auto page view is disabled" console warning still shown)
Any value other than the literal string "false" (e.g. "true", "no", "0", empty string) results in auto page view enabled (opt-out semantics: attr !== 'false')
autoPageView: false set via the data-analytics-config JSON attribute also disables auto page view; explicit attribute still takes precedence over JSON config
Both default-config return paths of getAnalyticsConfig() (script found / script not found) default autoPageView to true
Traditional (server-rendered pages, auto-injected script)
When the autoPageView app secret is missing (script tag rendered with data-analytics-auto-page-view=""), auto page view is enabled — matching the app config contract ("If not specified, it defaults to true")
When the admin sets Enable Auto Page Views = off in the Content Analytics app (attribute renders "false"), auto page view is disabled
When the secret is stored as true (default app value), auto page view is enabled (current behavior preserved)
Verified end-to-end against a dotCMS-rendered LIVE page with the auto-injected script from AnalyticsWebAPIImpl (manual or e2e check — no Java changes expected)
React / Next.js
When config.autoPageView is undefined or true, <DotContentAnalytics> tracks page views on App Router route changes (current behavior preserved)
When config.autoPageView is explicitly false, no automatic page views are sent; manual pageView() via useContentAnalytics still works
useRouterTracker is invoked unconditionally at the top level of the component (fix the conditional hook call); the enable/disable decision is passed as data, not by skipping the hook
Docs & types
JSDoc in getAnalyticsConfig() and library.model.ts updated — remove "autoPageView default to false" wording, document the opt-out default
Unit tests updated/added for: missing attribute, "false", invalid values, JSON config override (IIFE) and autoPageView: false (React tracker)
Additional Context
Intentional behavior change: existing IIFE installations without the attribute will start sending automatic pageviews after upgrading. This is the desired out-of-the-box behavior.
Traditional sites are the main production consumer of the IIFE: today a site whose Content Analytics app was saved before the autoPageView param existed (or with partial secrets) gets an empty attribute and silently loses page views. The opt-out semantics (attr !== 'false') fix this without touching the Java injection code.
Description
The
@dotcms/analyticsSDK currently requires explicit opt-in for automatic page view tracking, and the React SDK ignores theautoPageViewflag entirely:ca.min.js)autoPageViewdefaults tofalse— requiresdata-analytics-auto-page-view="true"data-analytics-auto-page-view="false"disables itautoPageViewapp secret is missing, the attribute renders as""→ SDK falls back tofalse→ page views silently off, contradicting the app config contract ("defaults to true")"false"(admin toggled it off) disables<DotContentAnalytics>)autoPageViewconfig is ignoredautoPageView: falseto disableinitializeContentAnalytics)pageView()onlyThe goal is that analytics works out-of-the-box: a developer who installs the script or the React provider gets page view tracking without extra configuration, and can explicitly opt out with
false.Affected code
core-web/libs/sdk/analytics/src/lib/core/shared/utils/dot-analytics.utils.ts—getAnalyticsConfig()fallback defaults (autoPageView: falsein both return paths) and attribute parsing (autoPageViewAttr === 'true')core-web/libs/sdk/analytics/src/lib/react/components/DotContentAnalytics.tsx—useRouterTrackeris called unconditionally (also currently inside anif, violating rules-of-hooks)core-web/libs/sdk/analytics/src/lib/standalone.ts— auto pageview gate (logic stays, driven by new default)core-web/libs/sdk/analytics/src/lib/core/shared/models/library.model.ts—autoPageView?: booleanJSDoc should document the new defaultTraditional injection path (reference only — no Java changes expected, the SDK fix aligns it automatically):
dotCMS/src/main/java/com/dotcms/analytics/web/AnalyticsWebAPIImpl.java—getJSCode()replaces${autoPageView}with the app secret, or blank when the secret is missingdotCMS/src/main/resources/ca/html/analytics_head.html— injected script tag always rendersdata-analytics-auto-page-view="${autoPageView}"(so a missing secret produces an empty attribute, not an absent one)dotCMS/src/main/resources/apps/dotContentAnalytics-config.yml— app paramautoPageViewdeclaresvalue: trueand documents "If not specified, it defaults to true"Acceptance Criteria
IIFE (standalone script)
data-analytics-auto-page-viewis not present, auto page view is enabled and apageviewevent fires on DOM readydata-analytics-auto-page-view="false", auto page view is disabled (existing "Auto page view is disabled" console warning still shown)"false"(e.g."true","no","0", empty string) results in auto page view enabled (opt-out semantics:attr !== 'false')autoPageView: falseset via thedata-analytics-configJSON attribute also disables auto page view; explicit attribute still takes precedence over JSON configgetAnalyticsConfig()(script found / script not found) defaultautoPageViewtotrueTraditional (server-rendered pages, auto-injected script)
autoPageViewapp secret is missing (script tag rendered withdata-analytics-auto-page-view=""), auto page view is enabled — matching the app config contract ("If not specified, it defaults to true")"false"), auto page view is disabledtrue(default app value), auto page view is enabled (current behavior preserved)AnalyticsWebAPIImpl(manual or e2e check — no Java changes expected)React / Next.js
config.autoPageViewis undefined ortrue,<DotContentAnalytics>tracks page views on App Router route changes (current behavior preserved)config.autoPageViewis explicitlyfalse, no automatic page views are sent; manualpageView()viauseContentAnalyticsstill worksuseRouterTrackeris invoked unconditionally at the top level of the component (fix the conditional hook call); the enable/disable decision is passed as data, not by skipping the hookDocs & types
getAnalyticsConfig()andlibrary.model.tsupdated — remove "autoPageView default to false" wording, document the opt-out default"false", invalid values, JSON config override (IIFE) andautoPageView: false(React tracker)Additional Context
autoPageViewparam existed (or with partial secrets) gets an empty attribute and silently loses page views. The opt-out semantics (attr !== 'false') fix this without touching the Java injection code.@dotcms/analyticsdefaults)