Skip to content

Commit f646b37

Browse files
committed
feat(frontend): add GTM for site data analysis
1 parent aabf5f0 commit f646b37

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

apps/frontend/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
NEXT_PUBLIC_API_URL=http://localhost:4000
2+
NEXT_PUBLIC_GTM_ID=GTM-XXXXXXX

apps/frontend/src/app/layout.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import './global.css';
22
import { Inter } from 'next/font/google';
3+
import Script from 'next/script';
34
import type { Metadata } from 'next';
45

6+
const GTM_ID = process.env.NEXT_PUBLIC_GTM_ID;
7+
58
const inter = Inter({
69
subsets: ['latin'],
710
variable: '--font-inter',
@@ -45,7 +48,26 @@ export default function RootLayout({
4548
}) {
4649
return (
4750
<html lang="ko" className={inter.variable}>
51+
{GTM_ID && (
52+
<Script id="gtm" strategy="afterInteractive">
53+
{`(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
54+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
55+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
56+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
57+
})(window,document,'script','dataLayer','${GTM_ID}');`}
58+
</Script>
59+
)}
4860
<body className="flex min-h-screen flex-col font-sans">
61+
{GTM_ID && (
62+
<noscript>
63+
<iframe
64+
src={`https://www.googletagmanager.com/ns.html?id=${GTM_ID}`}
65+
height="0"
66+
width="0"
67+
style={{ display: 'none', visibility: 'hidden' }}
68+
/>
69+
</noscript>
70+
)}
4971
<header className="border-b border-border">
5072
<div className="mx-auto flex max-w-3xl items-center gap-2.5 px-4 py-4">
5173
<svg

0 commit comments

Comments
 (0)