How to Personalize Content Using Liquid — Thread the Needle with Braze

“Be Absolutely Engaging.” Braze’s new tagline emphasizes the importance of marketers crafting highly engaging messaging that resonates with their audience through personalization. In today's fast-paced marketing landscape, where complex marketing strategy is becoming the norm and customer expectations have never been higher, delivering tailored content is essential. Standing out from the crowd has never been more crucial.

Liquid — Braze’s open-source, customer-facing template language created by Shopify and written in Ruby — allows marketers to do just that. With Liquid, marketers can harness the full potential of their customer insights and deliver content that captivates and engages like never before.

In this episode of Thread the Needle, Michelle Ohlson, Solution Architect at Stitch, walks through how to create personalized content for your customers using Liquid, including

  • An overview of Liquid and its basic syntax and functionality.  
  • A walkthrough of conditional logic and filters/operations. 
  • Assigning variables in Liquid
  • 3 use cases — using conditional logic, variables, and for loops.


Hello everyone. My name is Michelle Ohlson. I'm a Solution Architect at Stitch and I'm here to walk through some functionality and interesting use cases using Liquid to personalize your content in Braze. I'll take you through an introduction to Liquid as well as some different filters and operators, and then we'll end with three different use cases for using Liquid to supercharge your content.

To start, what is Liquid? Liquid is a coding language written in Ruby and created by Shopify, and it really lets you ultimately pull in different attributes and perform different operations on them, and again, leverage this all for personalization. I'm going to share my screen and start with a review of some just basic liquid syntax and functionality.

To start, you can pull different types of attributes using Liquid, and depending on the type of attribute you're pulling through, the syntax might be ever so slightly different. So starting with standard attribute, you know, bread and butter, kind of most basic attribute that you can pull in Braze, you'll start with the two open squiggles.

dollar sign, another open squiggle, the attribute name, and then close with three squiggle brackets at the end. If you want to identify an attribute that's maybe a little more complex, say a custom attribute, content block, etc., you would add that attribute type as the prefix, then a period, and then follow the rest of the syntax and note the attribute name.

Here we have a custom attribute example, as well as a content block example, and there are many different attributes that you can pull through. You can pull attributes based on campaign elements, canvas elements, geo-fencing elements, and custom event properties, and I definitely recommend checking out the Braze documentation for a full list of all of the different types of attributes you can pull in.

One last comment here before we move on. Pay attention to the coloration when you're coding using Liquid because it can often help you troubleshoot a bit. So, for example, let's say you're trying to write some liquid and there's no highlighting on there, it means that the system can't really recognize that you're trying to use liquid.

Next, if it's fully yellow highlighted, the one difference here is if you're looking at a variable, which we'll see later, but if you're trying to pull through a specific attribute, the yellow highlighting means that Braze can tell that you're trying to use liquid, but it's not quite identifying the attribute.

And then if you're yellow highlighted on the outside, purple in the middle, you're good to go. And as we encounter different colorations, I will definitely call that out. Next, I'm going to move on to conditional logic. Conditional logic is, again, a very powerful way to segment people using Liquid and personalize, really, your content from there.

The main structure for conditional logic. It's very similar to if then else logic that you may see in other coding language. If a user meets these conditions, this is the result. Otherwise, if they don't meet these conditions, check these conditions and so on and so forth. How we document that specifically in Liquid is we start with an if tag and end with an end if tag, then we start evaluating our conditions.

If, and then you can specify whatever that first condition is, here's the first result. Else if, any further conditions you want to check, you would use else if, then condition two, result two. You can have 50 of these else/if conditions if you really want to. There's no limit there. The only thing to be aware of is before your very last condition, you'll want to use this else tag instead of else if. And after this else tag,

that's really where you define the default criteria. If someone doesn't meet any other of your criteria, what do you want to be the default? Maybe you show them a specific fallback content block. A very common thing that I see is this abort message tag that basically says don't do anything with this person if they don't meet any of the criteria.

And as I mentioned before, the conditional logic, it's a different coloration from the attributes, so don't panic if you're seeing this green. Green is good to go here. And surprisingly enough, red is good to go for abort message tags. Now I'm going to talk through some of the different types of filters and operations that you can do on different data types of attributes.

And then going to talk about assigning variables before we get into some fun use cases. Depending on the data type, there are different operations that you can perform on that data. And there are also different ways that you identify values of that data type. To start strings, the value must be enclosed in a single quote when you're identifying it.

And the operators include contains, equals, and not equals, really. Not really a whole lot of different types of operations you can perform on that. An example here is if we say, if this loyalty tier attribute equals prep, for example. Numbers are a bit more flexible. When you're noting it, you don't need to enclose it in single quotes or anything,

and there are tons of operators available there. You can add, subtract, multiply, divide, and we will get into some crazy examples of that in a little bit, so stay tuned. Boolean are effectively true false values. There's no enclosure or single quote around them, and because really, the values are only, it's true or it's false, the operators you can leverage are really equals or not equals.

Dates get a little bit tricky. This is another one that I'm going to strongly recommend that you check out the Braze documentation on. There's a specific liquid notation here. That will reformat the date to whatever you need and dates often need to actually be converted to other data types to perform operations.

