Google Tag Manager

Forum Discussion

reentry's avatar
reentry
Influencer
2 months ago
Solved

How to Filter Multiple Values in a String Field (e.g., Product Categories)?

Hello everyone,

I’m currently working with a string field called Product Categories, which can have multiple values like Music, Metal, and Festival. My goal is to select 3 random products from the category Metal.

However, with the current filtering options in Braze (only equals or not equals), it seems impossible to achieve this. The equals operator only works for exact matches, and since the field contains multiple values, I can’t directly filter for Metal.

Does anyone have a workaround or a better approach to handle this scenario? How do you manage filtering when a field contains multiple values?

Thank you in advance for your help!

  • Hello Arso,

    Thanks for your input—I had a similar thought, but I’ve found a solution that works perfectly.

    It turns out Braze handles this in a rather peculiar way, but it works:

    When you create a field in a catalog via the API, you can set the type to "ARRAY". This enables the use of the operator "Include Value". Interestingly, this option is only available if the field is created via the Catalog API, and I’m not sure why that’s the case.

    I discovered this while reading the documentation on creating selections via API:
    Create Catalog Selections API

    Here’s my workflow:

    • I create the field via the API.
    • Then, I upload a CSV file with the data (next step: automation).

    The data in the array field looks like this:
    ["value1", "value2", "value3"]

    Hopefully, this solution can help someone else as well!



     

  • Hello Arso,

    Thanks for your input—I had a similar thought, but I’ve found a solution that works perfectly.

    It turns out Braze handles this in a rather peculiar way, but it works:

    When you create a field in a catalog via the API, you can set the type to "ARRAY". This enables the use of the operator "Include Value". Interestingly, this option is only available if the field is created via the Catalog API, and I’m not sure why that’s the case.

    I discovered this while reading the documentation on creating selections via API:
    Create Catalog Selections API

    Here’s my workflow:

    • I create the field via the API.
    • Then, I upload a CSV file with the data (next step: automation).

    The data in the array field looks like this:
    ["value1", "value2", "value3"]

    Hopefully, this solution can help someone else as well!



     

    • Arso's avatar
      Arso
      Expert

      Great find! I've used the catalogs API but I haven't tried arrays. Mainly because my clients have had their product databases structured in the way I described above. 

  • Hello! If you're doing this operation in the segment tool or on the campaign-level, you can use "matches regex" as a filter, and if you type "metal" in the input field, it would give you all users with a Product Categories attribute, where the value string contains "metal". 

    If you're doing this in liquid, on the message level, you can use "contains" as an operator to filter for "metal". 

    • reentry's avatar
      reentry
      Influencer

      Apologies, I didn’t explain it clearly earlier. I’d like to create a catalog with all products and then use a selection to filter them by product category.

      In the campaign, it should work so that, for example, 3 random products from the catelog with "Metal" category are selected. 

      Rano

      • Arso's avatar
        Arso
        Expert

        Ah, this is a product catalog. You need the selection to randomize the products. Got it. 

        Unfortunately, in this case, you'll have to split the Product Categories string column into one column per category, with a boolean value - true/false, yes/no. Then you can do a filter on "Metal equals TRUE". You can use the same catalog, keep the existing field and add the new columns on top. 

        I know this is not an ideal solution but it's the only quick and viable one here. You can submit a feature suggestion on the Product Roadmap page in Braze. 

        There might be a very complicated way to sort through the catalog within the message, using Liquid, but it will be a very heavy task to do this every time your campaign needs to send. Plus, add the randomization liquid on top and you have a very messy code.