Pass tracking number as event property to Klaviyo

Solved

Pass tracking number as event property to Klaviyo

monnedepraetere
Tourist
9 0 1

We're trying to set up a Shopify Flow which identifies failed deliveries and passes on the courier's unique tracking number (along with the customer email and order name) to Klaviyo as Event Properties (see also Klaviyo's docs).

 

The trigger of the Flow is a Scheduled Run combined with a Get Order Data action after which we run a 'For Each' loop on all the orders to send them to Klaviyo.

 

So far we got the customer email and orderNumber working by passing this to Klaviyo as follows:

 

 

{
"deliveryStatus": "deliveryFailed",
"customerEmail": "{{getOrderDataForeachitem.email}}",
"orderNumber": "{{getOrderDataForeachitem.name}}"
}

 

 

As for the tracking number, we are able to produce this via the following loop:

 

{% for fulfillmentOrders_item in getOrderDataForeachitem.fulfillmentOrders %}
  {% for fulfillments_item in fulfillmentOrders_item.fulfillments %}
  {% for trackingInfo_item in fulfillments_item.trackingInfo %}
  {{trackingInfo_item.number}}
{% endfor %}
{% endfor %}
{% endfor %}

 

 

However, this in theory produces a list of tracking numbers whereas we only need a single tracking code value as we'll never have more than one tracking number assigned to an order. How can we condense the above loop in a single line statement that can be passed on as an Event Property to Klaviyo? 

Accepted Solution (1)

DaveMcV
Shopify Staff
104 31 29

This is an accepted solution.

Hi Monnedepraetere,

If it will always be the first item of each array, you could use the `| first` filter and `assign` to ensure you only get one value.

Something like:

{% assign firstFulfillmentOrder = getOrderDataForeachitem.fulfillmentOrders | first %}
{% assign firstFulfillment = firstFulfillmentOrder.fulfillments | first %}
{% assign firstTrackingInfo = firstFulfillment.trackingInfo | first %}
{{ firstTrackingInfo.number }}
DaveMcV | Flow Development Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.

View solution in original post

Replies 4 (4)

ParcelPanel
Explorer
73 2 7

If you use ParcelPanel to connect Klaviyo via API, you can accomplish more than passing the tracking number, but also updating your customers on the latest shipment status. For example, after the shipment status is changed to "Delivered," it will be the best time to send a review request email.

 

Here's our help center article that might be helpful to you. How to connect ParcelPanel & Klaviyo via API?

Make Post-Purchase the Best Part of the Customer Experience.
Delight your customers with automated shipment tracking, increase brand loyalty and drive more sales.
Official Website | ParcelPanel Shopify App

Digico
Shopify Partner
47 1 5

Your loop seems correct (check if there's your needed data sent), once you have this create a new "then" event in Flow. That is HTTP Request to Klaviyo API to send only the current transaction. I'll follow the post.

 

Basic tutorial of API in Shopify Flow:

https://help.shopify.com/en/manual/shopify-flow/reference/actions/send-http-request

DaveMcV
Shopify Staff
104 31 29

This is an accepted solution.

Hi Monnedepraetere,

If it will always be the first item of each array, you could use the `| first` filter and `assign` to ensure you only get one value.

Something like:

{% assign firstFulfillmentOrder = getOrderDataForeachitem.fulfillmentOrders | first %}
{% assign firstFulfillment = firstFulfillmentOrder.fulfillments | first %}
{% assign firstTrackingInfo = firstFulfillment.trackingInfo | first %}
{{ firstTrackingInfo.number }}
DaveMcV | Flow Development Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
monnedepraetere
Tourist
9 0 1

Many thanks Dave, that worked.!

 

FYI - this is how the whole 'Event Properties' code section looks like in the end:

{% assign firstFulfillmentOrder = getOrderDataForeachitem.fulfillmentOrders | first %}
{% assign firstFulfillment = firstFulfillmentOrder.fulfillments | first %}
{% assign firstTrackingInfo = firstFulfillment.trackingInfo | first %}

{
"deliveryStatus":  "deliveryFailed",
"customerEmail": "{{getOrderDataForeachitem.email}}",
"orderNumber":  "{{getOrderDataForeachitem.name}}",
"trackingNumber": "{{ firstTrackingInfo.number }}",
"trackingUrl": "{{ firstTrackingInfo.url}}"
}