Personalize Flow Emails with Dynamic Event Data

read
Last updated at:

Overview

You can create personalized flow emails by using dynamic event data. For instance, you could use event data in an Abandoned Cart flow email to show individuals what product they left behind, an image of the item, and more. This allows for a more personalized experience for the customer, as well as a higher chance of conversion.

In this article, you will learn what dynamic event data is, when to use it, where to find it, and how to include it in your flow emails.

About Event Variables

When you have an integration with a third-party service or tool, Klaviyo records certain metrics when a customer profile takes an action. What actions Klaviyo tracks depends on your integration, but common ones include Checkout Started, Placed Order, and Viewed Product. In addition, each metric recorded in Klaviyo includes relevant information about the event, which is called metadata.

For example, when a customer begins to check out, Klaviyo will track this as a Checkout Started event. Klaviyo is periodically sent details from the third-party platform about the item(s) left in the cart, quantity of each item, total, images, etc. In Klaviyo, this data is stored as event variables and includes all of the information associated with an action a specific customer took.

When You Can Use Event Variables

Because event variables are based on a customer’s behavior, they can only be used in metric-triggered flow emails.

List-, segment-, and date property-triggered flows are not triggered by events, but by information about the customer in their profile. Thus, there are no event variables to pull from and use in a flow email. Similarly, event variables cannot be used in campaigns, as these are manual, one-time sends and are not based on the action a customer took.

image21.png

Common examples of metric-triggered flows include:

How to Find Event Variables

In a flow, you first need to select the email in which you want to show the dynamic event data. Next, click Configure Content > Edit Content.

image24.png

Once in the email template editor, click Preview on the left-hand side. You’ll see a popup saying, Choose a recent event to preview with. In the window, you will see a recent event that corresponds with the flow's trigger. For example, in an Abandoned Cart flow email, the preview window will show a recent Started Checkout event. If you want to look at the data for a different event, toggle left and right using the arrow buttons.

image10.gif

This preview window will show all of the data available for that particular event metric. To view a specific event variable, click on any line of data to reveal the associated template variable. The variable will appear within a gray box at the bottom of the window. Variable entries are numbered starting at 0 (not 1, as this information is brought over in an array), and this number does not equal the item quantity.

To use event variables, you must copy them exactly. Event variables are case-sensitive, and the slightest deviation from how it appears in the preview window could cause the variable not to work.

image20.gif

If you want to view the dynamic event data for an item in an abandoned cart email, click the first item under Items. In this case, the first item is MATTE COLOR LIP BALM - PEACH and the variable is {{ event.Items.0 }}.

image18.png

Event Variable Arrays

If you add the variable above to an email, you can pull in the dynamic data for the first item left in the cart. It is similar to going up to a line of people and asking the first person their name. This approach works well if there can only be a single item; however, it is time-consuming for multiple items or when you don’t know how many items someone might add.

Ideally, you would want to use a single command to get all of the event variables for items within a group instantly -- like being able to call out “Name” and getting the names of everyone in a long line.

When it comes to a list of event variables, arrays allow you to do just that.

An array occurs when there are multiple entries under one umbrella property (like multiple items in an order). As mentioned above, the first item will have a "0" at the end (or potentially in the middle), the next item will have a "1," and so on. Using an array, you can capture information about both the umbrella property (e.g., Items or Collections) and the individual entries under that property.

In the example below, there are three items in the preview for a Placed Order event:

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

For this example, the event variable for these items is event.Items.

image14.png

Another example is an event variable for an image, which allows you to display a dynamic image of a product.

image3.png
Here, {{ event.extra.line_items.0.product.images.0.src }} turns into {{ item.product.images.0.src }}.

Common Examples of Event Variables

The syntax for different event variables depends on both the integration and event metric. You can see the syntax for all of the available variables for a given event by scrolling through the preview window and clicking on the different entries.

Some common examples of variables by integration are listed below. Keep in mind that the exact variable may differ depending on the metric used to trigger the flow. 

BigCommerce
Product Name/Title {{ event.extra.line_items.0.product.name }}
Product Handle {{ event.extra.items.0.product.url }}
Image {{ event.extra.items.0.product.images.0.src }}
Price for Product  {{ event.extra.line_items.0.product.price }}
Quantity {{ event.extra.line_items.0.quantity }}
Total {{ event.extra.total_inc_tax }}
 

