11'use client' ;
22
3- import { ReactElement , useMemo } from 'react' ;
3+ import { ReactElement , Suspense , useMemo } from 'react' ;
44
55import { DotCMSAnalyticsConfig } from '../../dotAnalytics/shared/dot-content-analytics.model' ;
66import { useRouterTracker } from '../hook/useRouterTracker' ;
77import { initializeAnalytics } from '../internal/utils' ;
88
9+ /**
10+ * Internal component that uses Next.js hooks requiring Suspense boundary
11+ */
12+ function DotContentAnalyticsTracker ( {
13+ config
14+ } : {
15+ config : DotCMSAnalyticsConfig ;
16+ } ) : ReactElement | null {
17+ const analytics = useMemo ( ( ) => initializeAnalytics ( config ) , [ config ] ) ;
18+ const debug = Boolean ( config . debug ) ;
19+
20+ if ( analytics ) {
21+ useRouterTracker ( analytics , debug ) ;
22+ }
23+
24+ return null ;
25+ }
26+
927/**
1028 * Client bootstrapper for dotCMS Analytics in React/Next.
1129 * - No UI: initializes the analytics singleton from props or env config.
1230 * - If auto tracking is enabled, hooks into Next App Router to send page views.
31+ * - Automatically wraps in Suspense boundary for Next.js App Router compatibility.
1332 *
1433 * @param props.config - Optional analytics configuration. If provided, overrides env config.
1534 */
@@ -18,12 +37,9 @@ export interface DotContentAnalyticsProps {
1837}
1938
2039export function DotContentAnalytics ( { config } : DotContentAnalyticsProps ) : ReactElement | null {
21- const analytics = useMemo ( ( ) => initializeAnalytics ( config ) , [ config ] ) ;
22- const debug = Boolean ( config . debug ) ;
23-
24- if ( analytics ) {
25- useRouterTracker ( analytics , debug ) ;
26- }
27-
28- return null ;
40+ return (
41+ < Suspense fallback = { null } >
42+ < DotContentAnalyticsTracker config = { config } />
43+ </ Suspense >
44+ ) ;
2945}
0 commit comments