根据Google的documentation,在发送自定义维度或指标的数据时,我必须使用他们的索引来识别它们,如下所示:
ga('send', 'pageview', {
'dimension15': 'My Custom Dimension'
});
或
ga('set', 'dimension5', 'custom data');
我需要知道是否可以使用维度名称(即:" MyDimension")而不是索引来发送数据。我需要在多个客户使用的代码中执行此操作,而某些客户已经定义了其他自定义维度,而其他客户则不需要。如果我能够定位自定义维度名称,我就不必为每个客户使用不同的维度索引而使自己复杂化。
答案 0 :(得分:1)
Custom dimension和指标值会在收集时作为一对索引和值参数发送到Google Analytics。 index参数对应于Configuration阶段中定义的自定义维度或度量标准的索引。
// Set value for custom dimension at index 1.
ga('set', 'dimension1', 'Level 1');
这直接来自您需要使用索引号的文档。
从评论更新。您无法发送Json跟踪代码直接使用Measurement协议,测量协议要求您发送维度索引。你不能破解这个。 Measurement protocol documentation