Magento 1

Magento 2

Product Name/Title

{{ event.extra.line_items.0.product.name }}

{{ event.extra.line_items.0.product.name }}

Product Handle

{{ event.extra.items.0.url_key }}

{{ event.Items.0.Product.Attributes.UrlKey }}

Image

{{ event.extra.line_items.0.product.images.0.url }}

{{ event.extra.line_items.0.product.images.0.url }}

Price for Product 

{{ event.extra.items.1.base_original_price }}

{{ event.extra.line_items.0.product.price }}

Quantity

{{ event.extra.line_items.0.quantity }}

{{ event.extra.line_items.0.quantity }}

Total

{{ event.extra.base_grand_total }}

{{ event.extra.base_grand_total }}

Shopify
Product Name/Title
 
{{ event.extra.line_items.0.product.title }}
Product Handle {{ event.extra.line_items.0.product.handle }}
Image {{ event.extra.line_items.0.product.images.0.src }}
Price for Product  {{ event.extra.line_items.0.line_price }}
Quantity {{ event.extra.line_items.0.quantity }}
Total {{ event.extra.customer.total_spent }}
WooCommerce*
Product Name/Title {{ event.extra.Items.0.Name }}
Product Handle {{ event.extra.Items.0.URL }}
Image {{ event.extra.Items.0.Images.0.URL }}
Price for Product  {{ event.extra.Items.0.LineTotal }}
Quantity {{ event.extra.Items.0.Quantity }}
Total {{ event.extra.Items.0.TotalWithTax }}

*You can rebuild carts from an Abandoned Cart Flow in WooCommerce by using the parameter ?wck_rebuild_cart={{ event.extra.CartRebuildKey }}.

Below, we discuss two different ways of iterating over these or other event variable arrays:

  • Using the Block Repeat feature
  • Creating a dynamic table

Using the Block Repeat Feature

The Block Repeat feature allows you to add a single block (text, image, etc.) that will automatically repeat itself and iterate over all entries in a property array.

First, go to the preview window to grab the event variable you want the block to iterate over. Here, we chose event.Item.

Next, drag a block into your email and click the gray "hamburger" icon in the upper left-hand side (between the question mark icon and Cancel button). Paste the event variable into the Repeat For box and give the variable an alias -- in this case, item is the alias.

image12.png

Switch the feature to On before clicking the Save button. You will then see the feature icon turn dark gray.

In the text box, insert the variable alias {{ item }} and save it. When you preview the template, you will see that all the value entries will populate as this variable is looped over.

image1.gif

Another example is using the Block Repeat feature with a table, such as in the example below.

image8.png

Building a Dynamic Table

If you want to create a more complex block featuring dynamic content, you can build a dynamic table. A dynamic table loops over all entries for a single variable. For example, if a customer abandons a cart with multiple items, those items will all be displayed in the table. A dynamic table also allows you to create a table of information that repeats (if necessary).

In Klaviyo, there are several built-in flows that contain emails in which dynamic tables are already set up, including the Abandoned Cart, Customer Winback, and Product Review / Cross Sell flows. You can also create these tables yourself if you are familiar with the event variables for your integration.

Step One: Adding a Dynamic Table

First, drag a table block into your email. Typically, you will want to delete the third column and column headers within the block columns as well as the divider, which can be adjusted under the Block Styles tab.

Next, go to Rows. Before inserting any text in the table, switch the table from Static to Dynamic. If you have already written a message in one of the cells, copy the message prior to changing the table to Dynamic, as doing so will automatically erase the contents of a table.

2019-11-19_14-26-00-2.gif

Step Two: Capturing the Event Variable

Go into Preview tab to pull up the available dynamic variables. Then, scroll down to the title for one of the products abandoned in a cart to find the event variable: {{ event.extra.line_items.0.product.title }}. This contains more information about the product than {{ event.Item }}, which is simply the name of the item.

image17.png

Step Three: Establishing a Data Source for the Dynamic Table

Click Data Source. Here, you will be able to input a Row Collection field, which is the variable you want to repeat, as well as the Row Alias. By default, they say Items and item, respectively.

