Skip to content

Commit db68947

Browse files
E2B-1546: add google tag manager capibilites for /docs (e2b-dev#576)
This PR adds necessary Google Tag Manager identification tags to our next.js app. Primary focus for the GTM here lies on `/dashboard `& `/docs`
2 parents 28fd11e + 637f680 commit db68947

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

apps/web/src/app/layout.tsx

+25-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Metadata } from 'next'
22
import { Analytics } from '@vercel/analytics/react'
3+
import Script from 'next/script'
34

45
import { Providers } from '@/app/providers'
56

@@ -28,35 +29,43 @@ export const metadata: Metadata = {
2829
},
2930
}
3031

31-
declare global {
32-
// eslint-disable-next-line @typescript-eslint/no-namespace
33-
namespace JSX {
34-
interface IntrinsicElements {
35-
'chatlio-widget': any;
36-
}
37-
}
38-
}
39-
4032
export default async function RootLayout({ children }) {
4133
const pages = await glob('**/*.mdx', { cwd: 'src/app/(docs)/docs' })
4234
const allSectionsEntries = (await Promise.all(
43-
pages.map(async filename => [
35+
pages.map(async (filename) => [
4436
'/docs/' + filename.replace(/\(docs\)\/?|(^|\/)page\.mdx$/, ''),
4537
(await import(`./(docs)/docs/${filename}`)).sections,
46-
]),
38+
])
4739
)) as Array<[string, Array<Section>]>
4840
const allSections = Object.fromEntries(allSectionsEntries)
4941

5042
return (
51-
<html
52-
lang="en"
53-
className="h-full"
54-
suppressHydrationWarning
55-
>
43+
<html lang="en" className="h-full" suppressHydrationWarning>
5644
<head>
45+
{process.env.NODE_ENV === 'production' && (
46+
<Script id="google-tag-manager" strategy="afterInteractive">
47+
{`
48+
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
49+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
50+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
51+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
52+
})(window,document,'script','dataLayer','GTM-K2W3LVD2');
53+
`}
54+
</Script>
55+
)}
5756
<Canonical />
5857
</head>
5958
<body className="flex min-h-full antialiased bg-zinc-900">
59+
{process.env.NODE_ENV === 'production' && (
60+
<noscript>
61+
<iframe
62+
src="https://www.googletagmanager.com/ns.html?id=GTM-K2W3LVD2"
63+
height="0"
64+
width="0"
65+
style={{ display: 'none', visibility: 'hidden' }}
66+
/>
67+
</noscript>
68+
)}
6069
<Providers>
6170
<Layout allSections={allSections}>
6271
<Header />

0 commit comments

Comments
 (0)