What is RegEx in Google Analytics?
While mastering RegEx is a skill of its own, one that can be quite complex to master, Google Analytics requires only a foundational understanding of its functionalities.
To put it short, RegEx in Google Analytics allows you to match specific patterns in your data.
How to Use RegEx Effectively in Google Analytics
In order to use RegEx effectively in GA, you will need to understand the tool’s Metacharacters & sequences, and their individual functionalities.
RegEx Google Goal Example
Let’s say you have three different thank you pages with unique URLs (/thank-you/, /thank-you-sales/, /product-inquiry-received/), but you would like to track all of them under a single goal completion. In order to do this you will need to set the ‘Destination’ (under Goal Details) to ‘Regular Expression.’
In the empty field you will need use the Pipe symbol | to separate each URL: thank-you|thank-you-sales|product-inquiry-received
RegEx PageView Filter Example
Let’s say you operate a Health and Wellness website and you have been writing lots of COVID-19 related blogs. You want to analyze traffic on all the blog pages that begin with /covid-19. This can be done very easily by using the ^ metacharacter and adding ^/covid-19 in the advance section of your All Pages breakdown.
Another RegEx PageView Filter Example
You currently run an eCommerce shop that offers both a wide list of products and services. You’re looking to compare PageViews and Bounce Rate data on two specific sections of your site, /products/ and /services/. This can be done by using both the ^ and the |. You can create the following regex to pull the data you need, ^/(products|services)/. Now you will be able to analyze the metrics you want for all the pages containing /products/ or /services/ (example: /products/black-gloves, /products/shoes/runners, /services/online-styling-course/ )
RegEx Custom Segments Example
Another area of Google Analytics that you can apply regular expressions to is within your custom segment settings. Let’s say that you wanted to filter traffic based on two Countries, Canada and Australia. This can be done by either using the built in OR options or by using regex.
RegEx can be a very powerful tool in Google Analytics. Allowing you to speed up your data analysis process, segment your data, and track specific goal interactions.
If you need help or have questions regarding regex use cases in Google Analytics or Google Tag Manager, feel free to email us at email@example.com