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

时间:2020-02-02 13:11:07

标签: google-analytics

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

Custom report screenshot

我用来将数据推送到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“ set”是作为虚拟综合浏览量发送的,其中,net gtag“ event”是事件而非虚拟综合浏览量。现在的问题是如何设置与我以前类似的自定义报告,或者如何更新代码段以获取与过去相似的结果?

更新

这是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>

2 个答案:

答案 0 :(得分:0)

根据您的analytics.js代码,set命令设置自定义维度及其给定值,以便它们持久存在并与页面中的所有/所有匹配一起发送。用于analytics.js的示例代码片段将发送CD和默认的综合浏览量。

尝试

<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('set', {'dimension1':  'Author Name', 'dimension4': 'Forum name'});
  gtag('config', 'UA-xxxxx',
        { 'anonymize_ip': true,
          'forceSSL': true
        });
</script> 

如果您在页面内发送了任何onclick或其他事件,或者在页面内发送了虚拟页面浏览量,它还将发送上述自定义尺寸及其设置值。

进行一些测试后,似乎没有必要使用custom_map(但是它可能会与新的app + web属性一起使用,并且可能在gtag.js代码段用于多个产品且需要映射自定义参数的地方)。 br /> 不确定,但是当我对它进行测试时,我发现custom_map的行为有些奇怪。

答案 1 :(得分:0)

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

<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>