如何限制分析嵌入api以仅显示一个Google Analytics分析帐户

Rus*_*yev 6 google-analytics google-analytics-api

如何限制分析嵌入api以仅显示一个Google Analytics分析帐户.现在我有三个帐户显示在下拉列表中.

Pep*_*epe 13

正如Philip Walton所说,viewselector将始终显示所有帐户等.并且只有一个"视图",您将不需要选择器并将id添加到图表数据

例如,如果您使用https://developers.google.com/analytics/devguides/reporting/embed/v1/devguide演示作为起点.要让它只显示一个视图,请将步骤3到6替换为:

<script>
gapi.analytics.ready(function() {

  // Step 3: Authorize the user.

  var CLIENT_ID = 'insert client id here';

  gapi.analytics.auth.authorize({
    container: 'auth-button',
    clientid: CLIENT_ID,
  });



  // Step 4: Create the timeline chart.

  var timeline = new gapi.analytics.googleCharts.DataChart({
    reportType: 'ga',
    query: {
      'ids': 'ga:insert view id here',
      'dimensions': 'ga:date',
      'metrics': 'ga:sessions',
      'start-date': '30daysAgo',
      'end-date': 'yesterday',
    },
    chart: {
      type: 'LINE',
      container: 'timeline'
    }
  });

    timeline.execute();


});
</script>
Run Code Online (Sandbox Code Playgroud)

因此,您可以删除原始步骤的第4步和第6步,并通过添加ID来编辑步骤5:YOURVIEWID到var时间轴.然后添加timeline.execute()以呈现图表

可以使用https://ga-dev-tools.appspot.com/account-explorer/找到所需的ID,并在"查看"下的按钮上显示所需的ID