4

I am using Angulartics for track some information to Google Analytics from AngularJS.

I need to set a Custom Dimension, I need to do something like this but using Angulartics third party.

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

In the documentation of Angulartics I just saw pageTrack() or eventTrack() methods. So I don't if it's possible?

4

2 回答 2

6

Angulartics 允许通过setUserProperties({'dimension' + index : 'dimension-value'}). 对于 Metrics,您传递一个带有类似数据的对象。重要的是使用前缀“维度”或“指标”与自定义维度/指标的索引连接。免费用户的指数为 [0,19],高级用户的指数为 [0,199]。

设置自定义维度/指标的有效示例包括:

$analytics.setUserProperties({'dimension1': 'dimension1-value'});

$analytics.setUserProperties({'dimension2': 'dimension2-value'});

$analytics.setUserProperties({'dimension3': 'dimension3-value'});...

$analytics.setUserProperties({'metric1': 'metric1-value'});

$analytics.setUserProperties({'metric2': 'metric2-value'});

$analytics.setUserProperties({'metric3': 'metric3-value'});...

查看 angulartics-google-analytics 的源代码显示:

$analyticsProvider.registerSetUserProperties(function (properties) {
  // add custom dimensions and metrics
  setDimensionsAndMetrics(properties);
});

function setDimensionsAndMetrics(properties) {
    if (window.ga) {
      // add custom dimensions and metrics
      for(var idx = 1; idx<=200;idx++) {
        if (properties['dimension' +idx.toString()]) {
          ga('set', 'dimension' +idx.toString(), properties['dimension' +idx.toString()]);
        }
        if (properties['metric' +idx.toString()]) {
          ga('set', 'metric' +idx.toString(), properties['metric' +idx.toString()]);
        }
      }
    }
  }

请参阅允许通过 setUserProperties() 设置维度/指标

于 2015-11-08T16:41:32.383 回答
1

截至版本0.1.2 angulartics.google.analytics支持为页面和事件跟踪设置自定义维度。

您可以像这样设置自定义尺寸

$analytics.setUserProperties({dimension1: 'myValue'});
于 2015-11-19T15:54:02.450 回答