Skip to content

Commit 06b486b

Browse files
committed
set timeout for loading gtm component
1 parent 1020d1c commit 06b486b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/features/common/components/shell/gtm/safe-gtm.component.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
import { GoogleTagManager } from "@next/third-parties/google"
44
import { useEffect, useState } from "react";
55

6-
const MAX_URL_LENGTH = 4000;
6+
const MAX_HASH_LENGTH = 4000;
77

88
export 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

0 commit comments

Comments
 (0)