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