使用@next/third-parties/google
@next/third-parties
提供的GoogleAnalytics组件,完成Google Analytics4接入
开始
安装 @next/third-parties
依赖:
npm install @next/third-parties@latest
@next/third-parties
是一个Vercel官方开源的第三方程序集成库,可用于将第三方库加载到 Next.js 应用程序中,Google Analytics4就是其中之一。
除了谷歌分析之外还能接入Youtobe嵌入、谷歌地图等等
所有Google支持的第三方库都可以从@next/third-parties/ Google导入
如果你使用的是App路由
app/layout.tsx
import {
GoogleTagManager }