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

How can I restrict analytics embed api to display only one google analytics account

如何限制分析嵌入 api 只显示一个 google 分析帐户。现在我在下拉列表中显示了三个帐户。

嵌入 API 的 ViewSelector 组件总是会向您显示所有帐户、属性和视图的列表。

如果您确切地知道要为哪个视图显示数据,那么您根本不需要使用 ViewSelector 组件,您只需要传递视图 ID (ids ) 直接到 ReportDataChart 组件。

正如 Philip Walton 所说,viewselector 将始终显示所有帐户等。只有一个 'view' 您将不需要选择器并将 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>

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

需要的id可以通过https://ga-dev-tools.appspot.com/account-explorer/找到,需要的id显示在'view'

下的按钮处