File tree Expand file tree Collapse file tree
src/features/common/components/shell Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ import { GoogleTagManager } from "@next/third-parties/google"
4+ import { useEffect , useState } from "react" ;
5+
6+ const MAX_URL_LENGTH = 8000 ;
7+
8+ export function SafeGTM ( { gtmId} : { gtmId : string } ) {
9+ const [ canLoad , setCanLoad ] = useState ( false )
10+
11+ useEffect ( ( ) => {
12+ const urlLength = window . location . href . length
13+ const hasLargeToken = urlLength > MAX_URL_LENGTH
14+ if ( hasLargeToken ) {
15+ console . warn ( "GTM disabled: URL too long" , urlLength )
16+ }
17+ setCanLoad ( ! hasLargeToken )
18+ } , [ ] )
19+
20+ return canLoad ? < GoogleTagManager gtmId = { gtmId } /> : null
21+ }
Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ import { COOKIE_LEVELS } from "@/features/analytics/models/cookie-levels.constan
1212import { OnetrustScriptComponent } from "@/features/analytics/components/onetrust-script.component" ;
1313import { CLIENT_CONFIG } from "@/features/analytics/services/config" ;
1414import { COOKIE_CONSENT_STATUS } from "@/features/analytics/models/cookie-consent-status.constants" ;
15- import { GoogleTagManager } from "@next/third-parties/google" ;
1615import styles from "./shell.module.scss" ;
1716import { UiLocalizationService } from "@/features/localization/services/ui-localization.service" ;
1817import { clsx } from "clsx" ;
@@ -27,6 +26,7 @@ import { ThemeDetectorComponent } from "@/features/common/components/theme-detec
2726import { ThemeCookieValues } from "@/features/common/values/theme.values" ;
2827import { AbTestingScriptComponent } from "@/features/analytics/components/ab-testing-script/ab-testing-script.component" ;
2928import AdobeAnalyticsScript from "@/features/analytics/components/adobe-analytics-script.component" ;
29+ import { SafeGTM } from "./gtm/safe-gtm.component" ;
3030
3131const GTM_ID = process . env . NEXT_PUBLIC_GTM_ID ;
3232
@@ -113,7 +113,7 @@ export const ShellComponent: React.FC<ShellComponentProps> = ({
113113 process . env . NEXT_PUBLIC_IS_PROD &&
114114 GTM_ID && (
115115 < >
116- < GoogleTagManager gtmId = { GTM_ID } />
116+ < SafeGTM gtmId = { GTM_ID } />
117117 < AbTestingScriptComponent />
118118 </ >
119119 ) }
You can’t perform that action at this time.
0 commit comments