带有 React 的 Google Analytics 4 [英] Google Analytics 4 with React

查看:43
本文介绍了带有 React 的 Google Analytics 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在我的应用中使用 react-ga 包和 google analytics 4.测量 ID 无法使用它,而且我可以使用的 google 分析 4 中没有跟踪代码.拜托,我需要帮助!

I've been trying to use react-ga package with google analytics 4 in my app. The measurement id doesn't work with it and there is no tracking code in google analytics 4 I can use. Please, I need help!

import ReactGA from 'react-ga';
const trackingId = 'G-XXXXXXXXXX'; // UA-XXXXXXXXX-X isn't available in GA4
ReactGA.initialize(trackingId, options);
ReactGA.pageview(page);

推荐答案

您在示例中输入的代码 G-XXXXXXXXXXX ,指的是新的 Google Analytics 4,它与前一个并且不能与该插件一起使用.

The code you entered in the example, G-XXXXXXXXXX , refers to the new Google Analytics 4 which, being a different system from the previous one and does not work (yet) with that plugin.

因此您可以按照@Shyam 的回答中提到的说明进行操作,或者(我建议您,因为目前 GA4 还太不成熟)创建一个 Universal Analytics 类型的媒体资源并使用其 ID (UA-XXXXX-X) 和你指出的插件.您可以通过点击Show advanced options(当您创建新属性时)找到它:

So you can follow the instructions mentioned in the answer of @Shyam or (and I suggest you because GA4 is too unripe at the moment) create a Universal Analytics type Property and use its ID (UA-XXXXX-X) with the plugin you indicated. You can find it by clicking on Show advanced options (when you create a new property):

这篇关于带有 React 的 Google Analytics 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