Skip to content

Commit

Permalink
Merge pull request #43 from DDD-Community/feature/42
Browse files Browse the repository at this point in the history
[FEATURE/42] Google Analytics
  • Loading branch information
hwanheejung authored Jul 25, 2024
2 parents b5fb0b4 + 9da9b80 commit e61792d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import GoogleAnalytics from '@/components/GoogleAnalytics'
import '@/styles/globals.css'
import type { Metadata } from 'next'
import localFont from 'next/font/local'
Expand Down Expand Up @@ -48,6 +49,7 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<GoogleAnalytics />
<head>
<link rel="icon" href="/images/favicon.ico" sizes="any" />
</head>
Expand Down
25 changes: 25 additions & 0 deletions src/components/GoogleAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Script from 'next/script'

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

<Script id="google-analytics" strategy="lazyOnload">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_GA_ID}', {
page_path: window.location.pathname,
});
`}
</Script>
</>
)
}

export default GoogleAnalytics

0 comments on commit e61792d

Please sign in to comment.