How to create filters for Google Analytics?

Google Analytics provides a lot of data. While having an overall portrait is necessary, sometimes, you might want to look at more specific pieces of information. This is when filters come in handy.

 

Filters allow you to refine the data shown in your widgets according to your needs. For example, you can filter your page impressions according to the country in which they occurred or device on which they occurred. You can use filters on both metrics and dimensions.

 

 

 

 

1 – Syntax

 

First, you need to know how to write a filter. Filters in Google Analytics require a specific syntax, which looks likes this:

 

ga:country==Canada

 

If we replace each of the variables with their official terms, it looks like this:

 

ga:nameoperatorexpression

 

Name: This is the name of the dimension or metric you want to apply a filter to. For example, ga:pageviews will apply to the metric called “pageviews”. To know the exact name you need to write, please refer to the Google Analytics documentation. Filters are case-sensitive, so be sure that your capital letters are in the right place!

 

Operator: This is the formula that will be applied, such as equal to, greater than, less than, etc.

 

Expression: This is the value to which the operator applies in order to either include or exclude data.

 

In our previous example ga:country==Canada

  • “country” is the name
  • “==” is the operator
  • “Canada” is the expression.

 

 

 

2 – Filters for dimensions

 

There are six operators you can use in order to filter dimensions.

 

 

Operators Descriptions Examples
== Exact match Includes only data that exactly matches the expression. All other dimensions will be excluded.Ex: The filter ga:deviceCategory==mobile will only display data related to mobile and ga:source==facebook will only display data coming from Facebook.
!= Does not match Excludes all data that doesn’t exactly match the expression.Ex: The filter ga:campaign!=CampaignName will discard all data related to the campaign called CampaignName.
=@ Contains substring Includes all data that contains the expression.Ex: The filter ga:country=@land will display all data for countries containing “land” in their name, such as England, Ireland, Scotland, etc.
!@ Does not contain substring Excludes all data that doesn’t contain the expression.Ex: The filter ga:campaign!@Spring will exclude all campaigns containing “Spring” in their name.
=~ Contains a match for the regular expression Includes all data that starts with the expression.Ex: The filter ga:campaign=~(s|S)pring will include all campaigns containing “spring” or “Spring” in their name.
!~ Does not match regular expression Excludes all data that doesn’t contain the expression.Ex: The filter ga:campaign!~(s|S)pring will exclude all campaigns containing “spring” or “Spring” in their name.

 

 

2.1 – Substring and regular expression

 

Substring? Regular expression? If you’re not familiar with coding and computer science, these terms might not mean much to you.

 

A substring is a sequence of characters contained in a longer sequence of characters; “Dash” is a substring of “DashThis” for example.

 

A regular expression (called RegEx) is a formula that defines a pattern. It’s more flexible and can offer many possibilities.

 

Regular expressions have multiple functions and can easily become complex. In the context of writing a Google Analytics filter, you probably won’t need to dive too deeply into formulas and endless options.

However, if you want to learn more on regular expressions and unleash their power, we suggest you explore the guide to regular expressions in Google Analytics. You will find an overview of the different symbols you can use and their functions, as well as other tips and tricks.

 

 

 

3 – Filters for metrics

 

There are six operators you can use in order to filter metrics.

 

Operators Descriptions Examples
== Equal to Returns data that is equal to the expression.

Ex: ga:uniquePageviews==5 will only show results where the number of pages viewed is equal to 5.

!= Does not equal Returns data that is different from the expression.

Ex: ga:pageviewsPerSession!=1 will only show results where the number of pageviews per session is not equal to 1.

> Greater than Returns data that is greater than the expression.

Ex: ga:timeOnPage>60 will only show results where the user spent more than 60 seconds on a page.

< Less than Returns data that is less than the expression.

Ex: ga:sessionDuration<30 will only show results where the sessions lasted less than 30 seconds.

>= Greater than or equal to Returns data that is greater than or equal to the expression.

Ex: ga:impressions>=100 will only show results where the impressions are greater than or equal to 100.

<= Less than or equal to Returns data that is less than or equal to the expression.

Ex:ga:pageviews<=100 will only show results where the pageviews are less than or equal to 100.

 

 

4 – Combination

 

It’s possible to combine filters to personalize the query even more. You can combine them either with an AND or an OR.

 

The OR operator is the comma ( , ) : ga:country==canada,ga:country==australia means the query will return results that are either Canada OR Australia.

 

The AND operator is the semicolon ( ; ) : ga:country==canada;ga:deviceCategory==Mobile means the query will return results that are related to Canada AND mobile devices.

 

 

5 – Multi-channel funnels

 

If you want to apply a filter on multi-channel funnel metrics, the filter syntax is going to change a little bit. Instead of beginning with ga, the filter has to start with mcf. The result would look like this: mcf:source==facebook. Please refer to Google Analytics documentation on multi-channel funnels to know how to write the name in your filter.

 

How do you know if the metric you want to choose is a multi-channel funnel metric? Easy!

 

When you create a widget in your dashboard, choose the option Custom widgets, located on the top-left side of the screen. Choose the type of widget you want and Google Analytics as your data source. A drop-down menu called Metric is there, at the very top of the panel. The metrics are categorized under different sections, and one of them is called Multi-channel funnels. They’re all there!

 

 

6 – In DashThis

 

You’re now mastering the art of Google Analytics filters. Congratulations!

 

It’s time to apply them to your DashThis widgets and get the information that specifically matters to you.

 

6.1 – New widgets

 

In the Editor mode, click on the Custom widgets option. Choose the type of widget you want to create as well as the metric and the dimension, if applicable. There is a field called Filter, which is where you’ll write your filter!

 

Filter_create

 

 

 

 

6.2 – Existing widgets

 

You can also apply filters to already existing widgets.

Hover over the widget, and click on Edit widget, located on the right side of the widget. The panel Edit widget appears. Under the section Basics, there is a field called Filter. Make the magic happen, and then click Save.

 

Filter_Existing

 

You now have the info you need in your widget!