To see what Databox can do for you, including how it helps you track and visualize your performance data in real-time, check out our home page. Click here.
Understanding regular expressions (regex) can be really challenging, especially if you are just getting started, but having this skill set is useful, especially for analysts and marketers. Regular expressions are essential for speeding up, setting up and auditing Google Analytics accounts and reports, and they help with advanced targeting, data organization, and deep insights delivery.
They also improve your ability to get accurate Google Analytics results, and as a newbie, you don’t need to have it all figured out initially. This article will discuss regex codes and provide all the information you need to use them in Google Analytics reporting.
So, let’s get right to it.
Regular expressions, also referred to as regex, are specific character sequences that broadly match search patterns in your analytics data set. They provide a syntax for finding, defining, and extracting data where basic filtering is not sufficient, and they can be used in multiple ways. You can use this tool in Google Analytics to develop flexible definitions for terms like goals, content groups, view filters, audiences, channel grouping, and segments. Besides, you can use regular expressions in place of plain text to simplify complex logic and test variables.
You can use this tool to find new data that Google does not filter by default. A regex is not only valuable for analytics, as users can use it to check for patterns in a string and run complex targeting on their A/B tests. Different tools and programming languages allow regular expressions, and they are usually made up of metacharacters with special meanings.
Regular expressions are handy in Google Analytics as they provide flexibility for report customization and configuration. Highlighted below are a few other uses of regex in Google Analytics.
Standard and custom reports in Google Analytics are in a table format, and using regular expressions in table filters is an efficient way to work with specific data within the reports. You can control what is included or excluded from your report with ease by using multiple regex codes, and you have the flexibility to use the advanced filter. Besides, you should ensure you select the ‘Matching RedExp’ for the match type when using the Advanced option for the table filter.
Building out filters is one of the most common uses of regular expressions in Google Analytics. You must set up a Google Analytics account and use a test view first to enable you to try a few things out first.
Go to the Admin tab, click on Filters, and add filters to set up filters.
There are different filters used in Google Analytics, with the most common ones being excluding traffic from your IP address, organizing your subdomain tracking, and cleaning up query parameters.
Related: The 7 Most Important Google Analytics Filters for Marketers
Regular expressions can be used to set up goals using events, destination, duration, and pages. You can create a goal that matches multiple pages. For example, If your users are redirected to different thank you pages after doing a transaction. when setting up a destination goal, you can use a regular expression to match different thank you pages
Struggling to find an easy yet effective way to gain a comprehensive understanding of your traffic sources, user behavior, and revenue generation?
You can do all that and more with our free plug-and-play GA4 Acquisition dashboard template:
You can easily set it up in just a few clicks – no coding required.
To set up the dashboard, follow these 3 simple steps:
Step 1: Get the template
Step 2: Connect your Google Analytics 4 accounts with Databox.
Step 3: Watch your dashboard populate in seconds.
When creating a custom GA report, you can use regular expressions to filter specific information. For example, you can use a regex to include only the home and services sections of your website when creating a customized report. Also, you can use this expression in the filters you have in your reporting views.
Google Analytics reports on All Sessions by default, and you can use segments if you want to dig deeper into a large dataset. If your segment has different conditions, you can use regular expressions to define the conditions in the segment builder. Besides, creating custom segments using regex is much easier than without.
Another critical use of regular expressions is to create channel grouping in Google Analytics. Channel grouping can be used to classify the various ways users find your websites, such as through social media and other platforms. For example, to create channel groups for social, you should select ‘Matches Regex’ and input (instagram| facebook| twitter| linkedin).* to match Instagram, instsgram.com, Facebook, facebook.com, LinkedIn, linkedin.com, Twitter, and twitter.com.
There are multiple pages in a typical sales funnel. For example, a user may go to different pages on your website when making a transaction. To set up a sales funnel to match the multiple pages, you need to use regular expressions, even though defining a funnel is optional. Plus, all URLs are treated as regex when you configure a funnel.
Related: How to Set Up and Use Funnel Reports in Google Analytics: A Step-by-Step Guide
Regular expressions can be used to create a dashboard for a specific data set, and you can add filters to the dashboard widgets inside Google Analytics.
You can use regular expressions to build audiences for remarketing and ad targeting in Google Analytics. Building an audience list is like custom segment creation, as you use a segment to create an audience.
Metacharacters are characters that take on a special meaning when used in regular expressions. These characters can be regarded as regex building blocks, and outlined below are the commonly used ones.
The asterisk is used to match zero or more of the previous items. This definition can be quite tricky to understand, so here are some examples to clarify it.
For example:
It will neither match bokks nor goggle because there needs to be zero or more of the ‘O’ as defined. You should also note that using an asterisk in regex is more powerful in combination with other metacharacters.
The dot matches one single character, like numbers and letters, and it picks up whitespace as well.
It only matches words with only one character, proving not very useful. However, Its true power lies when it is combined with other regular expressions like the asterisk.
This commonly used metacharacter combination matches zero or more random characters. This means that this combination matches everything, making it very powerful. Plus, you can use this to match anything in a string.
This regular expression is the logical OR that should be used when you want to say OR. It is commonly used in Google Analytics to filter, set up, and track goals.
In filtering use cases, you can use the example of “ digital marketing| content writing” to get reports on articles under these two themes.
The backlash is an escaping character that you can use to turn a metacharacter into a regular character and vice versa. You can use this to clarify whether to read regular expressions that appear in plain text as regex or normal text.
For example, the forward-slash (/) signifies the beginning and end of a regex. If you want to treat this / character as a forward slash rather than a special character, you need to add the escaping backslash character like this -\/.
This way, search queries in regex would be search\/\?q= instead of /search/?q=
You should add the backslash to treat the characters literally in the case of dollar signs and question marks.
This means USD\ $2 would match USD$2
The caret is used to signify the beginning of a regular expression and placing it at the start of a regex connects the search to the beginning of the searched data.
Besides, It won’t be matched if there is anything before the word that is anchored by the caret.
The dollar sign is used to signify the end of a regular expression – so it is the opposite of the caret. Placing a dollar sign at the end of the regex connects the search to the end of the data being searched.
Without these anchors, the dollar sign and caret, the regex would match anywhere in the searched data. Besides, the caret and dollar sign are commonly used together to target exact matches.
The question mark is used as a qualifier to check for zero or one occurrence of the preceding character. Using this means that the last character is optional, and it is useful if you want to target misspellings.
The plus sign is used as a qualifier to check for one or more occurrences of the previous characters. It is very similar to the asterisk with minor distinctions.
Parentheses in regular expressions work in the same way they do in mathematics – to create groups. This function is used to check for a string, and they capture the matched content as different elements. You can use the parentheses to create and store variables when using them in an advanced filter. Plus, combining them with a pipe will enable you to create a list.
For example: ^/products/(romance|thriller|suspense)/books/$ would match /products/ romance/ books/, /products/ thriller/ books/, and romance/ suspense/ books/.
The square bracket expression is used to make lists and match several iterations of alternative characters. You can also use this expression to exclude other iterations.
Square brackets develop different marching conditions depending on the characters you place inside them. Besides, you can combine them with dashes to create strong lists.
You can use the dashes to create linear lists to match, and it is best to combine them with square brackets. With this combination, you don’t have to list everything out.
The curly bracket is a qualifier that tells you how many times to repeat the preceding item.
The exclamation mark is a logical NOT, and it is only used at the beginning.
For example: [!A-Z] would match single characters that are not upper case letters.
There is no need to log into your Google Analytics account every time you want to check how your website is performing. With Databox, you can get website performance insights at a glance, not only from your GA but also from all of the other tools you are using.
It’s free and easy to get started.
To visualize your most important metrics in one place with our custom dashboard software just sign up for a free account here. From there, you can build a custom dashboard yourself, get access to our library of 300+ pre-built templates, have our customer success team set up multiple dashboards for you, and much more.
Are you maximizing your business potential? Stop guessing and start comparing with companies like yours.
At Databox, we’re obsessed with helping companies more easily monitor, analyze, and report their results. Whether it’s the resources we put into building and maintaining integrations with 100+ popular marketing tools, enabling customizability of charts, dashboards, and reports, or building functionality to make analysis, benchmarking, and forecasting easier, we’re constantly trying to find ways to help our customers save time and deliver better results.
Hey, we’re Databox.Our mission is to help businesses save time and grow faster. Click here to see our platform in action.
Luca Tagliaferro graduated in Digital Marketing from a UK leading University and 2012 and in the last 10 years he became one the leading SEO consultants in the UK (according to Google). He specializes in international SEO, e-Commerce SEO, website auditing, and migrations.
Get practical strategies that drive consistent growth