Filters are short statements that you can apply to a Google Analytics widget to refine the data that’s displayed and drill down to particular metric you're interested in.
Where available, filters can be applied from within your widget’s setup screen by adding a Custom filter statement to the Filter by field.
While our Google Analytics Number and Leaderboard widgets also offer pre-built filters, you may find this article useful for understanding filters in general and how to use them.
What is a filter statement?
A filter statement consists of several elements that tell the Google Analytics API exactly what data needs to be displayed:
- Dimensions and Metrics
- Strings and Values
Example of a Google Analytics filter
Let’s say you are interested in building a Number widget that displays the number of visitors this month to the contact page on your website. By default, the widget will pull through the total number of visitors across the whole of the website you’re tracking with Google Analytics. However, applying the filter
ga:pageTitle==Contact would allow you to refine this and display only the visitors to your page titled Contact.
Core Reporting filters vs Real-Time Reporting filters
Google Analytics offers two categories of data - Core Reporting metrics and Real-Time Reporting metrics. The filter statements you write will differ slightly depending on the widgets you use.
Core Reporting filter statements
Google Analytics' Core Reporting API lets you track longer-term data and trends (eg. data for time periods of Today, This Week, Past 28 days, Past 365 days, etc.)
Core Reporting filter statements always begin with
ga: and use the dimensions and metrics available through the Core Reporting API .
The following Geckoboard Google Analytics widgets request this data:
- Number widget
- Top Sources List
- Top Platform List
- Top Location List
- Top Pages List
- Top Products
- Product Sales Bar Chart
- Goals Line Chart
- Events Line Chart
- Visitors Line Chart
- Campaign Line Chart
- E-commerce Line Chart
Example of a filter statement for tracking Core Reporting data
ga:source is the dimension or metric you want to filter on, the operator is how you want the field to be compared (equals
==, not equals
=@, etc.), and
Real-time Reporting filter statements
Google Analytics' Real Time Reporting API lets you track data and events occurring currently on your website (e.g. number of visitors currently on your website, number of people currently performing a particular
Event Action on your pricing page, etc).
In Geckoboard, Google Analytics widgets and metrics with the words Current or real-time in their title or description use this API and let you track real-time data.
Widgets with the word Current in their title also refresh at a faster rate than others, as they serve only real-time metrics.
Real-Time Reporting filters always begin with
rt: and use the dimensions and metrics available through the Real-Time Reporting API .
The following Geckoboard Google Analytics widgets request real-time data:
- Current Sources List
- Current Platform List
- Current Location List
- Current Page List
- Current Visitor Gauge
- Current Visitor Map
Example of a filter statement for real-time data
rt:source is the dimension or metric you want to filter on, the operator is how you want the field to be compared (equals
==, not equals
=@, etc.), and
Dimensions & Metrics
The cornerstone of the filter statement are the dimension(s) or metric(s) that the widget is supposed to filter, such as the source of traffic or the URL of a specific page.
Almost the full range of dimensions and metrics can be added and even combined within a filter statement to create a very specific set of data within a widget.
Google Analytics doesn't allow for certain combinations of dimensions and metrics to be queried together.
For example, AdWords related metrics
Cost per Conversion,
Cost per Goal Conversion,
Cost per Transaction) and Event Tracking dimension-based filters (
Event Label) cannot be used together.
If you've used a forbidden combination, you may see this error message:
Examples of dimensions and metrics include:
Operators work with dimensions and metrics to allow you to specify how your data should be manipulated.
Let's say you’ve selected
city as the dimension you’re interested in: do you want to include only data from a specific city, exclude data from a specific city, include only data from a specific list of cities, or display data from cities that contain a specific word? Operators let you take the basic
city data and do much more with it than simply showing it.
Dimension filter operators
||Exact match||Aggregate metrics where the city is London.
||Does not match||Show visitor data for all sources apart from Geckoboard.
||Contains substring||Show data for any page whose URL contains the word ‘learn’.
||Does not contain substring||
||Contains a match for the regular expression||Show data for visitors from countries starting with ‘united’.
||Does not match regular expression||Exclude data for visitors from countries starting with ‘united’.
Metric filter operators
||Equals||Show data for visitors who have had exactly 8 sessions.
||Does not equal||Show data for non-first time sessions.
||Greater than||Show data for visitors who have over 9 sessions.
||Less than||Show data for visitors who have fewer than 3 sessions.
||Greater than or equal to||Show data for visitors who have 9 sessions or more.
||Less than or equal to||Return results where the time on the page is 10 seconds or less.
How to combine filters using AND and OR operators
Filters can also be combined using
AND as well as
OR logic to create a powerful tool for monitoring very specific elements of your website.
AND operator is defined using a semi-colon (;). It is preceded by the
OR operator and can be used to combine dimensions and metrics in the same expression.
Country is United Kingdom AND the source is Facebook AND sessions are greater than 5:
OR operator is defined using a comma (,). It takes precedence over the
AND operator, but cannot be used to combine dimensions and metrics in the same expression.
Visitors using either Windows OR Macintosh operating systems:
Strings & Values
The final part of a filter statement to be aware of is the string or value. Set at the end, the string or value should match those available for the dimension or metric you’ve defined in the first part of the statement, i.e if your dimension is
city you must choose the name of a city to filter or else you will trigger an error.
Here are some example Google Analytics filters to get you started:
||Traffic source is Twitter.|
||Referring keyword is ‘geckoboard’.|
||Title of page is ‘Contact’ (exact match).|
||URL of page contains ‘contact’ anywhere.|
||Visitor country is United Kingdom.|
||Country is United Kingdom and City is not London.|
||Show all events with the category Reports or Studies.|
||Show all events with the category Reports but exclude those with event label Share.|
||Firefox users on (Windows OR Macintosh) operating systems.|
||Operating system is (Windows OR Macintosh) AND browser is (Firefox OR Chrome).|
Tip for testing your Google Analytics filters
Google Analytics' Query Explorer is a useful tool that, amongst other things, lets you test filters.