You can leave the alias as is, but for Row Collection, paste in the event variable. Remove the brackets on both sides as well as the number and following text. For example, {{ event.extra.line_items.0.product.title }} becomes event.extra.line_items. This shortened form is called the collection.

image13.png

Step Four: Including a Dynamic Product Title

After the data source is set up, you can move on to using variables to include text in your email. Since this email is for an abandoned cart flow, it’s important to show the name of the product left behind.

To input the product title into the text, navigate to one of the columns. If you want an image in the first column and the text in the second, click on Column 2.

Next, paste in the full event variable once again. This time, replace the collection for the variable (i.e., the text you used for the Row Collection) as well as the following number with the Row Alias, and don’t delete the surrounding brackets. For this example, {{ event.extra.line_items.0.product.title }} now becomes {{ item.product.title }}, since item is the alias.

image11.png

Once you finish the steps above, preview the email to ensure that the title shows up. If it doesn’t appear, double-check the spelling, capitalization, and formatting of the text here and in Data Source against the variable shown in the preview window.

Step Five: Adding an Image

To insert a dynamic image, you need to find the event variable for the image in the preview window. Often, this variable is listed under image, img, or src, but it depends on your integration. Here, it is under src: {{ event.extra.line_items.0.product.images.2.src }}.

Once you have this variable, head to the column where you want to display the image (Column 1, in this case) and change it from Text > Image. Choose Browse and then select Placeholder.

image25.png

Input the image event variable, replacing the collection and following number with the alias; here, {{ event.extra.line_items.0.product.images.2.src }} becomes {{ item.product.images.2.src }}. Then, click Save.

Note that if there’s a number near the end (such as the 2 in this example), it should not be removed.

image7.png
In addition, check the Fit Image Area checkbox and set the pixel size (250 px is good in most cases).

image9.png
Once you finish making changes, click Save and preview your image to make sure it appears as expected. If an image doesn’t appear, check the spelling of the variable under Placeholder against the one in the preview window.

Step Six (Optional): Showing the Quantity and Total of a Product

If you want to show the quantity and total price for each product, navigate back to the column where you added the product title.

Type in “Quantity:” in the text box. Next, navigate to the preview window to find the event variable -- for example, {{ event.extra.line_items.0.quantity }}.

image23.png
After exiting this window, paste the variable next to “Quantity”, replacing the collection and number with the alias.

For the total, use the line_price event variable (e.g., {{ event.extra.line_items.0.line_price }}), which will show the total price of a product based on the quantity. For instance, if you have a lipstick that costs $12, and someone has added two of them, the line price will show as $24.

image22.png 

As with the quantity, write in “Total:” and replace the collection with the alias. To display the currency, either add in the currency symbol before the brackets -- for instance, ${{ item.line_price }} -- or add % currency_format inside the brackets and before the event variable, as well as another % before the closing brackets -- for example, {% currency_format item.line_price %}.

image15.png

By default, numbers will be shown as X.0. If you’d like to change this format, you can do so with the float format tag. Adding |floatformat:0 into the brackets will get rid of the decimal point and following number while |floatformat:1 will display with one number after the decimal point, |floatformat:2 will display with two, and so on.

image6.png

Step Seven (Optional): Linking to the Product Page

To link either a dynamic image or text to the associated product page, head to the preview window and locate the event variable for the product handle.

image2.png
For text, highlight the words where you want to link and click the insert link button. Then, either add the {{ organization.url }} tag or type out your store URL directly followed by products/ and the variable for the item product handle (for example, {{ item.product.handle }}). An example with the organization.url tag looks like: {{ organization.url }}products/{{ item.product.handle }}.

If you use the organization.url tag, you must set your link protocol to <Other> instead of http or https.

For images, add the same tag in the Link text input box under Image Settings.

image5.png 

Step Eight: Previewing Your Email

After completing the steps above, the email template should look similar to the one below.

image4.png
To see how this would look in an email, and to make sure the links work properly, click the Preview tab on the left-hand side and either preview the email directly in Klaviyo or send it to yourself. An example of the former is shown below.

image16.png

Additional Resources

x
Was this article helpful?
69 out of 154 found this helpful