How to target Shopify Customer Segments & Other Data With Workflow Enrollment Filters

Learn how to target pretty much any customer on your Shopify store in real-time based on their historical data in Shopify.

On this page:

Introduction
Implementation
Breakdown of Variables
Example Workflow Triggers

Introduction


Justuno allows you to create powerful workflow enrollment triggers based on JavaScript variables exposed in your Shopify theme. This guide explains how to create JavaScript window variables using Shopify’s Liquid customer object to pass key customer data into Justuno.

While Justuno will track many of these things natively, Justuno won't be aware of the customer's historical data from before the Justuno Shopify app was installed.

Implementation


To expose Shopify customer data as JavaScript window variables, add the following code snippet inside your Shopify theme’s <head> or <footer> section (e.g., theme.liquid file).


{% if customer %}<script>
 window.justunoShopifyCustomer = {
    order_count: {{ customer.orders_count | default: 0 }},
   currency: {{ cart.currency.iso_code | json }},
    total_spent: {{ customer.total_spent | default: 0 | json }},
    tags: {{ customer.tags | json }},
    is_wholesale: {{ customer.tags | json }}.includes("wholesale"),
    accepts_marketing: {{ customer.accepts_marketing | json }},
    last_order_days_ago: {% if customer.last_order.created_at %}
      {{ 'now' | date: '%s' | minus: customer.last_order.created_at | date: '%s' | divided_by: 86400 }}
    {% else %}
      null
    {% endif %},
    product_ids: "{% for order in customer.orders %}{% for line_item in order.line_items %}{{ line_item.product_id }}{% unless forloop.last and order == customer.orders.last %},{% endunless %}{% endfor %}{% endfor %}",
    skus: "{% for order in customer.orders %}{% for line_item in order.line_items %}{{ line_item.sku | json }}{% unless forloop.last and order == customer.orders.last %},{% endunless %}{% endfor %}{% endfor %}",
    product_names: "{% for order in customer.orders %}{% for line_item in order.line_items %}{{ line_item.product.title | json }}{% unless forloop.last and order == customer.orders.last %},{% endunless %}{% endfor %}{% endfor %}",
    collections: "{% for order in customer.orders %}{% for line_item in order.line_items %}{% for collection in line_item.product.collections %}{{ collection.title | json }}{% unless forloop.last and order == customer.orders.last %},{% endunless %}{% endfor %}{% endfor %}{% endfor %}"
};
</script>{% endif %}

Breakdown of Variables


  • order_count: The total number of orders the customer has placed.
  • currency: The customer’s preferred currency code (e.g., "USD", "EUR", "GBP").
  • total_spent: The total amount the customer has spent in the store.
  • tags: An array of tags assigned to the customer.
  • is_wholesale: A boolean value that checks if the customer has a “wholesale” tag.
  • accepts_marketing: A boolean indicating whether the customer has opted in for marketing emails.
  • last_order_days_ago: The number of days since the customer’s last order.
  • product_ids: A comma-separated string of product IDs.
  • skus: A comma-separated string of SKUs.
  • product_names: A comma-separated string of product titles.
  • collections: A comma-separated string of all product collections.

Examples of Justuno Workflow Segment Filters Utilizing The Above Variables


  1. This following example targets customers who's last purchase was over 30 days ago.

  2. This following example targets customers who have spent more than $1000


    The total amount that the customer has spent on all orders in the currency's subunit.

    The value is output in the customer's local (presentment) currency.

    For currencies without subunits, such as JPY and KRW, tenths and hundredths of a unit are appended. For example, 1000 Japanese yen is output as 100000.

    This means that if you are trying to target spend of more than $1000 USD, you should also add another JavaScript Value condition to ensure that the visitor's local currency is also USD




  3. This following example targets customers who have a specific Shopify tag