기능 플래그 및 A/B 테스트를 위한 채널 사용 방법
Capgo의 채널 시스템은 사용자를 구분하고 기능 접근을 제어하는 유연한 방법을 제공합니다. Capgo은 내장된 계획 관리 또는 A/B 테스트를 지원하지 않지만, 채널 할당 관리를 통해 이러한 기능을 implement할 수 있습니다.
채널 이해
Capgo 채널은 다음과 같은 기능을 제공합니다:
- 다양한 기능으로 특정 사용자 그룹을 대상으로 하세요
- 사용자를 다른 채널에 할당하여 A/B 테스트를 수행하세요
- 새로운 기능을 점진적으로 출시하세요
- 베타 테스트 프로그램을 생성하세요
채널 할당 방법
1. 백엔드 할당 (권장)
이 방법은 더 안전합니다. 다음 단계를 수행합니다:
- __CAPGO_KEEP_0__에서 장치 ID를 가져옵니다
- __CAPGO_KEEP_0__으로 장치 ID를 전송합니다
- Your backend calls the Capgo API to assign the device
이 방법을 구현하는 방법은 다음과 같습니다:
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)
}
백엔드 구현
당신의 백엔드가 해야 할 일은:
- Capgo 대시보드에서 API 키를 가져와야 합니다.
- Capgo API을 호출하여 장치를 채널에 할당해야 합니다.
API 키를 얻으려면:
- Capgo 대시보드에 로그인하세요.
- 설정 > API 키로 이동하세요.
- 새 키를 생성하기 위해 'Generate New Key' 버튼을 클릭하세요.
- 선택
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
}
}
백엔드도 다음을 수행해야 합니다:
- 사용자의 권한을 검증합니다.
- 채널 assignments를 모두 로그합니다.
- 속도 제한을 처리합니다.
- 실패한 assignments에 대한 재시도 로직을 구현합니다.
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__ 대시보드
- In 채널 설정에서 '기기 자체 연결 허용' 옵션을 활성화하세요.
- 변경 사항을 저장하세요.
이 설정이 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
}
백엔드 ASSIGNMENT 사용
- : 프로덕션 환경에서는 백엔드 ASSIGNMENT 방법을 항상 사용하세요.일관된 ASSIGNMENT
- __CAPGO_KEEP_0__: 사용자 ID 또는 다른 안정적인 식별자로 일관된 채널 할당을 위해 사용하십시오.
- 모니터링: 각 채널의 기능 사용률 및 성능 지표를 추적하십시오.
- 격차 롤아웃: 작은 사용자 세그먼트부터 시작하여 점진적으로 확장하십시오.
- 명확한 문서화: 채널 전략 및 목적을 문서화하십시오.
결론
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.
채널 관리에 대한 자세한 내용은 channels 문서를 참조하십시오..