Excluding WordPress preview traffic in Google Analytics

A common issue with Google Analytics is internal traffic crowding your reports.

The standard way to exclude such traffic from your reporting is by creating a filter to exclude any traffic from known IPs (see here how). While this tactic is great, in times such as COVID-19, with many of the team working from home, managing the IP exclusions is difficult.

One quick way to solve this (to some extent) is by excluding known URLs from reporting to Google Analytics. If you’re using WordPress (like I am), you might want to exclude the Preview pages of your posts.

To achieve this we will need to create a simple ‘Custom Filter’.

  1. To create a filter, navigate to your account’s Admin page.
  2. Select the relevant Account, Property and View
  3. Under the View column, click on ‘Filters’
  4. Click ‘Add Filter’
  5. Give the filter a descriptive name, e.g. ‘Exclude Internal Traffic’
  6. Select the Filter Type ‘Custom’
  7. Set the type to ‘Exclude’
  8. Set the Filter Field to ‘Request URI’
  9. Paste in the value
    \?(p=.*|preview=true)
  10. Save the filter

If you’re using Elementor, you can also exclude it’s preview mode by using the value \?(p=.|elementor-preview=|.preview=true) in your exclusion rule.
(shoutout to Mark Alves for correcting a typo here)

You can also verify your filter before saving to examine how the filter would have impacted your past seven days data.

8 Responses

  1. To clarify, put in the entire \?(p=.|elementor-preview=|.preview=true to eliminate Elementor preview URLs from pageviews? And what if we want to exclude Elementor blocks from appearing that contain “&elementor-block=1” in it? What would that filter code be? Thanks!

    1. So yes.
      And any other parameter you’d want to exclude can be added w/o the & symbol, e.g. \?(p=.|.*elementor-preview=|.*preview=true|.*elementor-block=)

      1. So, yes, all I want is for ALL instances of the word “elementor” in URLs to not show up in my page views. I don’t care where within the URL the word “elementor” shows. If “elementor” shows, it’s in a preview setting and so should not count as a page view.

        That said, I have tried to put in your suggestion as a “custom” filter (filter field – “request URI”) exactly as follows and when I save, I get an error that the expression is invalid and it won’t let me save the filter:

        \?(p=.|elementor-preview=|.preview=true

        Can you please retype what the filter should be exactly? I’m not very tech savvy, so if you’re using any quotations or asterisks, please explain what those are used for and if I am to also insert those into the filter. Thank you.

        1. The filter is built with Regex, so the syntax is of course based on that.
          To filter in/out the phrase “elementor” you can simply add in “.*elementor.*”.
          The .* indicates this:
          . is any character (except new line)
          * is 0 or more of the preceding token

          so basically will capture any instance of this in the URI

          1. You can type in “elementor” without the .* it will work just the same (these additions are to make it fail safe).
            The custom filter type is by default set to regex, you can’t really control it (unlike the “simple” filters)

  2. This doesn’t seem to be working for me. I used the following Filter Pattern in the Request URI field: \?(p=.|.*elementor-preview=|.*preview=true|.*elementor_library=)

    When I clicked “Verify this filter” I saw the before filter and after filter seemed to have this URI pattern filtered out. However, when I go look at page traffic, I am still seeing “preview” and “elementor” in my Page URLs. Can you advise?

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts