来自 Google Analytics 的自定义维度值

custom dimension value from Google Analytics

我正在研究 Google Anlytics Report,我想知道如何在 JavaScript, 喜欢浏览量?

相关代码:

var dataChart = new gapi.analytics.googleCharts.DataChart({
   query: { 
      dimension: 'ga:dimension1', 
      metrics: 'ga:pageview'
   },
   chart: {
      container: 'chart-container',
      type: 'Table',
      options: {
         width: '100%'
      }
   }
});

如果您只想从 Google Analytics 查询中获取数据,您应该使用 Data object (which just runs a query) instead of the DataChart 对象(它运行查询并将结果转储到 Google 图表中。

DataDataChart 对象在查询并成功返回时都会发出事件,因此您只需监听这些事件并记录结果。

这是一个例子:

// Creates a new report object.
var report = new gapi.analytics.report.Data({
  query: {
    'ids': 'ga:XXXXXX',
    'metrics': 'ga:pageviews',
    'dimensions': 'ga:dimension1',
    'start-date': '7daysAgo',
    'end-date': 'yesterday',
  }
});

// Runs the query.
report.execute();

// Specifies the callback function  to be run when the query succeeds.
report.on('success', function(response) {

  // Logs the entire response object.
  console.log(response);

  // Logs just the total pageviews.
  console.log(response.totalsForAllResults['ga:pageviews']);
});