带有React的Google Analytics 4 [英] Google Analytics 4 with React
问题描述
我一直在尝试在我的应用中将react-ga包与Google Analytics(分析)4结合使用.度量ID不适用于该ID,并且我可以使用的Google Analytics(分析)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-XXXXXXXXXX
指的是新版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目前还没有完全成熟),请创建通用Analytics(分析)类型的属性,并将其ID(UA-XXXXX-X)与您指定的插件.您可以通过点击显示高级选项
(在创建新属性时)找到它:
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屋!