기능 플래그 및 A/B 테스트를 위한 채널 사용 방법
Capgo의 채널 시스템은 사용자를 구분하고 기능 접근을 제어하는 유연한 방법을 제공합니다. Capgo에는 내장된 계획 관리 또는 A/B 테스트가 없지만 채널 할당을 관리하여 이러한 기능을 implement할 수 있습니다.
채널 이해
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)
}
백엔드 구현
Your backend needs to:
- API 키를 Capgo 대시보드에서 가져야 합니다.
- Capgo API을 호출하여 장치를 채널에 할당해야 합니다.
API 키를 얻으려면:
- Capgo 대시보드에 로그인하세요.
- 설정 > API 키로 이동하세요.
- 새 키를 생성하세요.
- 모드
all장치 및 채널을 관리하기 위해 모드를 선택하세요. - 생성된 키를 안전하게 백엔드 환경 변수에 저장하세요.
- 키는 32자리 16진수 문자열입니다.
- 클라이언트 측 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
}
}
백엔드도 다음을 수행해야 합니다.
- 사용자의 권한을 검증합니다.
- 채널 assignments를 모두 로깅합니다.
- 속도 제한을 처리합니다.
- assignment에 실패한 경우 다시 시도 로직을 구현합니다.
2. Self-Assignment (Less Secure)
이 메서드는 장치가 직접 채널에 할당할 수 있도록 허용합니다. 테스트에 유용하지만 프로덕션에 적합하지 않습니다.
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
}
Before users can self-assign to a channel, you need to enable this feature in the Capgo dashboard:
- Capgo 대시보드에서 이 기능을 활성화해야 합니다.
- __CAPGO_KEEP_0__ 대시보드의 채널 섹션으로 이동하세요.
- 관리하고 싶은 채널 이름을 클릭하세요.
- __CAPGO_KEEP_0__
이 설정이 거짓일 경우, 이 채널을 통해 호출하는 모든 시도는 실패합니다. 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
}
백엔드 ASSIGNMENT 사용
- 프로덕션 환경에서는 백엔드 ASSIGNMENT 방법을 항상 사용하십시오.일관된 ASSIGNMENT
- 유저 ID 또는 다른 안정적인 식별자를 사용하여 일관된 채널 ASSIGNMENT을 사용하십시오.__CAPGO_KEEP_1__
- 모니터링: 각 채널별로 기능 사용률과 성능 지표를 추적합니다.
- 점진적인 롤아웃: 작은 사용자 세그먼트부터 시작하여 점진적으로 확장합니다.
- 명확한 문서화: 채널 전략과 목적을 문서화합니다.
결론
By leveraging Capgo’s channel system, you can create more personalized app experiences and run A/B tests. For production use, always prefer the backend assignment method for better security and control.
채널 관리에 대한 자세한 내용은 채널 문서.
채널을 사용하여 기능 플래그 및 A/B 테스트를 위한 방법을 사용하는 방법
채널을 사용하는 경우 __CAPGO_KEEP_0__ __CAPGO_KEEP_1__ __CAPGO_KEEP_2__ __CAPGO_KEEP_3__ __CAPGO_KEEP_4__ __CAPGO_KEEP_5__ __CAPGO_KEEP_6__ __CAPGO_KEEP_7__ __CAPGO_KEEP_8__ __CAPGO_KEEP_9__ __CAPGO_KEEP_10__ __CAPGO_KEEP_11__