Skip to content

Commit

Permalink
feat: CustomGoogleAnalytics 컴포넌트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
hanyugeon committed Jun 27, 2024
1 parent e2798cf commit d63cf53
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Metadata } from 'next';

import { appleSplashScreens } from '@/constants/metadata';

import GoogleAnalytics from '@/components/common/GoogleAnalytics';
import ContextProvider from '@/components/common/ContextProvider';
import AuthFailedErrorBoundary from '@/components/common/AuthFailedErrorBoundary';
import Layout from '@/components/layout/Layout';
Expand Down Expand Up @@ -39,6 +40,7 @@ const RootLayout = ({ children }: { children: React.ReactNode }) => {
return (
<html lang="ko">
<body className={`${LineSeedKR.variable} app-layout font-lineseed`}>
<GoogleAnalytics />
<Layout>
<ContextProvider>
<AuthFailedErrorBoundary>{children}</AuthFailedErrorBoundary>
Expand Down
32 changes: 32 additions & 0 deletions src/components/common/GoogleAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use client';

import Script from 'next/script';

import * as gtag from '@/utils/gtag';

const GoogleAnalytics = () => {
return (
<>
<Script
strategy="afterInteractive"
src={`https://www.googletagmanager.com/gtag/js?id=${gtag.GA_TRACKING_ID}`}
/>
<Script
id="gtag-init"
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gtag.GA_TRACKING_ID}', {
page_path: window.location.pathname,
});
`,
}}
/>
</>
);
};

export default GoogleAnalytics;

0 comments on commit d63cf53

Please sign in to comment.