Basic Google Analytics Filters for Every Site | LunaMetrics

Basic Google Analytics Filters for Every Site

/

blog-basic-ga-filters-tinypng
In Google Analytics, Filters are used by Views to segment the data into smaller groups. Filters can be used to include only specific subset of traffic, exclude unwanted data, or to search and replace certain pieces of information.

Creating New Filters

Filters can be created at either the Account or the View level. It is a best practice to create all the filters at the Account level, then assign them to different views. You can also create a filter at the View level, which would make that filter be applied to that particular view only; however, you should never need to do so unless if you have to create a filter based on Custom Dimensions or Metrics.

To manage or edit your filters, navigate to All Filters menu. Through the All Filters menu you can manage or edit all the filters in the account. You can refer to Google Analytics documentation to learn more about creating and managing filters at different levels.

Filters in Account and View

Couple of Notes

A couple of notes before jumping into the basic filters tutorial:

Recommended Views

Unfiltered View – Always have a view called “Unfiltered View – Do Not Delete” defined to keep your raw data intact. This view is there to make sure if anything unexpected happens to the data at least you have a backup saved somewhere. You should never add any filters to this view.

Main View – This view would be the one you use for reporting on a regular basis. Call it whatever you like, but make sure it’s communicated to your team which view should be used for reporting.

Test View – Apply your filters to this “Test View” first. Since the effects of applying a filter cannot be undone, it is recommended that you apply your new filters to a Test View first and let them run for a couple of days, to have enough time to verify the credibility of the results. If you have not already created and defined a “Test View”, it is a good time to create one now; your Test View should use the same exact settings as your “Main View” that you would normally use for your reporting purposes. If everything looks good after a few days, then apply to your Main View.

Filter Processing

Filters cannot be applied to your previous historical data; they can only be applied to your data moving forward. Filters are processed in order, so make sure you arrange the filters in the correct order.

Naming Conventions for Views

If you have multiple websites, clients, companies, etc. you should use a naming convention for your views to make sure you can identify each view at a glance. This becomes handy especially when you are going through configuring your accounts, trying to figure out which views to apply a filter to.

Example: For the website Example.com, use “Example.com – Main View”, “Example.com – Test View” and “Example.com – Unfiltered View – Do Not Delete”.

Basic Filters

In this blog, I am going to cover some of the basic (as opposed to more customized) filters everyone can use to segment their data. We use these filters to make sure our data is valid, to clean up the data, and to find out where the data is coming from.

Data Collection

Exclude Internal IP
Include Internal IP
Include Specific Hostname
Include Specific Subdomain
Exclude Dev Site Traffic

Data Consistency

Make your data more correct and more consistent. Use the following filters to make your data more consistent. Also, if you are suffering from having (other) in your reports, give these filters a try to consolidate more data.

Prepend Hostname to Request URI
Lowercase Hostname
Lowercase Request URI
Lowercase Search Term
Lowercase Campaign Dimensions
Remove Query String
Append Slash to Request URI
Search and Replace Filter

Data Sources

Segment your data for better analysis. The following filters would help you avoid Sampling. Since all the default reports are aggregated at the view level, it would be wise to define and use more views. If you find yourself often applying Advanced Segments, using a view/filter might be a better option for you.

Include a Traffic Medium
Include a Device Category
Include a Country

Filter Configurations

Exclude Internal IP

Use this filter to exclude yourself, i.e. your company’s internal visits, from the Main View. You may also exclude the traffic from all third party companies or agencies you work with. Multiple IP addresses can be excluded using this filter, so gather a list of all internal IPs and follow the steps below.

  • In Google Analytics interface, under Account, select All Filters.
  • Click on +ADD FILTER.
  • In the Filter Name field, enter “Exclude Internal IP”.
  • For the Filter Type, choose Custom.
  • In the Filter Field drop down menu, in the search box, type “ip”, then select IP Address.
  • IP Address Field

  • In the Filter Pattern field, use regular expression to enter all IP addresses you would like to exclude.
    • If you are excluding one or more distinct IP addresses, you should separate them by a pipe character, i.e. “|”. For example for the two addresses 192.168.1.1 and 255.255.255.1 you can enter 192\.168\.1\.1|255\.255\.255\.1
    • If you are excluding a range of IP addresses, use a regex pattern that covers the entire range in one statement.

