简体   繁体   English

如何将数组作为谷歌分析自定义维度发送?

[英]How to send an array as google analytics custom dimension?

Using Analytics.js 使用Analytics.js

I've got 3 articles with an arrays of tags, example: Rihanna, Beyonce and JayZ 我有3篇带有标签数组的文章,例如: Rihanna,Beyonce和JayZ

And I need to determine which one of them is more popular for users. 我需要确定哪一个更受用户欢迎。

In first article i've got only JayZ tag and send the demension as: 在第一篇文章中,我只获得了JayZ标签并发送了以下内容:

ga('set', { 'dimension1': 'JayZ', }); ga('set',{'dimension1':'JayZ',});

ga('send', 'pageview'); ga('发送','网页浏览');

But the second and the third has an arrays [Rihanna, Beyonce] and [Beyonce, JayZ] 但第二个和第三个有阵列[蕾哈娜,碧昂丝][碧昂丝,JayZ]

How to send this tags as separete parametres to one custom dimension? 如何将此标签作为separete参数发送到一个自定义维度?

This send just a simple string of all tags 这只发送一个简单的所有标签字符串

ga('set', { 'dimension1': array, }); ga('set',{'dimension1':array,});

This send only last parametr: 这只发送最后一个参数:

ga('send', 'pageview' {'dimension1': 'JayZ', 'dimension1': 'Beyonce'}); ga('send','pageview'{'dimension1':'JayZ','dimension1':'Beyonce'});

I can't use sepearate dimenssions for every tag, i've got 10 000 tags on my website =) 我不能为每个标签使用sepearate dimenssions,我的网站上有10 000个标签=)

You cannot. 你不能。 GA does not accept arrays, it only takes strings as custom dimensions. GA不接受数组,它只将字符串作为自定义维度。

Of course you could join your arrays into strings ( myarray.join(";") ) , but that still might not help you since a custom dimension can only have 150 bytes (and you could not sort/filter by individual tags). 当然你可以将你的数组加入到字符串中( myarray.join(";") ),但是这仍然可能对你没有帮助,因为自定义维度只能有150个字节(并且你不能按单个标记排序/过滤)。

As possible workaround you may use for cycle and send custom dimensions with events. 作为可能的解决方法,您可以使用循环并通过事件发送自定义维度。

var arrayga = ["first", "second", "third"];
var len = arrayga.length;

for (var i = 0; i < len; i++) {
   ga('send', 'event', 'Produkt', 'Sent', {
  'dimesion1': arrayga[i]
}

This will work only for hit type custom dimenssion. 这仅适用于热门类型自定义维度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM