2

I want to create a Regex query to filter only the homepage with some subcategories. I have multi-language home pages with the this structure:

  • mail.example.com/en/
  • example.com/
  • example.com/de/categoy/bla-bla-bla/
  • example.com/fr/categoy/bla-bla-bla/
  • example.com/en/category/category/bla-bla-bla/
  • example.com/fr/
  • subdomain.example.com/
  • subdomain.example.com/bla-bla-bla/
  • example.ua/en/news/video/bla-bla-bla/

So, I'm trying to include only all home pages with different languages and using RegEx for it as ^example\.com\/((fr|en|de)\/)?$

The regex101.com showed that my expressions working well, but in Google Analytics I have some data from content pages as example.ua/en/news/video/bla-bla-bla/ and cant exclude it.

enter image description here

1

Your regular expression is fine, but it won't match the field that you are filtering against. You are filtering against Hostname which is always going to be either example.com or example.ua. It will never have URL path after it. Your rule is always going to match.

Instead you should be filtering against the Request URI. From the documentation:

Request URI -- Includes the relative URL, or piece of the URL after the hostname. For example: for http://www.google-analytics.com/requestURL/index.html?sample=text the Request URI is /requestURL/index.html?sample=text

Then your filter pattern shouldn't include the domain name. It should just be:

^\/((fr|en|de)\/)?$
4
  • Thanks a lot for discribing. Dec 14 '21 at 13:28
  • Thanks a lot for describing. I tried to use this expression and found that subdomains are included. So I need something for excluding subdomain.example.com. And I choose ^example\.com\/((ru|en|fr)\/)?$ for Request URI. And its not working. Im thinking, that google is not good with RegEx. Also, I'm using hostname, because a have one filter that include Full URL Dec 14 '21 at 13:39
  • Google Analytics doesn't have a field that contains both of those pieces of information, nor a filter mechanism to filter against two or more fields. Dec 14 '21 at 13:48
  • Thanks a lot for the help! Your expressions work well. I just need to remove the second filter Full URL and all data started to collect good. Have a good day! Dec 14 '21 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.