Skip to content

Commit

Permalink
chore: google analytics, tag manager setting (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
saseungmin authored Nov 26, 2023
1 parent 7d86697 commit 1c8c5f0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactNode } from 'react';

import localFont from 'next/font/local';
import Script from 'next/script';

import Layout from '@/components/common/Layout';
import Toast from '@/components/common/Toast';
Expand Down Expand Up @@ -58,6 +59,28 @@ function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="ko" className={pretendardFont.className}>
<head>
{process.env.NODE_ENV === 'production' && (
<>
<Script async src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID}`} />
<Script id="google-analytics">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID}');
`}
</Script>
<Script id="google-tag-manager">
{`
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID}');
`}
</Script>
</>
)}
<link
rel="apple-touch-icon"
href="/apple-touch-icon.png"
Expand Down

1 comment on commit 1c8c5f0

@vercel
Copy link

@vercel vercel bot commented on 1c8c5f0 Nov 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.