温馨提示:本文翻译自stackoverflow.com,查看原文请点击:google analytics - ga to gtag in custom dimension in combination with custom reports and virtual pageviews
google-analytics

google analytics - 从ga到gtag以自定义维度结合自定义报告和虚拟综合浏览量

发布于 2020-04-12 10:43:07

过去,我使用Google Analytics(分析)自定义报告来跟踪每个作者的综合浏览量和每个论坛主题类别的综合浏览量,这些都是我在Google Analytics(分析)(analytics.js)中进行的设置:

自定义报告屏幕截图

我用来将这些数据推送到Google Analytics(分析)的代码很简单 ga('set', 'dimension1', 'Name of Author');

我已经将Google Analytics(分析)javascript代码段更新为gtag,但似乎无法以相同的方式推送数据。

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxx"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'UA-xxxxx',
            { 'anonymize_ip': true,
              'forceSSL': true,
              'custom_map': {'dimension1': 'author', 'dimension4': 'forum_name'}
            });
        gtag('event', 'author', {'event_category': 'Writers', 'event_label': 'Author Name'});
        gtag('event', 'forum_name', {'event_category': 'Forum category', 'event_label': 'Forum Category name'});
    </script>

目前,我正在Google Analytics(分析)中将数据作为事件来获取。但是现在代码的工作方式使分析数据变得更加困难。过去,我可以单击作者姓名,查看哪些页面的浏览量最高,对于论坛类别,它是相同的。我可以进行挖掘,并按类别查看吸引最多访问者的网址。

我认为这两个代码段之间的区别是ga“设置”是作为虚拟综合浏览量发送的,而网络gtag“事件”是一个事件而不是虚拟综合浏览量。现在的问题是如何设置与我以前类似的自定义报告,或者如何更新代码段以获取与过去相似的结果?

更新资料

这是Google Analytics(分析)的旧版本,也是我一直在使用的代码:

<script>
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
        ga('create', 'UA-XXXXX', 'auto');
        ga('set', 'dimension1', 'Author Name');
        ga('set', 'dimension4', 'Forum name');
        ga('require', 'ec');
        ga('set', 'anonymizeIp', true);
        ga('set', 'forceSSL', true);
        ga('send', 'pageview');
</script>

查看更多

提问者
user1923728
被浏览
134
user1923728 2020-03-05 21:45

经过大量测试,我终于找到了自己问题的答案。技巧似乎是在配置中添加尺寸,以便将它们作为综合浏览量发送。

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxx"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-xxxxx',
    { 'anonymize_ip': true,
      'forceSSL': true,
      'dimension1': 'Author Name', 'dimension4': 'Forum category'
  });
</script>