Search code examples
javascriptgoogle-analyticsgoogle-visualizationgoogle-analytics-api

How to exclude specific dimension result using Google Analytics API


How do I filter out (not set) from the query so that it doesn't display?

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%'
              }
          }
      });

The current result I get is:

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

The result I want is:

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

Solution

  • You can use filters parameter of API to exclude dimension value using != operator.

    So you will have to add one key, value to the query object like this.

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