Skip to content

Commit

Permalink
fix: google tag manager setup (#3840)
Browse files Browse the repository at this point in the history
  • Loading branch information
enesozturk authored Feb 11, 2025
1 parent ff75922 commit 18d09b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/builder/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { GoogleTagManager } from '@next/third-parties/google'
import type { Metadata } from 'next'
import { ThemeProvider } from 'next-themes'
import { headers } from 'next/headers'
import Script from 'next/script'

import { khTeka } from '@/lib/fonts'
import { googleTagDataLayer, googleTagManagerSource } from '@/lib/gtag'
import { cn } from '@/lib/utils'
import { ContextProvider } from '@/providers/appkit-context-provider'
import { AppKitProvider } from '@/providers/appkit-provider'
Expand Down Expand Up @@ -77,6 +79,10 @@ export default async function RootLayout({ children }: Readonly<{ children: Reac
</AppKitProvider>
</ThemeProvider>
<GoogleTagManager gtmId="G-38H3M597C1" />
<Script src={googleTagManagerSource} strategy="afterInteractive" />
<Script id="google-tag-manager" strategy="afterInteractive">
{googleTagDataLayer()}
</Script>
</body>
</html>
)
Expand Down
10 changes: 10 additions & 0 deletions apps/builder/lib/gtag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const googleTagManagerSource = `https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID}`

export function googleTagDataLayer() {
return `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID}');
`
}

0 comments on commit 18d09b3

Please sign in to comment.