reactjs - React redux-beacon 跟踪链接点击分析

标签 reactjs google-analytics react-redux react-router redux-beacon

如果使用 Redux-Beacon,在 React/Redux 应用程序中跟踪内部链接点击分析的最佳方法是什么?

通常,内部链接单击会触发路由器位置更改(它不会触发任何其他 redux 操作)。但“LOCATION_CHANGE”实际上是一个pageView

可以在 history.push('...') 之前调度事件吗?喜欢:

dispatch({ type: VIEW_BLOG_POST, postId });
.....
history.push(`/${postId}`);
...

没有真正改变状态,只是为了用 redux-beacon 中间件捕获事件?

... 另外,外部链接点击量又如何呢?我需要管理这些不同的东西吗? (我想避免混合跟踪实现)

最佳答案

Is it ok, to dispatch an event before the history.push('...')?

是的,完全没问题。您所要做的就是将 VIEW_BLOG_POST 映射到新的事件定义。该操作不必以任何方式改变状态。它将通过 reducer ,所有 reducer 都会返回对先前状态的引用。如果您使用react-redux,这对性能的影响几乎为零。假设您将此作为 GA 中的一个事件进行跟踪,它将如下所示:

import { trackEvent } from '@redux-beacon/google-analytics';

const trackBlogPostClick = trackEvent((action, prevState, nextState) => {
  return {
    category: /* fill me in */,
    action: /* fill me in */,
    label: /* (optional) */,
    value: /* (optional) */,
  };
}, /* (optional) tracker names array or tracker name string */ );

// And wherever your events map is:

const eventsMap = {
  VIEW_BLOG_POST: trackBlogPostClick,
}

Without really changing the state, but just to catch the event with redux-beacon middleware?

👍

Also what about external link clicks? Do I need to manage these different? (I want to avoid mixed tracking implementations)

这很大程度上取决于您希望如何在 Google Analytics(分析)中跟踪这些信息。但从 redux-beacon 的角度来看,以同样的方式对待它们并没有什么错。

关于reactjs - React redux-beacon 跟踪链接点击分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54807396/

相关文章:

javascript - 解析电子商务数据以推送到 Google 标签管理器的数据层

reactjs - 使用 thunk 中间件从非 React 组件调度异步 redux 操作

javascript - 如何将键添加到作为无状态功能组件的数组元素

javascript - React-bootstrap-autosuggest 的问题

javascript - 将函数传递给reactjs中的子组件

reactjs - 如何通过 anchor 标记传递 Prop ?

python - 从 iPython 运行 ga.read_ga 的问题

google-analytics - Google Analytics(分析)可视计数器

javascript - 使用Reducer Redux中的新内容更新数组

javascript - 从 redux-store 加载数据的最佳位置在哪里?