Shopifyでアフィリエイトアプリの作り方
- User
Shopifyでアフィリエイトアプリの作り方
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Shopifyでアフィリエイトアプリの作り方
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
(※2024 年 6 月時点の API/審査要件に基づいています)
| 手順 | 詳細 | コマンド例 |
|---|---|---|
| パートナー登録 | https://partners.shopify.com/ | ー |
| Shopify CLI | Node: npm i -g @shopify/cli @shopify/app | |
| ngrok / Cloudflare Tunnel | ローカル → HTTPS 公開 | ngrok http 3000 |
| GitHub | 公開アプリは必須 (審査時にコードレビューされる場合あり) |
shopify app create node -n affiliate-app
cd affiliate-app
npm run dev # ngrok URL が自動発行される
/web
|-- server/ # Koa or Express
|-- frontend/ # React + Polaris + App Bridge
|-- shopify.app.toml # スコープ & 設定
スコープ例:
SCOPES=read_orders,write_discounts,write_script_tags,read_customers
| テーブル | 主なカラム |
|---|---|
| affiliates | id, name, email, referral_code, commission_rate |
| clicks | id, affiliate_id, shop_domain, ip, user_agent, occurred_at |
| orders_affiliates | order_id, affiliate_id, commission_amount, status(pending/paid) |
RDB (PostgreSQL) or Firestore などお好みで。
mutation {
discountCodeCreate(...){ id, code }
}
https://{shop}.myshopify.com/discount/ABC123?redirect=/products/xxx
orders/create webhook で注文内の discountApplications を確認し、該当コードがあれば紐付け。長所:Checkout で確実に渡る。
短所:割引が必須。クリックデータが弱い。
https://{shop}.myshopify.com/?ref=AFFCODE
// /snippets/affiliate.js
(function() {
const params = new URLSearchParams(window.location.search);
if(params.get('ref')){
document.cookie = `aff=${params.get('ref')};path=/;max-age=2592000`;
}
})();
fetch('/cart/update.js', {
method: 'POST',
headers: { 'Content-Type':'application/json' },
body: JSON.stringify({ attributes: { affiliate: getCookie('aff') } })
});
orders/create webhook で note_attributes / cart_attributes を読んで紐付け。長所:割引不要で純粋な紹介が可能。
短所:チェックアウトページ中のスクリプトが制限されるため、Online Store のみ対象。Shopify Plus であれば Checkout Extensibility で補完可能。
shopify.api.webhooks.addHandlers({
'ORDERS_CREATE': {
deliveryMethod: DeliveryMethod.Http,
callbackUrl: '/webhooks/orders-create',
callback: async (topic, shop, body) => {
const order = JSON.parse(body);
const code = order.discount_applications?.[0]?.code;
const attr = order.note_attributes?.find(a => a.name==='affiliate')?.value;
const aff = code || attr;
if(aff){
// DB に保存、コミッション計算
}
}
}
});
機能例
• Affiliate 一覧、追加・停止
• コミッション率設定
• 未払い報酬のダッシュボード
• CSV / PayPal Payout エクスポートボタン
// frontend/pages/Affiliates.jsx
import { Page, DataTable, Button } from '@shopify/polaris';
...
orders_affiliates.status を paid へ更新✅ OAuth フローが 100% 動く
✅ パーミッション要求は最小限
✅ アプリ設定 -> GDPR Webhook (customers/data_request, customers/redact) 実装
✅ 英語 & 日本語の listing, スクリーンショット
✅ サポート用プライバシーポリシー URL
✅ 1 ストアでテストインストールした状態で審査申請
• Checkout で JS が動かない → 割引コード or Plus チェックアウト拡張へ切替
• テーマ改変を嫌がるマーチャント → Theme App Extension 形式を選択
• 自社に支払処理ライセンスが無い → PayPal Payouts API を代理利用
• 個人情報扱い → 注文情報を外部転送する場合は明示的 Consent 必須
• Shopify Dev Docs
https://shopify.dev/docs
• Admin GraphQL API: DiscountCode
• ScriptTag / Theme App Extensions
• Polaris UI Kit
https://polaris.shopify.com/
• App Bridge React
• Shopify CLI v3 チュートリアル
orders/create webhook」で十分。「こんな機能はどう実装する?」「コードをもう少し見たい!」など、追加の質問があれば気軽にどうぞ 😄