Skip to content

Commit

Permalink
feat: GoogleAnalystics 컴포넌트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ienrum committed Jul 6, 2024
1 parent 9ab2e7d commit e505340
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { Metadata, Viewport } from 'next';
import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

import GoogleAnalytics from '@/src/components/GoogleAnalystics';

import Introduction from '../components/Introduction';
import { MSWComponent } from '../mocks/MSWComponent';
import Providers from './Providers';
Expand Down Expand Up @@ -30,7 +32,10 @@ const RootLayout = ({
}>) => {
return (
<html lang='ko'>
<link rel='icon' href='/icon.ico' sizes='any' />
<head>
<link rel='icon' href='/icon.ico' sizes='any' />
<GoogleAnalytics gaId={process.env.NEXT_PUBLIC_MEASUREMENT_ID!} />
</head>
<body className='font-sans'>
<Providers>
<MSWComponent>
Expand Down
30 changes: 30 additions & 0 deletions src/components/GoogleAnalystics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';

import Script from 'next/script';

interface GoogleAnalytics {
gaId: string;
}

const GoogleAnalytics = ({ gaId }: GoogleAnalytics) => {
return (
<>
<Script
strategy='lazyOnload'
src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}
/>

<Script id='' strategy='lazyOnload'>
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gaId}');
`}
</Script>
</>
);
};

export default GoogleAnalytics;

0 comments on commit e505340

Please sign in to comment.