Send an event to Klaviyo when a fulfillment is delayed, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Send an event to Klaviyo when a fulfillment is delayed

This task will watch for new order fulfillments, waiting a configurable number of days after each one. When the waiting period is over, if the fulfillment's status matches an item in the list, this task will send an event to Klaviyo, allowing you to use Klaviyo to contact the customer appropriately.

Runs Occurs whenever an order is fulfilled, with a 5 day delay. Configuration includes test mode, qualifying fulfillment statuses, klaviyo api token, klaviyo event name, and days to wait before checking.

15-day free trial – unlimited tasks

Documentation

This task will watch for new order fulfillments, waiting a configurable number of days after each one. When the waiting period is over, if the fulfillment's status matches an item in the list, this task will send an event to Klaviyo, allowing you to use Klaviyo to contact the customer appropriately.

Configure the "Qualifying fulfillment statuses" option with values from Shopify's "shipment_status" documentation.

Enable "Test mode" to make available a "Run task" button - press this button to have Mechanic send a test event to Klaviyo, allowing you to verify that everything's connected properly.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, everybody.

That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.

(By the way, have you seen our documentation? Have you joined the Slack community?)

Open source
View on GitHub to contribute to this task
Subscriptions
{% if options.test_mode__boolean %}
  mechanic/user/trigger
{% else %}
  shopify/orders/fulfilled+{{ options.days_to_wait_before_checking__number_required | default: 5 }}.days
{% endif %}
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
test mode (boolean), qualifying fulfillment statuses (array, required), klaviyo api token (required), klaviyo event name (required), days to wait before checking (number, required)
Code
{% if options.test_mode__boolean or event.preview %}
  {% capture order_json %}
    {
      "name": "#1234",
      "email": "customer@example.com",
      "fulfillments": [
        {
          "shipment_status": {{ options.qualifying_fulfillment_statuses__array_required[0] | json }}
        }
      ]
    }
  {% endcapture %}
  {% assign order = order_json | parse_json %}
{% else %}
  {% assign order = order.reload %}
{% endif %}

{% assign fulfillments_qualify = false %}

{% for fulfillment in order.fulfillments %}
  {% if options.qualifying_fulfillment_statuses__array_required contains fulfillment.shipment_status %}
    {% assign fulfillments_qualify = true %}
  {% endif %}
{% endfor %}

{% if fulfillments_qualify %}
  {% assign klaviyo_data = hash %}
  {% assign klaviyo_data["token"] = options.klaviyo_api_token__required %}
  {% assign klaviyo_data["event"] = options.klaviyo_event_name__required %}
  {% assign klaviyo_data["customer_properties"] = hash %}
  {% assign klaviyo_data["customer_properties"]["$email"] = order.email %}
  {% assign klaviyo_data["properties"] = hash %}
  {% assign klaviyo_data["properties"]["order_name"] = order.name %}

  {% action "http" %}
    {
      "method": "get",
      "url": "https://a.klaviyo.com/api/track?data={{ klaviyo_data | json | base64 }}"
    }
  {% endaction %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Qualifying fulfillment statuses
["in_transit", "failure", "attempted_delivery"]
Klaviyo event name
Fulfillment delayed or failed
Days to wait before checking
5