Personalize Flow Emails with Dynamic Data

read

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-08-31_10-54-34.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 three items in the preview order:

The variable for the "Sweet Tarts" item is {{ event.Items.0 }}
The variable for "Runts" item is {{ event.Items.1 }}
The variable for "Nerds" item is {{ event.Items.2 }}

2017-08-31_10-57-35.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-08-31_11-02-12.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, you can create a dynamic table. A dynamic table loops over all entries for a single variable. This means, for example, if a customer abandons a cart with multiple items, these will all be displayed in the table. A dynamic table will allow you to create a table of information that repeats (if necessary).

The Abandoned Cart, Customer Winback, and Product Review / Cross Sell flows that Klaviyo provides out-of-the-box contain emails with dynamic tables that are already set up. If you're familiar with event variables for your integration, you can also learn how to create a dynamic table yourself.

Step One: Add a Dynamic Table

To create a dynamic table, drag over a table block and toggle to Rows. Here, you can additionally toggle the block from Static to Dynamic.

2017-08-31_11-03-15.png

Step Two: Establish a Data Source for Dynamic Table

The data source will prompt you to input a Row Collection field, as well as a Row Alias. The Row Collection field should contain the variable you want to repeat. Applying the same example we used for the section above, this variable would be event.Items and the Row Alias would be item.

 2017-08-31_11-03-57.png

 

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. This is what using an alias solves.

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. Instead of copying the variable exactly, be sure to use the Row Alias you already established along with your data source.

2017-08-31_11-05-51.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 how to find the image link variable. The data source is highlighted in yellow and the variable value is highlighted in orange. 

2017-08-31_11-07-07.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.

So, the variable we insert is: 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?
10 out of 20 found this helpful