nextjs,tailwindcss,vercel

[๊ตฌ๊ธ€ ์• ๋„๋ฆฌํ‹ฑ์Šค] nextjs app router ์—์„œ google tag manager ์‰ฝ๊ฒŒ ์ ์šฉํ•˜๊ธฐ

์ฃผ์˜ ๐Ÿฑ 2024. 8. 2. 17:45
728x90
๋ฐ˜์‘ํ˜•

https://tagmanager.google.com/

๊ตฌ๊ธ€ ํƒœ๊ทธ๋งค๋‹ˆ์ €๋กœ ๊ตฌ๊ธ€ ์• ๋„๋ฆฌํ‹ฑ์Šค ์ ์šฉํ•˜๋ ค๋ฉด, ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผํ•˜๋Š”๋ฐ, ๊ณ ๋Œ€๋กœ ๋ณต๋ถ™ํ•˜๋ฉด ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค. 

๋‹ค์Œ์„ ์ฐธ๊ณ ํ•˜๋ฉด ๋œ๋‹ค. 

https://nextjs.org/docs/app/building-your-application/optimizing/third-party-libraries

 

Optimizing: Third Party Libraries | Next.js

Optimize the performance of third-party libraries in your application with the `@next/third-parties` package.

nextjs.org

 

์„ค์น˜

npm install @next/third-parties@latest next@latest

 

๋‹ค์Œ ์ฝ”๋“œ๋ฅผ layout.tsx์— ์ ์šฉ

 

import { GoogleTagManager } from '@next/third-parties/google'
 
export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <GoogleTagManager gtmId="GTM-XYZ" />
      <body>{children}</body>
    </html>
  )
}

 

 

๊ตฌ๊ธ€ ์• ๋„๋ฆฌํ‹ฑ์Šค๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ : 

import { GoogleAnalytics } from '@next/third-parties/google'
 
export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>{children}</body>
      <GoogleAnalytics gaId="G-XYZ" />
    </html>
  )
}

๋ฐ˜์‘ํ˜•