프로그래밍 일기/Front-End
Nuxt3 구글 애널리틱스, 애드센스 등록 방법 Analytics, Adsense
MakeMe
2024. 7. 22. 16:41
반응형
npx nuxi@latest module add gtag
또는
npm install nuxt-gtag
# nuxt.config.ts
export default defineNuxtConfig({
modules: ['nuxt-gtag'],
gtag: {
id: process.env.GOOGLE_ANALYTICS_ID
},
app: {
head: {
script: [
{
hid: 'adsense',
async: true,
src: `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${process.env.GOOGLE_ADSENSE_ID}`,
crossorigin: 'anonymous'
}
]
}
}
})
# .env
GOOGLE_ANALYTICS_ID=G-12345678
GOOGLE_ADSENSE_ID=ca-pub-12345678
이와 같이 등록하면 정상적으로 작동 합니다.
반응형