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中運行,並在此處無所事事以避免使用本地數據污染您的分析。