Search code examples
google-analyticsgoogle-analytics-filters

GA Search & Replace Filter


I wonder whether someone can help me please.

I have the following URI in GA: /invite/accept-invitation/accepted/B

Which I'd like to change to: /invite/accept-invitation/accepted

I've tried a 'Search and Replace filter as follows:

Search String - /invite/accept-invitation/accepted/*

Replace String - /invite/accept-invitation/accepted

But the result I get is:

/inviteaccept-invitation/accepted/B

Could someone tell me where I've gone wrong with this please?

Many thanks and kind regards

Chris


Solution

  • Google Analytics "Search and replace" filter uses regular expressions. More precisely:

    Replace string is either a regular string or it can refer to group patterns in the search expression using backslash-escaped single digits like (\0 to \9).

    More details are available on the filter settings UI, which also refers to this link.

    So in your case, the search string would be something like this.

     \/invite\/accept-invitation\/accepted\/\w+
    

    In this expression \ is escaped. Your last string part is captured with \w+, which matches any word character (equal to [a-zA-Z0-9_]), between one and unlimited times, as many times as possible.

    The Replace string doesn't have to be a regular expression. So in your case, your original version could be used:

    /invite/accept-invitation/accepted/
    

    Putting this together would result something like this, which gives the desired output in my test view:

    enter image description here