For example, we're going to get into number of days until an expiration date in a little bit, and we're actually going to have to convert that date into a number, effectively, in order to perform any operations on it. As I said with this, there are other specific items for things like arrays and objects and whatnot, and if you have any questions on any of these, I strongly recommend checking out the Braze Learning documentation.

The last thing I'm going to talk about is the concept of assigning a variable. Assigning variables also very powerful functionality to use in Liquid. It really lets you perform these operations and give you a lot more flexibility in deciding how values relate to each other. The way you do that is you just say assign, you create your variable, and then you define what that variable is. So in this case, a points available variable is the value of titles purchased multiplied by 10. Now, that is our review of the liquid functionality. Now I'm going to show you some specific use cases. We're going to start with a very standard, very basic, using liquid to personalize some content use case.

Let's pretend that this is a beautifully designed content block with all well designed creative, it's eye-catching, and I'm sure one of my fellow stitchers will show you how to do that in another video. But for now, we really are just focused on this one line of content. I want to personalize this content with first name as well as that user's favorite genre.

So I'm going to click on the value that I want. You can also type in the liquid if you're feeling comfortable enough with it, but if not, no worries. Really, anytime you see this plus sign, that's where you would click to add liquid. I'm going to add personalization. First name is a default attribute. And I still want to have a default value available.

So I'm going to type in bookworm and insert. And now this will populate the first name. And if no first name is there, the default will be bookworm. Going to do a similar thing with genre. So personalization, custom attribute, favorite genre. And the default value is going to be top. So I'm going to insert that there.

Now let's preview that so you can see what that looks like. I'm going to put first name Michelle, which is my name. Favorite genre is thriller, which is my favorite genre. Love me some Stephen King. So you have 'Hi Michelle, new thriller picks for you.' And let's say we didn't have either of those values available for some reason, we have 'Hi Bookworm, new top picks for you below.'

So that is a very classic use of liquid in content itself. Next, we're going to get into something a little trickier, but that really demonstrates assigning different value variables and then using the results of those variables to determine the right content for an individual. So, in this use case, let's say we have our favorite bookstore, they have a loyalty program, and they want to send specific content to an individual if their loyalty points are about to expire.

So, how do we do that? Really, what we're doing here is assigning a bunch of variables. We are taking this expiry variable that we're setting and we're saying that it is the custom attribute loyalty tier expiration date. We are converting that to pacific time just to make sure later on that we're all in the same time zone.

We're changing this to a number of seconds as a number. So changing date to seconds and then this plus zero tells the system treat this like a number. We're then doing the same thing with the variable of right now and performing the same operations there. Next, you know how I said previously that we convert the date to a number and then are subtracting.

We're taking that expiration date and subtracting now to get a number of seconds until that future date. And then we're taking that number of seconds and dividing by 86, 400 to get the number of days until that future date expiration. From here, we can actually segment if the number of days until expiration is less than 30, we have certain content we can show, otherwise, if the number of days until expiration is its other value, additional content, otherwise abort message, we'll give a preview here with some different date values, if we're, this is tomorrow, so 'we have your points are about to expire act now.'

Otherwise, if it's over a month out, 'don't miss out on loyalty point discounts.' Or if it's two months out, the content won't show because it's aborted. I have one final use case to take you through, and this is a For Loop. So, don't panic, if you haven't worked with For Loops before. A For Loop basically tells the code to run, the same bit of code multiple times in a row.

This is especially great if you're trying to evaluate objects or arrays where there are multiple values in there and you want to evaluate each value individually to see if that data should get pulled through and leveraged. How we do that here, first we're assigning two different variables. This authors variable, because this is where the results of our for loop are going to go, we're basically just specifying an empty variable that that data can be contained in later on.

Then we are assigning this author's full to a favorite author's attribute. I'm just gonna pull up, this is how this data is designed to be received. So there are three values, author first name, author last name, primary genre, and an individual in this example can submit multiple authors and that genre is being captured.

So keep this in mind in terms of how the For Loop is going through that data. Then the for loop kicks off. It says for all objects in this author's full, so all objects in this favorite author's attribute. Then we're going to do our favorite conditional logic. If the primary genre is Thriller, now what do we do when we find Thriller?

We're going to take the author's last name and we're going to put that into this empty variable that we created earlier. So we're taking authors, we're taking that last name, and we're all concatting them together. And now, because the reason we did this as a For Loop, is we want to evaluate Stephen King,

and Nora Roberts, and Dean Koontz, and any other potential nested objects that are within this field. Now, if we preview that, and then I just put this here so that we can see. So, I have a specific test user for this, that contains this data that we had here. So, the two Thriller values are Stephen King, and Dean Koontz, and those are the ones we want to appear.

And now here they are in this concatenated list. So in the future, if we ever wanted to perform any sort of check or evaluation, we have these values, specifically these Thriller Author Last Names stored. And that is everything. As a reminder, we went through what liquid is, basics of syntax, some filters and operation, conditional logic, and our three use cases for personalizing content.

For more information, I of course definitely recommend checking out other videos or the Braze documentation. I want to thank you for your time and I hope that you have a great day and enjoyed the content. Bye bye. 

You might also like...