File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
src/features/common/components/shell/gtm Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 33import { GoogleTagManager } from "@next/third-parties/google"
44import { useEffect , useState } from "react" ;
55
6- const MAX_URL_LENGTH = 4000 ;
6+ const MAX_HASH_LENGTH = 4000 ;
77
88export function SafeGTM ( { gtmId} : { gtmId : string } ) {
99 const [ canLoad , setCanLoad ] = useState ( false )
1010
1111 useEffect ( ( ) => {
12- const urlLength = window . location . href . length
13- const hasLargeToken = urlLength > MAX_URL_LENGTH
14- console . log ( "url length" , urlLength )
15- if ( hasLargeToken ) {
16- console . warn ( "GTM disabled: URL too long" , urlLength )
12+ const hash = window . location . hash
13+ const hasLargeHash = hash . length > MAX_HASH_LENGTH
14+ let originalHash = ""
15+ if ( hasLargeHash ) {
16+ originalHash = hash
17+ window . location . hash = ""
18+ setTimeout ( ( ) => {
19+ window . location . hash = originalHash
20+ } , 500 )
1721 }
18- setCanLoad ( ! hasLargeToken )
22+ setCanLoad ( true )
1923 } , [ ] )
2024
2125 return canLoad ? < GoogleTagManager gtmId = { gtmId } /> : null
You can’t perform that action at this time.
0 commit comments