Skip to main content

Best Practice : using regex to reduce the steps in a dimension

"OR" inside regex, to reduce conditions in steps.

Context

A dimension that covers every source, campaign type and so on, and is also extended to Analytics, can grow very fast. Especially when the naming taxonomy isn't consistently followed: you have to juggle several conditions within a step, and they quickly pile up. 
​

The idea is to keep a single condition per step thanks to a regex, which handles the ORs and absorbs potential naming errors (typos, variants, encodings).

OR inside a regex

If you want to put an OR on several values in a single step, write them in one regex separated by |. A single condition then replaces several steps, and keeps its AND with the first "when" filter.

  • Without regex: 3 steps "UTM source = meta AND campaign contains branding", OR "… brand", OR "… notoriete".

  • With regex: 1 step "source = meta AND campaign matches regex branding|brand|notoriete".

The same principle applies to the source itself: ^meta|^fb$|^ig$|^facebook|^tiktok|^snap|^pinterest groups every way the social UTM sources are written into one condition.

How to add it to the dimension

  • In the step, keep the first condition on the UTM source or another filter.

  • Add the condition on the field you need (UTM campaign, UTM content...) with the Matches regex operator, and paste the regex without quotes.

  • Tick "Not case sensitive": no need to write [Bb]randing.

  • Order the steps from most specific to broadest: only the first matching step applies.

  • End each source with an "Others" step (no field condition) rather than a list of "do not contains".

  • Note in the step comment what the regex covers, then test the rule before saving.

How to build the regex

Need

Syntax

Example

OR between several values

a|b|c

branding|marque|ad4010

Starts with

^

^tiktok (tiktok, tiktok_ads…)

Exact value

^…$

^fb$ (not "fbx")

Optional character

.?

first.?commercial (first commercial, first_commercial)

Segment surrounded by spaces or +

[+ ]yt[+ ]

"- YT -", "+yt+"

Encoded spaces in UTMs

%20 or %2b

%20yt%20

Tip: ask an AI assistant to build the regex for you.

Before / after example

A "Strategy" dimension blended across Ads + Analytics goes from 50 to 20 steps, with the same output values.

Value

Before

After (1 step, after the social UTM source filter)

Brand

3 steps: branding, brand, noto

branding|brand|noto

Performance

4 steps: performance, perf, vente, sales

performance|perf|vente|sales

Other

list of "do not contains"

"Other" step with no condition

Did this answer your question?