Ora

How do I use filters in Google Analytics?

Published in Google Analytics Filters 6 mins read

Google Analytics filters are powerful tools that allow you to include, exclude, or modify the data collected in your reports, giving you a cleaner, more focused view of your website's performance. By applying filters, you can refine your data to remove irrelevant traffic, isolate specific segments, or ensure data consistency.

What Are Google Analytics Filters?

Filters in Google Analytics enable you to control which data appears in your reports. They work by processing raw data as it's collected, before it's stored in a reporting view. This means filters permanently alter the data in that view, so it's crucial to use them carefully. They help you focus on the most relevant data, making your analysis more accurate and actionable.

Why Use Filters?

  • Exclude Internal Traffic: Prevent your team's visits from skewing data.
  • Isolate Specific Segments: View data from a particular subdomain, directory, or region.
  • Consolidate Data: Merge variations of URLs or hostnames (e.g., example.com and www.example.com).
  • Clean Data: Remove spam or bot traffic that Google's default filtering might miss.
  • Format Data: Convert all URLs to lowercase for easier analysis.

Types of Google Analytics Filters

Google Analytics offers various filter types to cater to different data processing needs. These are broadly categorized into Predefined Filters and Custom Filters.

Predefined Filters

These are ready-to-use filters for common scenarios, requiring minimal setup.

  • Exclude/Include only traffic from the IP addresses: Filter out or include specific IP addresses or ranges.
  • Exclude/Include only traffic to the subdirectories: Focus on specific sections of your website (e.g., /blog/).
  • Exclude/Include only traffic to the hostnames: Analyze traffic for specific domains or subdomains.

Custom Filters

Custom filters offer more flexibility and precision, allowing you to define specific rules for data transformation.

  • Exclude/Include: Similar to predefined, but with custom fields and patterns.
  • Search and Replace: Find a specific string in a field and replace it with another. Useful for cleaning up URLs or campaign names.
  • Lowercase/Uppercase: Convert text in a specified field (e.g., Request URI, Campaign Source) to uniform casing.
  • Advanced: Combine fields or extract specific information using regular expressions. This is the most powerful filter type.

How to Add or Manage Filters in Google Analytics

Adding or managing filters is a straightforward process within the Google Analytics Admin section. Remember that filters are applied at the view level, so data in other views won't be affected unless you apply the same filters there.

Here's a step-by-step guide:

  1. Sign in to Google Analytics.
  2. Click Admin, located at the bottom left of the navigation panel.
  3. Navigate to the view (the third column) in which you want to add or remove filters. It's highly recommended to first apply filters to a test view before implementing them on your main reporting view.
  4. In the VIEW column, click Filters.
  5. To add a new filter, click + Add Filter.
    • Filter Name: Give your filter a descriptive name.
    • Filter Type:
      • To apply an existing filter, select Apply existing Filter and choose from the list of previously created filters.
      • To create a new filter, select Create new Filter and then choose either Predefined or Custom.
        • If "Predefined": Select a filter type (e.g., "Exclude only," "traffic from the IP addresses"), and specify the required parameters (e.g., IP address).
        • If "Custom": Choose a custom filter type (e.g., "Exclude," "Lowercase," "Search and Replace"), select the filter field (e.g., Request URI, Campaign Source), and provide the filter pattern or search string. For complex custom filters, you might use regular expressions to match patterns.
  6. Add or remove the filters as necessary, ensuring they are ordered correctly, as filters are processed sequentially.
  7. Click Save to apply your changes.

Practical Examples of Using Filters

To illustrate the utility of filters, consider these common scenarios:

1. Excluding Internal IP Addresses

This is essential for preventing your own team's website visits from skewing your traffic data.

  • Filter Type: Predefined
  • Select filter type: Exclude only
  • Select source or destination: traffic from the IP addresses
  • Select expression: that are equal to
  • IP address: [Your Static IP Address] (e.g., 192.168.1.1)
    • For multiple IPs or ranges, use regular expressions with a custom exclude filter.

2. Including Specific Subdomains

If you want a view to only show data for a particular subdomain (e.g., blog.yourwebsite.com).

  • Filter Type: Predefined
  • Select filter type: Include only
  • Select source or destination: traffic to the hostnames
  • Select expression: that contain
  • Hostname: blog.yourwebsite.com

3. Lowercasing URLs

This helps consolidate data for URLs that might be tracked with varying cases (e.g., /Page.html and /page.html treated as one).

  • Filter Type: Custom
  • Choose a filter type: Lowercase
  • Select Filter Field: Request URI

4. Search and Replace in Request URIs

To clean up URLs by removing query parameters that don't affect content, like session IDs.

  • Filter Type: Custom
  • Choose a filter type: Search and Replace
  • Filter Field: Request URI
  • Search String: \?sessionid=.* (using regex to match any sessionid parameter)
  • Replace String: `` (leave blank to remove)

Best Practices for Using Google Analytics Filters

Applying filters incorrectly can permanently alter or delete valuable data. Follow these best practices to ensure your data remains accurate:

  • Always Test Filters on a Test View First: Before applying any filter to your main reporting view, create a duplicate view and apply the filter there. Monitor this test view for a few days to ensure the filter works as expected without unintended consequences.
  • Understand Filter Order: Filters are applied in the order they appear in your view's filter list. The output of one filter becomes the input for the next. Incorrect order can lead to unexpected data.
  • Be Cautious with Exclude Filters: Exclude filters permanently remove data. Once excluded, that data cannot be recovered in that view.
  • Name Filters Clearly: Use descriptive names for your filters so you can easily understand their purpose later.
  • Keep a Raw Data View: Always maintain at least one Google Analytics view with no filters applied. This "raw data" view serves as a backup, ensuring you always have access to unprocessed information.
  • Document Your Filters: Keep an external record of all the filters you've applied, their purpose, and when they were implemented. This is invaluable for troubleshooting or when new team members join.

By carefully planning and implementing filters, you can significantly enhance the quality and usefulness of your Google Analytics data, leading to more insightful analysis and better decision-making.