结合通用分析和GA4的脚本? [英] Script to combine universal analytics and GA4?

查看:44
本文介绍了结合通用分析和GA4的脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在新网站上结合通用分析和GA4.

I would like to combine universal analytics and GA4 on my new website.

GA4的文档中提到了此跟踪代码:

The documentation for GA4 mentions this tracking code:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-123456"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'G-123456');
</script>

UA的文档中提到了此跟踪代码:

The documentation for UA mentions this tracking code:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-123456-4"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'UA-123456-4');
</script>  

对我来说,2个"config"调用看起来合乎逻辑,但是显然还需要使用"id"查询参数来请求脚本.如何正确组合UA和GA4?这就是我现在运行的方式:

The 2 'config' calls look logical to me, but apparently the script is also requested with an 'id' query parameter. How do i properly combine UA and GA4? This is how i have it running now:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-123456"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'G-123456');
    gtag('config', 'UA-123456-4');
</script>  

推荐答案

文档据说是通过这种方式将它们结合起来的(与查询字符串中的 UA-XXXXXX-13 不是 <代码> G-XXXXXXXXXX ):

Documentation said to combine these in this way (with UA-XXXXXX-13 in querystring not G-XXXXXXXXXX):

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXX-13"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-XXXXXX-13');
  gtag('config', 'G-XXXXXXXXXX');
</script>

https://developers.google.com/analytics/devguides/collection/ga4/basic-tag?technology = gtagjs

这篇关于结合通用分析和GA4的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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