next ga
2.3.4
Next.js团队正在开发一个官方插件,而插件支持它仍然仅在金丝雀中,插件的工作方式比Next-GA更简单,我建议您在项目中进行检查并在项目中手动进行操作,直到其稳定为止。
插件链接:https://github.com/zeit/next.js/tree/canary/packages/next-plugin-google-analytics
Next.js高阶组件以在每个页面更改上集成Google Analytics(分析)。
安装它
yarn add next-ga将其导入您的pages/_app.js ;
import Router from "next/router" ;
import withGA from "next-ga" ;用它包装您的自定义应用程序容器
// pass your GA code as first argument
export default withGA ( "UA-xxxxxxxxx-1" , Router ) ( MyApp ) ;就是这样,现在当用户访问页面时,它将将页面浏览量记录到Google Analytics(分析)之后,此后每个页面都会触发有关Google Analytics(分析)的页面浏览量。
注意:该模块检测到它是否在Localhost中运行,并在此处无所事事以避免使用本地数据污染您的分析。