regex IP

  • Select which Views you would like to apply this filter to, then add them to the Selected views list. Hold the Ctrl or Cmd button down to select multiple Views and add them all at once.
  • Click on Save to create the filter.
  • Select Views to Apply the Filter to

    Further Read: Take a look at Jon’s blog for more information on internal traffic.

    Include Internal IP

    It is a good practice to define a View to only include the internal traffic. This view can be used as a way to understand how the internal teams use the website. The specific filter you need to apply to this view is similar to the one above, but this time choose the Include option as the Filter Type. Remember that you should only use one include filter for a dimension.

    • Filter Name: Include Internal IP
    • Filter Type: Custom > Include
    • Filter Field: IP Address
    • Filter Pattern: Use a regex pattern to include all your internal IP addresses
    • Select the views to apply this filter to

    Include Specific Hostname

    This is one of the best filters you can make. Hostname is the domain of the page a visitor is on when they send a hit to GA. Obviously, you should only include traffic from people visiting your site. This is going to strip out a whole bunch of ghost referral spam, or traffic that never actually hits your website via the measurement protocol.

    This filter is also especially useful when implementing cross-domain tracking. It would filter out data based on the hostname of the hits and record the data in their corresponding views.
    Example: Assume you are tracking two domains www.exampleUSA.com and www.exampleGlobal.com. Assume you have defined separate views for each site called “exampleUSA Only” and “exampleGlobal Only” to segregate the hits. You would now need to create the following filters:

    • Filter Name: Include exampleUSA.com Only
    • Filter Type: Custom > Include
    • Filter Field: Hostname
    • Filter Pattern: ^(www\.)?exampleUSA\.com$
    • Apply the filter to exampleUSA Only View

    Also, create a similar filter for www.exampleGlobal.com.

    • Filter Name: Include exampleGlobal.com Only/li>
    • Filter Type: Custom > Include
    • Filter Field: Hostname
    • Filter Pattern: ^(www\.)?exampleGlobal\.com$
    • Apply the filter to exampleGlobal Only View

    Include Hostname Filter

    Include Specific Subdomain

    Same as the above filter, just change the filter pattern to match the subdomain.
    Example: Assume you would like to add a filter to the “Blogs Only” View, to only include the traffic from the blogs on exampleUSA.com.

    • Filter Name: Include blogs.exampleUSA.com Only/li>
    • Filter Type: Custom > Include
    • Filter Field: Hostname
    • Filter Pattern: ^blogs\.exampleUSA\.com$
    • Apply the filter to exampleGlobal Only View

    Exclude Dev Site Traffic

    To exclude development and staging traffic data from your production view, a.k.a. Main View, create the following filter:

    • Filter Name: Exclude Dev Site Traffic/li>
    • Filter Type: Custom > Exclude
    • Filter Field: Hostname
    • Filter Pattern: Enter a regex pattern of all development hostnames for your website. For example, if the development hostnames are dev.example.com, backend.example.com, and stage.example.com you would enter ^dev\.example\.com$|^backend\.example\.com$|^stage\.example\.com$ in this field (or some similar Regex).

    Exclude Dev Site Traffic

    Prepend Hostname to Request URI

    This filter is especially important if you are implementing a cross-domain tracking system. It would add the hostname to the beginning of the Request URI for every pageview hit, and then overwrite the Request URI with this new format. After applying this filter if you navigate to your Cross-Domain View, in All Pages report, you will have all pages with their corresponding hostnames.

    Example: Assume you are tracking two domains exampleUSA.com and exampleGlobal.com. Assume the Request URI to the homepages of both sites are index.html. After applying this filter, in your Cross-Domain View, in All Pages report you will see the following Pages:

    Hostname Homepage Address Resulting Page
    exampleUSA.com /index.html exampleUSA.com/index.html
    exampleGlobal.com /index.html exampleGlobal.com/index.html

    Create this filter as follows:

    • Filter Name: Prepend Hostname to Request URI
    • Filter Type: Custom > Advanced
    • Field A -> Extract A:
      • Select Hostname
      • Enter (.*)
    • Field B -> Extract B:
      • Select Request URI
      • Enter (.*)
    • Output To -> Constructor:
      • Select Request URI
      • Enter $A1$B1
    • Select Field A Required
    • Select Override Output Field
    • Apply this filter to the Cross-Domain View

    Add Hostname Filter

    Lowercase Hostname

    Your visitors might reach your website using different letter casings for the hostnames; e.g. Example.com and example.com. Create this filter to make the hostnames consistent.

    • Filter Name: Lowercase Hostname/li>
    • Filter Type: Custom > Lowercase
    • Filter Field: Hostname

    Lowercase Hostname Filter

    Lowercase Request URI

    This filter greatly consolidates the Pages by making all URIs to be lowercase.

    • Filter Name: Lowercase Request URI
    • Filter Type: Custom > Lowercase
    • Filter Field: Request URI

    The site visitors sometimes use different letter casings for their search terms. Create this filter to enforce all these terms be recorded as lowercase.

    • Filter Name: Lowercase Search Term
    • Filter Type: Custom > Lowercase
    • Filter Field: Search Term

    Lowercase Campaign Dimensions

    Generally in a business, there are going to be various marketing campaigns initiated by different departments across an organization. In most cases, marketing teams use tools such as URL builder to generate a campaign URL. However, two campaign names which were meant to be the same can be named with different letter casings and that would make Google Analytics record the data for each campaign separately. To make your campaign names consistent, create the following filter:

    • Filter Name: Lowercase Campaign Name/li>
    • Filter Type: Custom > Lowercase
    • Filter Field: Campaign Name

    Lowercase Campaign Name

    Just like lowercasing campaign names, it’s a good idea to make all campaign dimensions lowercase and consistent. Check with your marketing department before doing so! The following dimensions can be lowercase:

    • Campaign Source
    • Campaign Medium
    • Campaign Term
    • Campaign Content

    Remove Query String

    Sometimes, you may want a view that removes all query strings from your page URLs. You can accomplish this with an advanced filter.

    • Filter Name: Remove Query String
    • Filter Type: Custom > Advanced
    • Field A -> Extract A:
      • Select Request URI
      • Enter ^([^?]+)
    • Output To -> Constructor:
      • Select Request URI
      • Enter $A1
    • Select Field A Required
    • Select Override Output Field

    Remove Query String Filter

    Further Read: There are also other techniques for removing individual or all query strings from URLs. More detailed and advanced instruction can be found here.

    Append Slash to Request URI

    When visitors can access a page with or without using a trailing slash, Google Analytics would record a separate pageview for each case. If you see separate rows in your All Pages report for the same page paths with or without the trailing slash, you may want to create this filter.

    Note that this filter should be the last filter in the view as to not interfere with the other configurations.

    • Filter Name: Append Slash to Request URI
    • Filter Type: Custom > Advanced
    • Field A -> Extract A:
      • Select Request URI
      • Enter ^(/[a-zA-Z0-9/_\-]*[^/])$
    • Output To -> Constructor:
      • Select Request URI
      • Enter $A1/
    • Select Field A Required
    • Select Override Output Field

    Add Trailing Slash to URL

    Use this filter to look for information and modify it before it gets recorded in the aggregated tables.

    Example: Let’s consider if the site pages can be accessed with or without www. As a result, Google Analytics would create two rows to include both cases for each page. To avoid this, and to consolidate pageviews, create the following search and replace filter. This filter would look for “exampleUSA.com” as the hostname and replace that with “www.exampleUSA.com”.

    • Filter Name: Search and Replace www Filter
    • Filter Type: Custom > Search and Replace
    • Filter Field: Hostname
    • Search String: ^exampleUSA\.com$
    • Replace String: www.exampleUSA.com
    • Apply the filter to exampleUSA Only View

    Search and Replace Filter

    If you’re using the prepend hostname filter from above, make sure this filter comes first!

    Include a Traffic Medium

    Let’s start by Organic Traffic. To segregate organic traffic from the other means of reaching your website, define this filter and apply it to the Organic Only View.

    • Filter Name: Include Organic Only
    • Filter Type: Custom > Include
    • Filter Field: Campaign Medium
    • Filter Pattern: organic
    • Apply the filter to the Organic Only View

    You can define similar filters to only include the paid search traffic (filter pattern: cpc), email (filter pattern: email), etc.

    Include a Device Category

    First, create a filter for mobile devices. Add this following filter to the view that only contains traffic from mobile devices, i.e. Mobile Only View.

    • Filter Name: Include Mobile Only
    • Filter Type: Custom > Include
    • Filter Field: Device Category
    • Filter Pattern: Mobile
    • Apply the filter to the Mobile Only View

    You can create similar filters for Desktop Only and Tablet Only views.

    Include a Country

    To include traffic only from a particular country or region create a similar filter to this one.

    • Filter Name: Include US Traffic Only
    • Filter Type: Custom > Include
    • Filter Field: Country
    • Filter Pattern: United States
    • Apply the filter to the US Traffic Only View

    If there are multiple countries you are interested in including in a view, enter a pipe “|” separated list of them; e.g. United States|Canada|Mexico

    Filter by Country

    Summary

    Well, there you have it! A grand list of simple filters that can add tremendous value to your analytics account.

    Let me know what you think and if you would recommend any other filters to be included in this list.

    Enjoy!

    Zee is an Analytics Engineer with a passion for user experience design. He is an advocate of simplicity, and he appreciates data-driven designs. He received a degree in Electrical Engineering from Georgia Tech where he challenged himself to solve complex engineering problems and competed at numerous coding hackathons. Zee enjoys reading, learning new languages, and helping local tech startups.

    • John Peterson

      Thanks for covering all the filters in details I have been using the IP filters for so long where I tend to block mine and my clients IPs so that traffic is filtered out in GA I will be adding domain based filters now to crape out traffic from sister site for one of my client and double check them using gostats. Thanks again!

      • Zee Drakhshandeh

        No problem! I’m glad you found it helpful.

      • Zee D

        Glad you found it helpful!

    • http://www.aclaustin.com/ American Color Labs Austin

      hi Zee, thank you for this insightful article. Above you have mentioned in the “Include Specific Hostname” the filter pattern for http://www.example.com
      What about filter pattern for just example.com? Is that something GA going to contain automatically?
      Thanks for your time.

      • http://www.lunametrics.com/blog/author/zee/ Zee D

        Thanks for the question. The filter pattern ^(www.)?example.com$ would actually match both http://www.example.com and example.com. The question mark “?” would match zero or one of the previous expression, which is (www.) in this case.

    • Diana

      Very good article, Zee.

      Here is my questions to you:

      I have created a filter to display the full page path in my reports – Mainly to include the domain name (example.com). Now when creating a Goal funnel, do I need to include exmple.com/thank-you.html in the steps?

      Let me know what you think.

      Thanks

      Diana

      • http://www.lunametrics.com/blog/author/zee/ Zee D

        Hi Diana,

        In the Goal Funnel steps, you need to include /thank-you.

        Now normally, we think of a “thank-you” page as a Destination Goal. If this is the case, the goal should be set to “thank-you”, and you must have the page before thank-you as a step in your goal funnel.

        • Trevor Nicholls

          HI, when adding the prepend www. filter we see the desired effect in the behaviour>site content>all pages report, however, whilst the anchor text in the link appears correct, the actual url no longer works as it trys to send us to http://www.example.comwww.example.com

          • http://www.lunametrics.com/blog/author/zee/ Zee D

            That’s correct. Just copy paste the URL into a new tab – no way around that. The reason: The links used on those arrow buttons are set to href = “the hostname shown in the View Settings” + “whatever you see as the URL in that row”.
            So when you apply the filter to prepend the hostname to the request URIs, you are essentially updating the value of that row, but GA is not aware of it.

    • Murray Finlayson

      Awesome content, Zee. Thanks for providing so much useful information.
      Do you have any guidance on the ranking of the filters? For example, would you suggest putting the Spam Referrals filter #1?
      Regards,
      Murray

      • Murray Finlayson

        Sorry, I meant that the Include Valid Hostname filter should be first. Is this correct?

        • http://www.lunametrics.com/blog/author/zee/ Zee D

          Hi Murray,

          Thanks for the comment! And yes, I always keep my include/exclude filters on top of the list and the other filters on the bottom.

          • Murray Finlayson

            Thanks Zee, but does it matter the order of include/exclude filters?

            Specifically, I have:
            Include Valid Hostnames
            Exclude Spam Referrals
            Exclude Internal IP
            Exclude Dev/Staging

            Or does this not matter?

            Murray

            • http://www.lunametrics.com/blog/author/zee/ Zee D

              Your set up looks good.

              Filter ranking only matters when you are dealing with dependent filters, which happens when you are using the output of one filter as the input for another one. For example, you might have this filter set up:
              – Exclude Query Parameters
              – Append a Trailing Slash

              Here, it does matter when you are adding that slash (/) to the end of the Request URI; appending the trailing slash should come after you removed all the query parameters.

    • nagendra babu

      Hi its nice information, but i have a doubt ,we are adding so many filters ok .but i want to remove one filter how ?

      • http://www.lunametrics.com/blog/author/zee/ Zee D

        If you think you are adding so many filters, well don’t do it! And there are buttons to either Remove or Delete filters in the interface. Navigate to Account > All filters > Delete or you can go to View > Filters > Remove.

    • nagendra babu

      can u plz explain me.

    • Amir

      Hi Zee,
      Awesome post!
      w.r.t. the filter “Include Specific Hostname”, is there any benefit in doing it the way you described (i.e. Customer filter type and using RegEx), vs. doing it with the Predefined filter type and using “Include only” -> “traffic to the hostname” -> “that contain” -> Hostname = exampleUSA.com
      (see image).
      Thx.

      • http://www.lunametrics.com/blog/author/zee/ Zee D

        Hi,

        Using a Regex will give you more power in general. For example, what if you want to include traffic from two distinct domains, exampleUSA.com and exampleGlobal.com? I’d define a custom filter with Regex: example(USA|Global)?.com ,and this is not something you could do with a Predefined filter.

        I would always use the Custom filters.

        Thanks for asking!

        • Amir

          Got it about multiple domains, but if I have just one domain – is there anything wrong or not complete in using predefined?

          • http://www.lunametrics.com/blog/author/zee/ Zee D

            No, there is nothing wrong with using predefined filters.

    Contact Us.

    LunaMetrics

    24 S. 18th Street, Suite 100,
    Pittsburgh, PA 15203

    Follow Us

    1.877.220.LUNA

    1.412.381.5500

    getinfo@lunametrics.com

    Questions?
    We'll get back to you
    in ONE business day.