Google Analytics:发送数据时可以使用自定义维度名称而不是索引吗?

Google Analytics: Can I use custom dimension name instead of index when sending data?

根据 Google 的 documentation,在发送自定义维度或指标的数据时,我必须使用它们的索引来识别它们,如下所示:

ga('send', 'pageview', {
  'dimension15':  'My Custom Dimension'
});

ga('set', 'dimension5', 'custom data');

我需要知道是否可以使用维度名称(即:"MyDimension")而不是索引来发送数据。我需要在多个客户使用的代码中执行此操作,有些客户已经定义了其他自定义维度,而其他客户则没有。如果我能够定位自定义维度名称,我就不必为每个客户使用不同的维度索引而使自己复杂化。

Custom dimension 和指标值在收集时作为一对索引和值参数发送到 Google Analytics。 index参数对应配置阶段定义的自定义维度或指标的索引。

// Set value for custom dimension at index 1.
ga('set', 'dimension1', 'Level 1');

这直接来自您需要使用索引号的文档。

根据评论更新。您不能只发送 Json 跟踪代码直接使用测量协议测量协议要求您发送维度索引。你不能破解这个。 Measurement protocol documentation