Skip to content

Commit

Permalink
FEAT: ✨ google analytics 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
bbung95 committed Sep 13, 2024
1 parent a8f1146 commit a52f99d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Feed from '@/components/Feed';
import Footer from '@/components/Footer';
import Sidebar from '@/components/Sidebar';
import ToastArea from '@/components/common/Toast/ToastArea';
import GoogleAnalytics from '@/lib/GoogleAnalytics';
import type { Metadata } from 'next';
import '../../styles/tailwind.css';
import Provider from './Provider';
Expand Down Expand Up @@ -32,6 +33,9 @@ export default function RootLayout({
<link rel='icon' href='/logo.svg' />
</head>
<body className='flex'>
{process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS && (
<GoogleAnalytics gaId={process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS} />
)}
<Provider>
<Sidebar />
<div className='min-h-dvh flex-1 flex flex-col overflow-y-scroll styled-scroll'>
Expand Down
27 changes: 27 additions & 0 deletions src/lib/GoogleAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Script from 'next/script';

const GoogleAnalytics = ({ gaId }: { gaId: string }) => {
return (
<>
<Script
async
src={`https://www.googletagmanager.com/gtag/js
?id=${gaId}`}
/>
<Script
id='google-analytics'
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gaId}');
`,
}}
/>
</>
);
};

export default GoogleAnalytics;

0 comments on commit a52f99d

Please sign in to comment.