Analytics
2.1K members online now
2.1K members online now
Ask questions about filter set-up and issues with using filters in Google Analytics reports
 
Guide Me
star_border
Reply

Why is Search and Replace not working?

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

For several weeks I have been trying to construct Search and Replace filters to consolidate URLs that have a lot of unneeded parameters. I have tested numerous different versions of the Regex, each time giving the new filter a couple of days to run, and nothing seems to work--GA still records Pageviews for the URL with parameters appended. I cannot figure out what the problem is. Here is what I have tried:

 

Search String:

/page\.aspx\?.*

^/page\.aspx\?.*

\/page\.aspx\?.*

^\/page\.aspx\?.*

/page\.aspx.*

\/page\.aspx.*

 

Replace String

/page\.aspx

 

And before anyone suggests it, sadly, Google Tag Manager is not an option. I have to use Filters.

 

So why do none of the Filters that I have tried work???

1 Expert replyverified_user

Re: Why is Search and Replace not working?

Rising Star
# 2
Rising Star
Do you want to exclude all parameters? If so, an Advanced filter is a better match.

Advanced
Field A -> Extract A
Request URI
^(.*)(\?.*)$

Output To -> Constructor
$A1

Tick the boxes for:
Field A Required
Override Output Field

Let me know if the above helps.

Re: Why is Search and Replace not working?

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Unfortunately, no, I can't replace all parameters, just the ones on certain URLs. And particular parameters are necessary on some pages, and not necessary on others. Yes, it's a mess.

Re: Why is Search and Replace not working?

Rising Star
# 4
Rising Star
Can you use the Exclude URL Query Parameters functionality in Admin > View Settings?

https://support.google.com/analytics/answer/1010249?hl=en

Re: Why is Search and Replace not working?

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
Not without losing those parameters for the pages that actually need them.

Re: Why is Search and Replace not working?

Rising Star
# 6
Rising Star
Okay, I hear you. Back to the Search and Replace approach. Have a look at the guide below. Have a go at it and let me know if it helps.

http://www.lunametrics.com/blog/2015/04/17/strip-query-parameters-google-analytics/

Re: Why is Search and Replace not working?

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭
Doesn't help, unfortunately. All of the strings I tested use acceptable regex, according to the GA documentation and according to various regex testers.

So it continues to be a mystery why, since I'm using acceptable regex, the filters don't work.

Re: Why is Search and Replace not working?

Rising Star
# 8
Rising Star
Let me try to understand what the problem is. You want to exclude some query parameters from page URLs. That is, some parameters, not all.

If this is the case, and referring to the guide I posted previously, what you need are these two search and replace filters:

Search for (parameterName=[^&]*&?)
Replace with

Search for ([?&]$)
Replace with

Note that replace with is empty.

Check out the above guide, namely Remove One URL Query with Filters.

Re: Why is Search and Replace not working?

[ Edited ]
Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭

Sorry, I wasn't clear. I am trying to strip ALL parameters from SOME URLs. I am trying to create Search and Replace filters for individual URLs that remove all parameters from those specific URLs.

I'm using a Search string to identify all instances of those URLs that have any parameters, and Replace them with a version of the URLs that have no parameters.

I was able to set up several different filters that work:

^/page\.aspx\?.*  Replace:  /page\.aspx
\/pg\/pg2\/pg3\.aspx\?.*   Replace:  /pg/pg2/pg3\.aspx
/page4\.aspx\?.*   Replace:  /page4\.aspx
/page5\.aspx\?.*   Replace:  /page5\.aspx

But when I reproduce these regex patterns for other URLs, it doesn't work. The other URLs are not filtered.