gtag 多个自定义维度 [英] gtag multiple custom dimensions
问题描述
我在网上搜索了将多个自定义维度发送到谷歌分析的解决方案.
I searched the web for the solution to send multiple custom dimensions to google analytics.
旧标签 ga 很容易配置,如下所示:
the old tag ga was easy to configure like so :
ga('create', 'UA-ID', 'auto');
ga('set', 'dimension1', value1);
ga('set', 'dimension2', value2);
ga('set', 'dimension3', value3);
ga('send', 'pageview');
这将发送所有 3 个自定义维度.
this would send all of the 3 custom dimensions.
问题出现在新的 gtag.js 我尝试了很多方法来配置多个自定义维度.该文档显示了如何配置 1 个自定义维度:
the problem occurs with the new gtag.js I tried lots of ways to configure multiple custom dimensions. the documentation shows how to configure 1 custom dimension as so :
gtag('config', 'UA-ID', {
'custom_map': {'dimension1': 'value'}
});
gtag('event','eventname', {'valuename':value});
这 [对于 1 个维度] 有效,但我不知道如何发送多个自定义维度.
This works [for 1 dimension] but I can't figure out how to send multiple custom dimensions.
[尝试发送具有 2 个维度字段的对象,尝试复制具有不同维度的配置自定义地图 - 没有奏效]
[tried sending the object with 2 fields of dimension , tried to duplicate the config custom map with different dimensions - it didn't work]
有什么想法吗?
推荐答案
您仍然可以使用旧版本的代码,但您必须将其发送到 JSON 中,例如
You can still use the Legacy version of the code but you have to send it inside a JSON instead, as the example
--Option I--
-- Set Option --
gtag( 'set' , {'dimension1' : "yxz"} ); // Set a Single Element
gtag( 'set' , {'dimension2' : "abc",'dimension3' : "123"} ); // Set multiple Elements
gtag('config', 'UA-1-1'); // Pageview with 3 cd
--Option II--
-- Map Function--
gtag('config', 'UA-ID', {
'custom_map': {'dimension1': 'value',
'dimension2': 'value2',
'dimension3': 'value3'}
});
gtag('event','eventname', {'value1':"1",'value2':"2",'value3':"3"});
这篇关于gtag 多个自定义维度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!