Shopify Flowを用いて、同じ商品を2回購入してくれた顧客にアクションをする方法

Topic summary

Shopify FlowとKlaviyoで「同一商品を2回購入した顧客にメール送信」したいという相談。初回購入で顧客タグに商品ハンドルを付与し、2回目購入時に同ハンドルが顧客タグに存在するか判定してKlaviyoイベントを送る設計だが、タグ判定の実装がうまくいかない課題。

提案:Shopify Flowの「Run Code」アクションを使用。注文のlineItemsからproduct.handleを配列化し、顧客tagsに同一handleが含まれるかをチェックして、isSecondPurchase(真偽値)を返す。Flowではこの出力を条件分岐に用い、trueならKlaviyoのTrack an Eventを実行(サンプルのLog outputをKlaviyoアクションに置換)。

技術詳細:Run Codeのinputでorder.lineItems.product.handleとorder.customer.tagsを取得。コードはhandles配列を走査し、tags.includes(handle)で判定。outputは{ isSecondPurchase: Boolean }。動作は十分検証済みではないため、必要に応じコード調整を推奨。

補足:スクリーンショットとコード断片が理解に重要。質問者は解説で理解し、Run Code学習と試行を進める方針。結論:解決済み。

Summarized with AI on December 17. AI used: gpt-5.

@Anonymous_876e90207c84eec074dc8f1fbdf1c908

Run Codeを利用されるのが良いかと思います。

Flowの全体図です。最後のLog outputをKlaviyoのアクションにご変更ください。

Run Codeの内容です。

input

{
  order {
    lineItems {
      product {
        handle
      }
    }
    customer {
      tags
    }
  }
}

code

export default function main(input) {
  let isSecondPurchase = false;
  const handles = input.order.lineItems.map(lineItem => lineItem.product.handle);
  handles.forEach(handle => {
    if(!isSecondPurchase) isSecondPurchase = input.order.customer.tags.includes(handle);
  })
  return {
    isSecondPurchase: isSecondPurchase
  }
}

output

type Output {
  isSecondPurchase: Boolean!
}

十分に検証はしていませんので、

うまく動作しない場合は、Run Codeのcode を見直していただくと良いかと思います。

ご参考まで。

(キュー田辺)

1 Like