Shopify Automation2026-07-02

[Shopify] Automating Customer Segmentation Based on Purchase Data: B2B Marketing Integration using Vercel Workflows


The Limits of Manual "Segment Delivery & Nurturing" as Customer Base Grows

To increase sales on an E-commerce site, implementing "personalized communication based on purchase history and customer attributes (MA: Marketing Automation)" is essential.

However, many E-commerce brands regularly face the following "gritty manual tasks":

  • Manually downloading CSVs from the admin panel of "VIP customers who have purchased 3 or more times, with a purchase in the last 3 months," and manually importing them into email marketing tools (like Klaviyo or Mailchimp).
  • Manually assigning tags (e.g., regular-buyer) on a SaaS platform when a customer purchases a specific item (like a subscription).
  • Due to delays in integrating with analytics tools, sending irrelevant ads or emails saying "Did you forget to buy this?" to customers who have already completed their purchase.

Such data synchronization lags and human errors not only severely damage the customer experience but also continuously increase the workload on operators.

This issue can be completely automated (Touchless) by catching Shopify's customer and order Webhooks and atomically executing segment evaluation and tag assignment within a secure, asynchronous processing pipeline using Vercel Workflows.


2. Before & After: Resolving Operational Bottlenecks

Item Manual CSV Export/Import (Before) Webhook + Vercel Workflows Automation (After)
Reflection Speed Weekly or monthly (slow due to manual process) Real-time (within seconds of purchase confirmation)
Evaluation Logic Manual Excel filtering by staff Accurate condition extraction by program (prevents bugs)
Breadth of External Integration Limited to sharing with email delivery tools Simultaneously sent to CRMs, LINE, Email (Resend), ad delivery lists, etc.
Errors & Omissions Mistaken deliveries due to copy-paste errors during list creation No fear of incorrect deliveries thanks to consistent Webhook-based updates

3. Implementation Example: Automated Customer Segmentation (Tagging) Upon Purchase

Below is an implementation example of Vercel Workflows (TypeScript) that automatically evaluates the cumulative Lifetime Value (LTV) based on order information and automatically assigns a "VIP" tag to the customer data in Shopify.

import { workflow } from "@vercel/workflows";

export const customerSegmentationWorkflow = workflow(async (context) => {
  const { customerId, currentOrderId } = context.payload;

  // 1. Fetch the customer's cumulative order data from the Shopify API
  const customerData = await context.run("fetch-customer-ltv", async () => {
    const shopifyDomain = process.env.SHOPIFY_DOMAIN!;
    const accessToken = process.env.SHOPIFY_ACCESS_TOKEN!;

    const response = await fetch(
      `https://${shopifyDomain}/admin/api/2024-01/customers/${customerId}.json`,
      {
        headers: {
          "X-Shopify-Access-Token": accessToken,
          "Content-Type": "application/json",
        },
      }
    );

    if (!response.ok) {
      throw new Error(`Failed to fetch customer data: ${response.status}`);
    }

    const { customer } = await response.json();
    return {
      totalSpent: parseFloat(customer.total_spent),
      tags: customer.tags ? customer.tags.split(", ") : [],
    };
  });

  // Threshold for VIP tagging (e.g., cumulative spend over 100,000 JPY)
  const VIP_THRESHOLD = 100000;

  if (customerData.totalSpent >= VIP_THRESHOLD && !customerData.tags.includes("VIP")) {
    // 2. If the threshold is exceeded and the VIP tag is not yet assigned, add the tag
    await context.run("add-vip-tag", async () => {
      const shopifyDomain = process.env.SHOPIFY_DOMAIN!;
      const accessToken = process.env.SHOPIFY_ACCESS_TOKEN!;
      
      const newTags = [...customerData.tags, "VIP"].join(", ");

      const updateResponse = await fetch(
        `https://${shopifyDomain}/admin/api/2024-01/customers/${customerId}.json`,
        {
          method: "PUT",
          headers: {
            "X-Shopify-Access-Token": accessToken,
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            customer: {
              id: customerId,
              tags: newTags,
            },
          }),
        }
      );

      if (!updateResponse.ok) {
        throw new Error(`Failed to update customer tags: ${updateResponse.status}`);
      }
    });

    // 3. Notify the marketing team via Email (Resend)
    await context.run("notify-marketing-team", async () => {
      await fetch(process.env.Email (Resend)_WEBHOOK_URL!, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
          text: `🎉 Customer ID: ${customerId} has surpassed 100,000 JPY in cumulative purchases. The VIP tag has been automatically assigned.`,
        }),
      });
    });
  }
});

4. HadayaLab's Marketing Automation Construction

At HadayaLab, we offer a BPR plan that completely automates the marketing data migration and tag management tasks—currently performed manually by E-commerce operators—using an API-first approach.

  • Automated CRM Sync (HubSpot, Salesforce Integration): Reflects Shopify customer behaviors (adding to favorites, purchasing, cart abandonment) to the CRM in real-time.
  • Direct Connection with LINE/SMS Delivery: Automatically sends messages via LINE Official Accounts to highly intent segments when inventory for specific product categories is restocked.
  • AI Analysis of Purchasing Behavior: Smart personalization where AI automatically predicts "items highly likely to be purchased next" based on buying trends and dynamically updates recommended banners.

If you are a marketing manager overwhelmed by manual segment deliveries and list updates, please consult HadayaLab regarding our E-commerce automation plans.

Get Your Free Workflow Audit