简体   繁体   English

使用 next-redux-wrapper 将 Google Analytics 添加到 Nextjs 应用程序

[英]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.

相关问题 如何使用 next-redux-wrapper 在 nextjs 页面之间共享 state? - How to share state between nextjs pages with next-redux-wrapper? Redux 可以不在 nextjs 中使用 next-redux-wrapper 吗? NextJS 应用程序中的 state 经理是否足够使用 Context+useReducer? - Is it possible not to use next-redux-wrapper in nextjs for Redux? Is Context+useReducer will be enough for state manager in NextJS apps? 无法使用 next-redux-wrapper 使 Redux (Thunks) 与 NextJS 一起工作:未调用 getInitalProps - Can't get Redux (Thunks) to work with NextJS using next-redux-wrapper: getInitalProps not called next-redux-wrapper HYDRATE 被多次调用 - next-redux-wrapper HYDRATE getting called multiple times 为什么 next-redux-wrapper 在记录器中水合物两次? - Why next-redux-wrapper hydrate twice in logger? 我是否正确理解了 next-redux-wrapper 的行为? - Did I correctly understand the behaviour of next-redux-wrapper? 如何将 Next-Redux-Wrapper Store Provider 移动到布局组件? - How to Move Next-Redux-Wrapper Store Provider to Layout Component? redux-persist 不从 redux-toolkit 保存 state,使用 next-redux-wrapper - redux-persist does not save state from redux-toolkit, next-redux-wrapper is used Redux 工具包 typescript 类型问题与 next js 和 next-redux-wrapper - Redux toolkit typescript type issue with next js and next-redux-wrapper 使用 next-redux-wrapper 时访问 React 外部的 Redux 存储 - Access Redux store outside React when using next-redux-wrapper
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM