Personalize Flow Emails with Dynamic Data

Overview

After you integrate Klaviyo with an another third-party tool or service, Klaviyo will begin tracking certain metrics through the integration. For many integrations, we track event data based on how and when people are engaging with your business through the integrated service.

When Klaviyo records an event through your integration -- such as Checkout Started, Placed Order, or Made Contribution -- we also capture pertinent information related to the event. For example, for order-related events, we capture relevant order data. This includes all items in the order, images, and other details related to each item.

Personalization and event variables make it easy to leverage this data to send your customers more tailored and relevant emails.

For example, when a customer begins to check out, Klaviyo will track a Checkout Started event. If this customer then leaves their cart behind, you can configure an abandoned cart flow to send one or more emails to the customer until he/she revisits your site and completes the checkout process. These abandoned cart emails can feature images of the exact items a customer left behind and a link back to the customer's own cart.

To populate an email with details from an event, you can insert event variables that will dynamically populate for each recipient.

636330

The rest of this guide will explain where to find the event variables available for use in a given email, and how to leverage these variables in your emails where possible.

How to use Event Variables

You can only access and use event variables in a flow email when the flow itself is triggered by an event. If a flow is triggered by a list or segment, it won't be possible to use event variables in your emails. You also won't be able to use event variables in campaign emails.

To find the different event variables you can use in a given template, click Preview within the template's main Edit Content window. When you click to preview your flow email, a window will appear that says, Choose a recent event to preview with. You will see the window populated with an example recent event that corresponds with the flow's trigger. For example, for an Abandoned Cart flow email, the preview window will show a recent Started Checkout event.

This event preview window will show all of the data available for that particular event metric. Here, you can click on any line of data and reveal the variable associated with it. The variable will appear within a gray box at the bottom of the window.

2017-04-24_13-22-39.png

In the above example, I clicked on the entry 0 for variable Items. This revealed the corresponding variable {{ event.Items.0 }}.

The syntax for different event variables will be specific to your event metric and your integration. In order to understand which variables are available for each event and the syntax for each, scroll through all of the data you see in the preview window for a specific flow email and click on different entries. 

When there are multiple entries under one umbrella property (like multiple items in an order), you will notice that the first item will have a "0" at the end (or potentially in the middle) and the next item will have a "1" and so on. This is called an array. Each entry in the array is numbered starting with "0" as the first entry. By using an array, we can capture one property (such as Collections, or Items) but capture multiple values for that one property where each value can be identified individually. 

In the example below, you will see there are two items in the preview order:

The variable for the "Hershey's MINI Chocolate Bar" item is {{ event.Items.0 }}
The variable for "hershey’s mini krackel, single piece" item is {{ event.Items.1 }}

2017-04-24_13-27-08.png

So, what happens if you want to iterate over all items in an array, and not just include a variable for a single entry in the array? There are two ways to approach this:

The Block Repeat Feature

This feature allows you to insert a single block that will automatically repeat itself and iterate over all entries within a property array.

To turn on this feature for a given block, click the icon at the very top of a block, next to Save Changes.

When you click this icon, a small window will pop up that prompts you to specify a property to loop over (i.e. repeat) as well as an alias you can use in your template. In the example above, you see that we have {{ event.Items.0 }} and {{ event.Items.1}}. The property variable itself is event.Items, and we want to loop over this variable so that both event.Items.0 and event.Items.1 will populate.

In this example, the Repeat For variable is event.Items.

We can then assign this an alias -- let's assign the alias as item. Then we can say, loop over every item in event.Items.

2017-04-24_13-33-48.png

After clicking to turn the block ON, and clicking Save, you will see the icon change to dark blue.

You can then insert the variable alias {{ item }} into your template and click save. When you preview your template, you will see that all value entries in the array will populate as the specified variable is looped over.

636334.png

Building a Dynamic Table

If you want to create a more complex block featuring dynamic content that loops over all entries for a single variable, you can create a Dynamic Table. The Dynamic Table will allow you to create a table of information that repeats.

The Abandoned Cart, Customer Winback, and Product Review / Cross Sell flows that Klaviyo may have provided out-of-the-box for you already contain emails with dynamic tables configured. Now that you're more familiar with Event Variables in general, you can learn how to create a Dynamic Table yourself.

Step One: Create a Dynamic Table

To create a Dynamic Table, drag over a Table Block and click over to Rows. Here, you can toggle the block from Static to Dynamic.

2017-04-24_13-41-24.png

Step Two: Establish a Data Source for Dynamic Table

The data source will prompt for a Row Collection field and then a Row Alias that you can use.

 636336.png

The Row Collection field will prompt for the variable you want to repeat. Applying the same example we used for the section above, this variable would be event.Items. The Row Alias would similarly be item.

The image above in this section shows event.extra.line_items as the variable to loop over. In the gif below, you can see that this variable is the core variable being used for several different event data values. 

636338

By setting event.extra.line_items as the variable to loop over, we can then use item.vendor and item.title in our template without having to worry about the more complex syntax of the full variable.

Step Three: Inserting Variables into Table

Next, you'll need to populate your table with the variables of your choice. You can find these variables when previewing your email (as explained above). Remember: instead of copying the variable exactly, be sure to use the Row Alias you established along with your data source.

2017-04-24_13-46-20.png

You will find this image link variable the same way you'd find any other variable: in the Preview Email window

Below, you will see where I found and clicked on the image link variable. What you see underlined in green is our Data Source. What you see underlined in red is the variable value we can use along with our alias.

636343.png

The full variable is: item.product.images.0.src

Since we want to iterate over ALL product images, and not just show the image of the first product, we must take out the "0" that identifies a specific item.

The variable we insert is thus: item.product.images.src

To insert an image link variable, you will use the Placeholder Image option to insert this variable. 

 
Was this article helpful?
5 out of 9 found this helpful