Knowing how to access individual pieces of data is a great start to setting up your Klaviyo account to utilize the Shopper Approved integration. In this article, I will demonstrate how to loop through data in Klaviyo, particularly to get the product information from the data sent by Shopper Approved.
In another article, I created a new flow in Klaviyo to send a review link via SMS message to the customer. To make the experience more customized, I will instead send an email to the customer, detailing the products purchased and requesting a review.
To add a new email to your Kalviyo flow, you can drag and drop the email action from the left-hand bar onto your flow directly:
You can then click on that new email box in your flow and click "Configure Content" to open the email editor:
For this example, we can edit the Plain Text version of the email:
Similarly to the survey link in the SMS message created previously, we can create custom code to extract pieces of the JSON data from Shopper Approved. The first thing I want to extract in my example email is the order ID. The code for this in Klaviyo would be {{ event.order_id }}, extracting the order_id of the Shopper Approved event.
Now, I want to extract the product information. Because the product information is nested under "products" in the Shopper Approved data, we can not just put {{ event.products }}, since there's more than one piece of data for that key. We need to loop over each product and extract the data that way.
To do a "for" loop in Klaviyo, you can first declare the beginning and the end of your loop:
{% for item in event.products %}
{% endfor %}
This is going to loop through each product under "products" in the Shopper Approved event, and give it a name of "item." We can then extract the data for each item inside of our loop:
{% for item in event.products %}
{{ item.Description }}
{% endfor %}
This will print the description for each product. Now, my email gives the customer their order ID, lists the products to be reviews, and then I added the survey link again at the end, which would be the same code as from the SMS message: