チャンネルを使用した機能フラグとA/Bテストの方法
Capgoのチャンネルシステムは、ユーザーを分割して機能へのアクセスを制御するための柔軟な方法を提供します。Capgoには、組み込みのプラン管理やA/Bテストはありませんが、チャンネル割り当てを自分で管理することで、これらの機能を実装できます。
チャンネルの理解
Capgoのチャンネルでは、次のことができます。
- 特定のユーザーグループに異なる機能を対象にする
- ユーザーを異なるチャンネルに割り当ててA/Bテストを実行する
- 新機能を段階的にロールアウトする
- ベータテストプログラムを作成する
チャンネル割り当ての方法
1. バックエンド割り当て (推奨)
この方法はより安全です。次の手順が含まれます。
- アップデータからデバイスIDを取得する
- バックエンドに送信する
- Capgo API を呼び出す
実装方法についてはこちら
import { CapacitorUpdater } from '@capgo/capacitor-updater'
// Get device ID
const getDeviceId = async () => {
const { deviceId } = await CapacitorUpdater.getDeviceId()
return deviceId
}
// Send device ID to your backend
const assignToChannel = async (channel: string) => {
const deviceId = await getDeviceId()
// Your backend will call Capgo API to assign the device
await yourBackend.assignDeviceToChannel(deviceId, channel)
}
バックエンド実装
バックエンドでは
- API キーを Capgo ダッシュボードから取得する
- Capgo API を呼び出してデバイスをチャンネルに割り当てる
API キーを取得するには
- Capgo ダッシュボードにログインする
- 設定 > API キーに移動する
- 「新しいキーを生成する」ボタンをクリックする
- 選択する
allデバイスとチャンネルの管理モード - 生成されたキーを安全にバックエンド環境変数に保存する
- キーは32桁の16進数の文字列になります
- It’s a secret key that should never be exposed in client-side code
Node.jsの例です
import axios from 'axios'
const CAPGO_API_KEY = 'your_api_key'
const CAPGO_API_URL = 'https://api.capgo.app'
async function assignDeviceToChannel(deviceId: string, channel: string) {
try {
const response = await axios.post(
`${CAPGO_API_URL}/device`,
{
app_id: 'YOUR_APP_ID',
device_id: deviceId,
channel: channel
},
{
headers: {
'authorization': CAPGO_API_KEY,
'Content-Type': 'application/json'
}
}
)
return response.data
} catch (error) {
console.error('Failed to assign device to channel:', error)
throw error
}
}
バックエンド側も
- ユーザーの権限を検証する
- チャンネル割り当てのログを取る
- レート制限を実装する
- 失敗した割り当てに対してリトライロジックを実装する
2. 自動割り当て(セキュリティが低い)
この方法ではデバイスが直接チャンネルに割り当てられることができます。テスト用に便利ですが、生産環境ではセキュリティが低いです
import { CapacitorUpdater } from '@capgo/capacitor-updater'
// Assign device to channel
const assignToChannel = async (channel: string) => {
await CapacitorUpdater.setChannel(channel)
}
// Get current channel
const getCurrentChannel = async () => {
const { channel } = await CapacitorUpdater.getChannel()
return channel
}
ユーザーがチャネルに自分で割り当てることができるようになる前に、この機能を Capgo ダッシュボードで有効にする必要があります。
- Capgo ダッシュボードのチャネルセクションに移動してください
- 管理したいチャネル名をクリックしてください
- チャネル設定で「デバイスが自分で関連付けられることを許可する」にチェックを入れてください
- 変更を保存してください
この設定がfalseの場合、チャネルを指定して呼び出そうとすると失敗します。 setChannel 機能フラグの実装
機能アクセスを制御するためにチャネルを使用してください:
A/Bテストの実装
const isFeatureEnabled = async (feature: string) => {
// Example: Check if user is in beta channel
const channel = await getCurrentChannel()
return channel === 'beta'
}
異なるチャネルにユーザーを割り当ててA/Bテストを実行してください:
ベストプラクティス
const assignToABTest = async (userId: string) => {
// Use consistent hashing to assign users
const hash = await hashUserId(userId)
const variant = hash % 2 === 0 ? 'variant-a' : 'variant-b'
await assignToChannel(variant)
return variant
}
機能フラグの実装
- 使用:バックエンド割り当て:生産環境では、常にバックエンド割り当てメソッドを使用してください
- 一貫した割り当て:ユーザーIDや他の安定した識別子を使用して、一貫したチャンネル割り当てを実行してください
- 監視:各チャンネルごとに機能の使用状況とパフォーマンスメトリクスを追跡してください
- 段階的なロールアウト:小さなユーザーセグメントから始めて、段階的に拡大してください
- 明確なドキュメント:チャンネル戦略と目的をドキュメント化してください
結論
:Capgoのチャンネルシステムを活用することで、より個別化されたアプリエクスペリエンスを作成し、A/Bテストを実行できます。生産環境では、セキュリティとコントロールのために、常にバックエンド割り当てメソッドを優先してください
For more details on channel management, check out our channels documentation.
Keep going from How to Use Channels for Feature Flags and A/B Testing
If you are using How to Use Channels for Feature Flags and A/B Testing to plan channel routing and staged rollout, connect it with Channels for the implementation detail in Channels Channels for the implementation detail in Channels Channels for the implementation detail in Channels ベータテストソリューション ベータテストソリューションにおける製品ワークフローについて バージョン目標ソリューション バージョン目標ソリューションにおける製品ワークフローについて