Segmentation

Segmentation allows restricting data returned in the request response. Use the filters parameter to segment a request.

You can segment a request by dimensions and metrics. However, note the following:

  • Filtration by a dimension is performed before the dimension is applied. In this way, the resulting metric represents the total value only for data that meets the condition of the dimension.
  • Filtration by a metric is performed after the metric is applied.
  • You can filter using the dimensions and metrics that are not included in your request.
&filters=ga:<dimension or metric> <filtration operator for the specified metric> <filtration operator for attributes>

In addition, the following limits are imposed: a maximum of 10 unique dimensions and metrics, 20 separate filters, and 2000 characters in the filter string.

Filtration operators for metrics

Operator Description Encoded form Example
== Equal to %3D%3D The time spent on a page is equal to 10 seconds: filters=ga:timeOnPage%3D%3D10.
!= Not equal to !%3D The time spent on a page is not equal to 10 seconds: filters=ga:timeOnPage!%3D%3D10.
> Greater than %3E The time spent on a page is greater than 10 seconds: filters=ga:timeOnPage%3E10.
< Less than %3C The time spent on a page is less than 10 seconds: filters=ga:timeOnPage%3C10.
>= Greater than or equal to %3E%3D The time spent on a page is greater than or equal to 10 seconds: filters=ga:timeOnPage%3E%3D10.
<= Less than or equal to %3C%3D The time spent on a page is less than or equal to 10 seconds: filters=ga:timeOnPage%3C%3D10.

Filtration operators for attributes

Condition Description Encoded form Example
== Exact match %3D%3D Selects data used for calculating metrics for the city of Moscow: filters=ga:city%3D%3DMoscow.
!= Does not match !%3D Selects data used for calculating metrics for all cities other than Moscow: filters=ga:city!%3DMoscow.
=@ Contains substring %3D@ Selects data used for calculating metrics for a city. The name of the city matches the value “Moscow”: filters=ga:city%3D@Moscow.
!@ Does not contain substring !@ Selects data used for calculating metrics for a city. The name of the city does not match the value “Moscow”: filters= ga:city!@Moscow.
=~ Matches a regular expression %3D~ Selects data used for calculating metrics for a city. The name of the city starts with the value “Moscow”: filters=ga:city%3D~%5EMoscow.*
!~ Does not match a regular expression !~ Selects data used for calculating metrics for a city. The name of the city does not start with the value “Moscow”: filters=ga:city!~%5EMoscow.*

You can use multiple data filtration conditions in a request simultaneously.

When forming compound filters:

  • The following regular expression operators are allowed: =~ and !~.
  • Special symbols (such as &) must be escaped using the URL encoding format.

You can also use conditional operators: AND or OR.

Using the AND operator:

<!--Country of Russia, language other than Russian.-->

ga:country==Russia;ga:language!~^ru.*

Using the OR operator:

<!--Country of Russia or Ukraine.-->

ga:country==Russia,ga:country==Ukraine