如何使用 Google Analytics API 排除特定维度结果

How to exclude specific dimension result using Google Analytics API

如何从查询中过滤掉(未设置)使其不显示?

var mainChart2 = new gapi.analytics.googleCharts.DataChart({
          query: {
              'dimensions': 'ga:socialNetwork',
              'metrics': 'ga:pageviewsPerSession,ga:sessions,ga:newUsers',
              'max-results': '5',
              'start-date': '30daysAgo',
              'end-date': 'yesterday',
              sort: '-ga:sessions'
          },
          chart: {
              type: 'TABLE',
              container: 'main-chart-2-container',
              options: {
                  width: '100%'
              }
          }
      });

我目前得到的结果是:

Social Network        Pages / Sessions        Sessions        New Users
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
(not set)             #                       #               #
Facebook              #                       #               #
Twitter               #                       #               #

我想要的结果是:

Social Network        Pages / Sessions        Sessions        New Users
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Facebook              #                       #               #
Twitter               #                       #               #

您可以使用 API 的 filters 参数来排除使用 != 运算符的维度值。

因此您必须像这样向 query 对象添加一个键值。

filters: 'ga:socialNetwork!=(not set)'