React.js中的Google Analytics(Analyticsisks(Google Analyticsiss)对象和datalayer

发布于 2025-02-06 14:37:19 字数 1058 浏览 2 评论 0原文

我在.env fiel中有 react_app_measurement_id = g-xxxxxxxx

i使用react-gtm模块和Google Tag Manager 4(并且仍然是通用分析),并且我在我的app.js中初始化:

   useEffect(() => {
            TagManager.initialize({ gtmId: 'GTM-XXXXXX' });

        analytics.logEvent('screen_view', {
            firebase_screen: 'Home',
            firebase_screen_class: 'MainPage',
        })
    }, [analytics])

但是,分析对象来自firebase.analytics(app)我在firebase.js文件中初始初始化了。还是那是什么不同?

我就像DataLayer对象一样,在组件中使用该分析对象,并且它还为我提供了Google tagassistant中的同类OB DataLayer对象,例如:

  setGameFinished(gameFinished => (gameFinished = true))
            analytics.logEvent('game_finished', {
                score: `${correctAnswerCount} of ${quizData.length}`,
            })

给我datalayer.push({event:“ game_fined of gange_fined”,eventmodel:eventmodel:eventmodel:eventmodel: {分数:“ 2 of 4”,send_to:“”},gtm.uniqueeventid:23})在Google Analytics(分析)tagassistant(调试窗口)中。

但是一样吗?我想我可能把东西弄乱了;)。有人可以解释我的区别吗?

I have in my .env fiel the field
REACT_APP_MEASUREMENT_ID=G-XXXXXXXX

I am using react-gtm-module and Google Tag Manager 4 (and still also Universal analytics) and I initialize in my App.js:

   useEffect(() => {
            TagManager.initialize({ gtmId: 'GTM-XXXXXX' });

        analytics.logEvent('screen_view', {
            firebase_screen: 'Home',
            firebase_screen_class: 'MainPage',
        })
    }, [analytics])

However, the analytics object comes from firebase.analytics(app) that I initialized in the firebase.js file... has that analytics object from fire/analytics anything to do with the google tag manager or the datalayer object, or with google analytics at all or is that something different?

I am using that analytics object in my components just as the datalayer object, and it also gives me the same kind ob datalayer object in google tagassistant, e.g:

  setGameFinished(gameFinished => (gameFinished = true))
            analytics.logEvent('game_finished', {
                score: `${correctAnswerCount} of ${quizData.length}`,
            })

gives me dataLayer.push({event: "game_finished", eventModel: {score: "2 of 4", send_to: ""}, gtm.uniqueEventId: 23}) in google analytics tagassistant (debug window).

But is it the same? I think I might have messed something up there ;). Can someone explain me the difference?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两人的回忆 2025-02-13 14:37:19

firebase和GTM之间的区别?首先,Firebase是SDK。用于本机应用程序。 JS驱动的应用程序(我认为本机除外)应该使用gtag.js。 GTAG是一种直接跟踪数据到GA4的方式。对于通用分析,他们使用分析。

所以,再次:
Firebase SDK旨在跟踪应用程序,并且数据将用于Firebase服务。引入Firebase后不久,Google意识到这不是一件非常舒适的事情,因此他们以与Firebase数据模型非常相似的GA4推出了GA4,并且由于数据模型非常接近,因此它们使得易于与ga4实例同步firebase实例。另外,他们决定不为本地应用程序打扰新的SDK,而是使用firebase for Ga4。

Google Analytics(与Firebase略有不同)也有其不良体系结构的历史,但是现在我们有两个分析库,分析库,分析。尽管带来了所有的错误,但要替换它。 GA4使用gtag.js lib。但这仅适用于网络。这只能在允许外部脚本执行的应用程序中起作用,因此,浏览器。电子驱动的应用也是如此。

Firebase SDK允许您将事件直接发送到Firebase端点,这使数据可用于分析或进一步ETL。

现在,与其他LIB不同,GTM并不只是将有效载荷发送到端点。这是为了增加一个中间人。基本上,GTM部署了一个用户逻辑的集合,因此在GTM中,用户可以在DataLayer数组中抓住您推动的任何内容,对其进行重新排列,更改并将其发送到任何地方。并且可以是GA4,可以是GA UA,可以是Facebook或任何其他端点。 GTM,因为任何其他标签管理系统最终都会在加载的页面上执行自定义JavaScript。

本机应用程序还有GTM。那东西在很大程度上没有用。它实际上不能做任何事情,需要在每个构建中加载。它还失去了执行代码的能力,因此不可能进行热固定或独立跟踪实现。老实说,移动GTM与无脚本标签中加载的GTM一样有用。本机GTM没有提供足够的用途来证明业务逻辑和附加依赖性的传播是合理的。它只是为了使Google可以声称它是跨平台。关于无标记的同样:只是让公司声称它并不完全取决于JS。

很好,现在我们已经完成了正在发生的事情的上下文,如果您使用的是前端的React,那么除了GTM之外,您不需要任何东西。 GTM能够在不干预的情况下加载跟踪所需的所有库并根据需要发送事件,但是有人需要在GTM中构建逻辑,以将被推到DL的任何内容。您不需要Firebase,将GTM(Datalayer)作为分析和前端之间的唯一接触点是最佳实践。

如果您正在为本机应用程序做反应本机,那是相反的 - 您可能不需要GTM。但是,与您的实施专家或拥有GTM帐户的人同步。

Difference between Firebase and GTM? First of all, Firebase is an SDK. To be used in native apps. JS-driven apps (except react native, I believe) are supposed to use gtag.js. Gtag is a way to track data directly to GA4. And for Universal analytics, they use the analytics.js lib.

So, again:
Firebase SDK was meant to track apps and that data goes to the Firebase service. Soon after introducing firebase, Google realized it wasn't a very comfortable thing to use, so they rolled out GA4 with a very similar to Firebase data model, and since the data model is so close, they made it easy to sync Firebase instance with a GA4 instance. Also, they decided not to bother with a new SDK for the native apps and went with firebase for ga4.

Google Analytics (a slightly different thing from firebase) has had its history of bad architectures as well, but now we have two analytics libraries, analytics.js that is meant to be deprecated in a year or so with Universal Analytics and ga4 that is meant to replace it despite all the bugs it brings. Ga4 uses the gtag.js lib. But that's only for web. This will only work in apps that allow unsecure external scripts execution, so, like, browsers. Electron-driven apps, too.

Firebase SDK allows you to send events directly to your Firebase endpoint and that makes the data available for analysis or further ETL.

Now, GTM, unlike the other libs, is not meant to just send the payloads to the endpoint. It's meant to add a middle man. Basically, GTM deploys a collection of user logic, so in GTM users can grab whatever you're pushing in the dataLayer array, rearrange it, change it and send it to wherever. And wherever can be anything, it can be ga4, can be ga ua, can be facebook or any other endpoint. GTM, as any other tag management system ultimately executes custom javascript on pages where it's loaded.

There's also GTM for native apps. And that thing is largely useless. It can't really do anything and requires being loaded on every build. It also loses the ability to execute code, so no hotfixing or independent tracking implementation is not possible. Honestly, mobile GTM is about as helpful as the GTM loaded within the no script tag. Native GTM does not provide enough use to justify the spread of business logic and added dependency. It was made just so that Google could claim that it's cross-platform. Same about the no-script: just for the company to be able to claim that it doesn't depend on JS completely.

Good, now that we're done with the context of what's happening, if you're using react for front-end, then you don't need anything except GTM. GTM is able to load all the libraries it needs for tracking without your intervention and send events as needed, but someone needs to build logic in GTM for whatever is being pushed to the DL. You don't need firebase, having GTM (dataLayer) as the only touchpoint between analytics and front-end is the best practice.

If you're doing react native for a native app, then it's the opposite - you likely don't need GTM. But sync with your implementation specialists or whoever owns the GTM account in the company.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文