嵌入API - >通过数据表的多维度

时间:2015-07-23 13:50:07

标签: javascript api google-analytics embed

有些人可以帮我调试我的代码吗?我希望Google图表中的多个维度包含来自Google Analytics的数据。我想要一个带x轴的折线图:日期和2个数据(唯一用户和应用版本)。我有这段代码:

gapi.analytics.ready(function() {

    /**
     * Authorize the user immediately if the user has already granted access.
     * If no access has been created, render an authorize button inside the
     * element with the ID "embed-api-auth-container".
     */
    gapi.analytics.auth.authorize({
      container: 'embed-api-auth-container',
      clientid: 'XXX'
    });


    /**
     * Create a new ViewSelector instance to be rendered inside of an
     * element with the id "view-selector-container".
     */
    var viewSelector = new gapi.analytics.ViewSelector({
      container: 'view-selector-container'
    });

    // Render the view selector to the page.
    viewSelector.execute();

    /**
     * Reports.
     */

    var report = new gapi.analytics.report.Data({
      query: {
          ids: 'ga:104696078',
          metrics: 'ga:users',
          dimensions: 'ga:date,ga:operatingSystem',
          'start-date': '30daysAgo',
          'end-date': 'yesterday'
      }
  });

  report.on('success', function handleCoreAPIResponse(resultsAsObject) {

      if (resultsAsObject.rows.length > 0) {

         var data = new google.visualization.DataTable();
          data.addColumn('string', 'date');
          data.addColumn('string', 'operatingSystem');
          data.addColumn('number', 'users'); 

          resultsAsObject.rows.forEach(function pushNumericColumn(row) {

              data.addRow([row[0], parseInt(row[1])]);

          }); 

          var options = {
              title: 'Custom Chart',
          };

          var chart = new    google.visualization.AreaChart(document.getElementById("chart_div"));
          chart.draw(data, options);
      }
  });
  });

0 个答案:

没有答案