Skip to content

Commit 21507c0

Browse files
committed
fix: remove GTM consent overhead
1 parent 08ac8a8 commit 21507c0

File tree

2 files changed

+18
-203
lines changed

2 files changed

+18
-203
lines changed

src/components/CookieConsent.tsx

Lines changed: 0 additions & 187 deletions
This file was deleted.

src/routes/__root.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ import { Navbar } from '~/components/Navbar'
3131
import { THEME_COLORS } from '~/utils/utils'
3232
import { useHubSpotChat } from '~/hooks/useHubSpotChat'
3333

34+
declare global {
35+
interface Window {
36+
dataLayer: unknown[] | undefined
37+
gtag: ((...args: unknown[]) => void) | undefined
38+
}
39+
}
40+
3441
export const Route = createRootRouteWithContext<{
3542
queryClient: QueryClient
3643
}>()({
@@ -194,15 +201,6 @@ function ShellComponent({ children }: { children: React.ReactNode }) {
194201
<SearchHotkeyController />
195202
</ToastProvider>
196203
</LoginModalProvider>
197-
<noscript>
198-
<iframe
199-
src="https://www.googletagmanager.com/ns.html?id=GTM-5N57KQT4"
200-
height="0"
201-
width="0"
202-
style={{ display: 'none', visibility: 'hidden' }}
203-
title="gtm"
204-
></iframe>
205-
</noscript>
206204
<Scripts />
207205
</body>
208206
</html>
@@ -247,9 +245,9 @@ function SearchHotkeyController() {
247245

248246
function IdleGtmLoader() {
249247
React.useEffect(() => {
250-
const gtmId = 'GTM-5N57KQT4'
248+
const gaId = 'G-JMT1Z50SPS'
251249
const existingScript = document.querySelector<HTMLScriptElement>(
252-
`script[src*="googletagmanager.com/gtm.js?id=${gtmId}"]`,
250+
`script[src*="googletagmanager.com/gtag/js?id=${gaId}"]`,
253251
)
254252

255253
if (existingScript) return
@@ -259,14 +257,18 @@ function IdleGtmLoader() {
259257
window.dataLayer = []
260258
}
261259

262-
window.dataLayer.push({
263-
'gtm.start': Date.now(),
264-
event: 'gtm.js',
265-
})
260+
if (!window.gtag) {
261+
window.gtag = (...args: unknown[]) => {
262+
window.dataLayer?.push(args)
263+
}
264+
}
265+
266+
window.gtag('js', new Date())
267+
window.gtag('config', gaId)
266268

267269
const script = document.createElement('script')
268270
script.async = true
269-
script.src = `https://www.googletagmanager.com/gtm.js?id=${gtmId}`
271+
script.src = `https://www.googletagmanager.com/gtag/js?id=${gaId}`
270272
document.head.appendChild(script)
271273
}
272274

0 commit comments

Comments
 (0)