[英]Add Google Analytics to Nextjs app with next-redux-wrapper
I have created a nextjs app with redux wrapper我用 redux 包装器创建了一个 nextjs 应用程序
class MyApp extends React.Component<AppProps> {
public static getInitialProps = wrapper.getInitialAppProps(store => async ({ Component, ctx }) => {
I am now trying integrate google analytics to the app ( G4 ).我现在正在尝试将谷歌分析集成到应用程序(G4)中。 Though many documentations explains how to add with useEffect, guides are little disconnected on how to use them while app extends component and not using hooks.尽管许多文档解释了如何使用 useEffect 添加,但指南在应用程序扩展组件而不使用钩子时如何使用它们几乎没有脱节。
Do i need to use componentMount methods or a better approach exists like upgrading this implementation to functional component?我需要使用 componentMount 方法还是存在更好的方法,例如将此实现升级为功能组件?
Converted the app as a functional component and used useEffect将应用程序转换为功能组件并使用 useEffect
const MyApp = (AppProps) => {
const router = useRouter();
useEffect(() => {
and then接着
MyApp.getInitialProps = wrapper.getInitialAppProps(store => async ({ Component, ctx }) => {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.