Braze Tutorial: Abandoned Cart Email & Liquid For Loops

Abandoned Cart Emails are a necessity to Marketing teams; however, they can be a bit tricky to set up!

Check out this video for a full tutorial on how to set up Abandoned Cart Emails using Liquid For Loops ➰

🗣️ WATCH FULL YOUTUBE VIDEO HERE 🗣

https://youtu.be/mMqrHqeYHto

What’s up everyone, my name is Allan, Founder and Consultant at For Now Marketing, and welcome back to our channel!

Before we get started, if you have any questions, whether you are currently using Braze or considering using Braze, please feel free to reach out! You can find these addresses and more in the Youtube description below.

Today, we are going to talk through a very common use case: Abandoned Cart Emails, using Liquid For Loops.

This will be a fun topic, so stay till the end, and get ready for some fun Liquid scripts!

Let’s get started!

Custom Attribute: items_in_cart

Before we can jump into the setup and the Liquid, there is a pre-requisite to our tutorial. It is strongly recommended that you work with your Engineering team to set up a Custom Attribute called items_in_cart that constantly represents the exact items that are in the user’s carts and is updated in real time, whether items are added or deleted.

Having this Custom Attribute will make it much, much easier for you to set up the Abandoned Cart Campaign, and this tutorial will be based off of us having this Custom Attribute.

Now, if you don’t have this Custom Attribute set up, this video may still be useful for you because we’re still going to go over the datatype of the items_in_cart Custom Attribute, so later when you are ready to have this conversation with your Engineering team, you can explain with confidence what you’re looking for and why.

Lastly, if you at least have a Custom Event for every time an item gets added or deleted from the cart, we could possibly make our own items_in_cart Custom Attribute using Webhooks. While this may be possible, it’s a technical process which will deserve its own video in the future.

For now, let’s just look into what this items_in_cart Custom Attribute looks like.

items_in_cart Example

So if you see here, I’ve added an example of the Custom Attribute items_in_cart, and let’s check out what’s inside this data.

By the way, items_in_cart is an Array of Objects. Array is pretty much a list of data, and Objects is pretty much a group of data, so when you put those together, we have a list of groups of data.

We have 3 groupings here, each representing one item that’s in the cart, and each groupings have additional information about each of the items.

We have “id” which is the product name, “img_link” which will provide an image that we can use in the Abandoned Cart Email, and “price”. All 3 data will be used inside our Abandoned Cart Email.

Array of Objects is the best data structure for our items_in_cart Custom Attribute, because most likely, your platform allows users to have multiple items in the cart, so the Array structure is handy. But also, each item will have multiple data that we’ll need to surface in the Abandoned Cart Email, so the Object structure is also handy.

And that’s why we use the best of both worlds: Array of Objects.

Abandoned Cart Email — HTML

All right, now that we’ve discussed the data, let’s finally jump into our email and take a look at the Liquid setup! I’ve created a basic Abandoned Cart Campaign from one of the Braze email templates.

Now, this part does require a little bit of HTML. Not a whole lot, as I’m not an HTML Developer myself, but we do need to know where each item row starts and ends. After a little bit of digging, I realized lines 140–170 represent one item line, so if I copy all this and paste it multiple times, this is the behavior or result we want for each item that’s in the items_in_cart Custom Attribute.

So I’ll press command+z twice to undo those two additions. Here’s where Liquid comes in.

We want to use a Liquid For Loop which will render as many rows as the number of items in our items_in_cart array. And for each row that gets rendered, we will insert dynamic data which will pull data from our items_in_cart array and replace these placeholder values, like the “Litora Nisi Proin”, $24.99", and the image.

Liquid For Loop

The first thing we’ll do is add {% for item in %}, right before line 139, right before whichever HTML section that we want to be repeated.

And before we break down what this means, let’s also add {% endfor %}, right at the end of or repeated HTML section, line 173 for us, so we don’t forget it for later.

{% for item in %}

This snippet starts our For Loop. The word “item” is our variable, and we could’ve chosen any other word, like {% for things in %} or {% for x in %}. “item” was simply the most intuitive variable name to choose, bc, well, the Custom Attribute we’re working with is items_in_cart.

is the Custom Attribute that we’re using for this For Loop, the one we saw earlier in my User Profile.

This syntax pretty much translates to: “for every item in your Custom Attribute items_in_cart. So Liquid will render the code that’s in between {% for item in %} and {% endfor %}. The {% endfor %} syntax is simply where the For Loop ends.

So that means that Liquid will render the HTML snippet as many times as the number of items in our items_in_cart Custom Attribute, which for us, was 3 times. And if we preview with our User Profile, there it is, 3 items in the email!

This could look different depending on how many items you have in your Custom Attribute. The number of items should match, theoretically.

Inserting Dynamic Data

Now that we got the For Loop set up, we need to insert the dynamic data. We don’t want to be listing “Litora Nisi Proin” every time!

So when the Liquid is going through each item of the array, it will use the variable name that we chose and store the data under that variable. In our case, all the data will live under the variable called item.

And if we look back at the User Profile example, each item has 3 children-data: id, img_link, and price. To access these 3 children-data, we access it this way: , , or .

So Liquid will simply go through each of the items in the Custom Attribute in order, and display each dynamic data during each iteration or cycle.

So what I will do is simply replace the placeholder data with the dynamic data that we just discussed. So replace Litora Nisi Proin with , the price 24.99 with , and the image link here with .

And now we have a completely dynamic Liquid For Loop that should render a very specific row for each of the items we have in our cart!

There’s only one way to find out how this looks. Click Preview, and…

Final Result

There it is, our beautiful Abandoned Cart Email! With each of the 3 items in my items_in_cart Custom Attribute, with dynamic name, price, and images!

Thank You!

That’s it for today.

If you have any questions, please share them in the comments. We’re happy to help! 🙏

If you learned something from this video, please subscribe for more awesome Braze videos in the future!

Thank you for watching, and see you next time!

allan@fornowmarketing.com

fornowmarketing.com

Previous
Previous

Braze Tutorial: Demystifying User Profile Types — Anonymous, Alias, & Identified

Next
Next

Braze Liquid: 5 Things You Need To Know About Liquid Conditionals (if/elsif/else)