Google Analytics, filter ALL but a few URL parameters

by chriscross   Last Updated April 11, 2019 17:04 PM

My sites is being bombarded with new and old URL parameters. At first I tried to add those to the list of excluded URL parameters. With that list now exceeding 200, I wanted to try and use a GA advanced filtern.

However, the only filter I found would exclude ALL parameters:

Create an advanced filter
Filter name: remove all query parameters from URI Filter type: advanced Filter field A: Request URI Filter
Field A pattern: (.)\?(.)
Field B: leave it blank
Output field: Request URI
Output pattern: $A1
Override output: YES Case Sensitive: NO

Source

The only parameters I'd like to not be filteted are query and page.
Does anyone know how to alter the regex accordingly?



Answers 1


Ok, so I was able to to solve my problem.

First I setup a new advanced filter:

Filter name:      remove all query parameters from URI except query and page   
Filter type:      advanced   
Filter field A:   Request URI Filter    
Field A pattern:  (.*?)\?   
Filter field B:   Request URI Filter   
Field B:          [\?|&](page=\d+|query=[^&]*) 
Output field:     Request URI Output pattern: $A1?$B1 
Field A required: YES   
Field B required: NO  
Override output:  YES   
Case Sensitive:   NO

In addition I created a second advanced filter which filters unnecessary ? at the end of the URL, using the regex (.*)\?$

chriscross
chriscross
February 18, 2015 11:22 AM

Related Questions


Updated May 18, 2016 08:01 AM

Updated March 24, 2017 23:04 PM

Updated December 16, 2016 08:01 AM

Updated February 28, 2019 02:04 AM