gtag.js和gtm

发布于 2025-02-07 08:49:21 字数 1166 浏览 1 评论 0原文

我与Google Tag Manager和gtag.js感到困惑。

我可以使用gtag.js跟踪GA并使用GTM跟踪GA4吗? 我尝试添加: `

<script async src="https://www.googletagmanager.com/gtag/js?id=Property ID GA"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
          gtag('config', 'Property ID GA');
    </script>
    <!-- Google Tag Manager -->
            <script>
                window.customDataLayer = window.customDataLayer || [];
            </script>
            <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
                        new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
                    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
                    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
                })(window,document,'script','customDataLayer','google tag manager');</script>
            <!-- End Google Tag Manager -->

`

GA4没有跟踪事件page_view。怎么了?

I´m confused with Google Tag Manager and gtag.js.

Can I use gtag.js tracking GA and use GTM tracking GA4?
I tried adding:
`

<script async src="https://www.googletagmanager.com/gtag/js?id=Property ID GA"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
          gtag('config', 'Property ID GA');
    </script>
    <!-- Google Tag Manager -->
            <script>
                window.customDataLayer = window.customDataLayer || [];
            </script>
            <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
                        new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
                    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
                    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
                })(window,document,'script','customDataLayer','google tag manager');</script>
            <!-- End Google Tag Manager -->

`

GA4 didn't track event page_view. What is wrong?

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

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

发布评论

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

评论(2

这个俗人 2025-02-14 08:49:21

如果您的网站已经具有GTM,则添加GA4的最佳方法可能只是创建GA4配置标签,从GA4属性的数据流的测量ID中更新测量ID,然后在发布GTM更改,一旦发布GTM,然后为所有页面创建一个触发器您的网站将开始跟踪GA4默认自动事件。

通过GTM创建GA4配置标签后,您的网站将包括GTM的GTAG.JS。

If your site already has GTM, the best way to add GA4 might be just create the GA4 Configuration Tag, update the measurement id from the GA4 property's data stream's measurement id, then create a trigger to all pages, once you publish your GTM changes, your site will start tracking GA4 default automatic events.

Once you create the GA4 Configuration Tag via GTM, your site will include gtag.js from GTM.

节枝 2025-02-14 08:49:21

您必须仔细阅读GA4安装说明:

看到这两个选项吗?您并不是要混合它们。如果您不想出于某种原因使用GTM,这是弗里斯特选项。或第二个选项。

删除与GTAG相关的代码。 GTM可以完成您需要的一切。只需在GTM中制作一个GA4标签,它将无缝加载所有依赖项。

如果您的GTM清理了代码,制作的标签,触发器并根据需要填写测量ID后,请进行单独的问题。

You have to read your ga4 installation instructions carefully:
enter image description here
See those two options? You're not meant to mix them. It's either the frist option if you don't want to use GTM for some reason. Or the second option.

Remove your gtag related code. GTM does everything you need as you go. Just make a GA4 tag in GTM and it will load all dependencies seamlessly.

Make a separate quesion if your GTM doesn't do what you expect after you've cleaned up code, made tags, triggers and filled the measurement ids as needed.

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