Filters

A filter string parameter is a chain of conditions applied to reduce/match query results.

{"filter":"[field_name] [comparison_sign] [value] [AND|OR] ..."}

Comparisons

SignDescription
==Equals
!=Does not equal
>Greater than
>=Greater than or equals to
<Less than
<=Less than or equals to
=@Contains. Case-insensitive. Applies only to dimensions.
!@Does not contain. Case-insensitive. Applies only to dimensions.
=~Matches regular expression. Applies only to dimensions.
!~Does not match regular expression. Applies only to dimensions.

Examples

Example 1

Get rows where field value for ctr is between desired range, and when campaign_name contains string "super campaign".

{"filter":"ctr >= 10 AND ctr <= 20 AND campaign_name =@ Super Campaign"}
Example 2

Field of campaign_name must contain string "super campaign" but excluding one specific case.

{"filter":"campaign_name =@ super campaign AND campaign_name != Super Campaign 1"}
Example 3

Apply regular expression condition for when the field value for campaign_name ends with string "paing", case-insensitive.

{"filter":"campaign_name =~ /paing$/i"}

Regular expressions

Supermetrics API uses Perl Compatible Regular Expressions (PCRE).

It is slightly different from POSIX Basic Regular Expression (BRE), and one notable difference is that the regular expresion must be enclosed by delimiters. We recommend using the common forward slash (/) for this purpose.

/^value[0-9]+$/

Please see the following additional resource links for information about regular expressions.

→ Perl Compatible Regular Expressions »
→ POSIX Basic Regular Expressions »
→ Online regular expression tester »

Limitations

  • Whenever possible, we relay any filter conditions to the data source API to reduce the amount rows we need to retrieve. When this is not an option, we increase the amount of rows we fetch to prepare for filtering. This can negatively affect your query performance.

Best practices

  • The simplest comparisons are usually the fastest, and most likely supported by the data source API directly. Please prefer equals or contains comparisons over matching with a regular expression for better performance.
Last updated 2021-10-20 UTC.