Personalize Flow Emails with Dynamic Event Data

Last updated at:


After you integrate Klaviyo with another third-party tool or service, Klaviyo will begin tracking certain metrics through the integration. Through an integration, Klaviyo is able to sync import activity from the other tool or service so that you can use this activity data in Klaviyo.

When Klaviyo records an event on a contact profile -- such as Checkout Started, Placed Order, or Made Contribution -- we also capture pertinent information related to the event. For an order event, this might include all items in the order, images, and other details related to each item.

Special "event variables" let you pull this detailed event data into any email.

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 they revisit 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.


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.


In the above example, we 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 }}


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.


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.


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.

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.



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.


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.


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.


The full variable is: item.product.images.0.src. To insert an image link variable, you will use the Placeholder Image option to insert this variable.

Was this article helpful?
58 out of 140 found this helpful