Learn business growth with Google Analytics 4 Forums Google Analytics 4 Improving Google Analytics Audience Creation with Regex

  • Improving Google Analytics Audience Creation with Regex

    Posted by Jose on 21 August 2022 at 7:06 am

    Yo, I’m whipping up some audiences on Google Analytics 4 and hit a bit of snag. Turns out there’s a quota when applying conditions to the same audience – lucky I found a way around it with regex. Here’s what I’m aiming for:

    I want to include folks who completed a purchase event where the item_name includes any of these terms: Cappuccino, Flat White, Mocha, Latte, Americano, Ovaltine, Bubble Milk, Croissant, Sugar Loaf, Thick Toast, Mini Donuts, Ciabatta, Pizza Bread, Baked Pasta, mousse cake, cheesecake, or tiramisu.

    And here’s the regex I’m trying to use to make that happen:

    1. Purchase event where item_name matches this regex: (^Flat White$).*|(^Bubble Milk$).*|(^Sugar Loaf$).*|(^Thick Toast$).*|(^Mini Donuts$).*|(^Pizza Bread$).*|(^Baked Pasta$).*|(^mousse cake$).*
      OR
    2. Purchase event where item_name matches this regex: ^(Cappuccino|Mocha|Latte|Americano|Ovaltine|Croissant|Ciabatta|mccafe|cheesecake|tiramisu)

    Okay, regex masters, how am I doing? Anyone see any issues?

    I’m a little concerned because the audience pool is smaller than I thought it would be – could there be something wrong with the above regex?

    Finley replied 11 months, 2 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • Finley

    Member
    24 January 2023 at 12:34 pm

    The first regex you’ve written includes a “$” symbol after each term which means it will only match entries that end with the specified term. Consequently, this may exclude matches where there are additional characters or words after the term in your event names. Also, there appears to be a discrepancy between the list of terms you’ve mentioned initially and in your regex. For instance, you mention “Cappuccino” in your initial list but feature it only in your second regex. Therefore, it’s recommended to use a single regular expression that includes all your terms and eliminates the “$” symbol. This could look like this: ^(Cappuccino|Flat White|Mocha|Latte|Americano|Ovaltine|Bubble Milk|Croissant|Sugar Loaf|Thick Toast|Mini Donuts|Ciabatta|Pizza Bread|Baked Pasta|mousse cake|cheesecake|tiramisu). Be careful to match the case because regex can be case-sensitive. If there are still issues, scrutinize your data to ensure these item_names exist as you expect. If the audience pool is still smaller than anticipated, it’s possible some of your events are not being caught or there might be other discrepancies in your data.

Log in to reply.