SDK Integration
วิธีที่ SDK ทำงาน
หัวข้อที่มีชื่อว่า “วิธีที่ SDK ทำงาน”GrowthBook SDK ใช้โมเดล fetch-once, evaluate-locally เมื่อแอปของคุณเริ่มทำงาน SDK จะเชื่อมต่อกับ GrowthBook API และดาวน์โหลด JSON bundle ขนาดเล็กที่เรียกว่า feature definitions ซึ่งประกอบด้วย flag, rules และ experiment configurations ทั้งหมดของโปรเจกต์ หลังจากการดึงข้อมูลครั้งแรกนั้น การประเมิน flag ทุกครั้งจะเกิดขึ้นภายในแอปของคุณทั้งหมด โดยไม่มี network round-trip ต่อการเรียกแต่ละครั้ง
นี่คือ flow ตั้งแต่ต้นจนจบ:
- GrowthBook UI — คุณสร้าง flag, กำหนด targeting rules และ publish การเปลี่ยนแปลง
- GrowthBook CDN — จัดเก็บ compiled feature definitions สำหรับแต่ละ SDK key
- SDK
init()— แอปของคุณดึงและ cache definitions เหล่านั้นตอน startup isOn()/getFeatureValue()— การประเมินทุกครั้งอ่านจาก local cache โดยไม่มี network call
สถาปัตยกรรมนี้ทำให้การประเมิน flag รวดเร็ว (ต่ำกว่า millisecond), ทำงานได้แบบ offline หลังจากการดึงข้อมูลครั้งแรก และรองรับปริมาณ request ใด ๆ โดยไม่เพิ่มภาระให้กับ GrowthBook
Platform ที่รองรับ
หัวข้อที่มีชื่อว่า “Platform ที่รองรับ”GrowthBook SDK พร้อมใช้งานสำหรับทุกภาษาและ platform หลัก:
- JavaScript / TypeScript — browser และ Node.js
- React — hooks และ context provider
- React Native — mobile apps
- Go — server-side
- Python — server-side
- Ruby — server-side
- PHP — server-side
- iOS (Swift) — native mobile
- Android (Kotlin) — native mobile
- Flutter — cross-platform mobile
โมดูลนี้ครอบคลุมอะไร
หัวข้อที่มีชื่อว่า “โมดูลนี้ครอบคลุมอะไร”โมดูลนี้ครอบคลุมบทเรียนต่อไปนี้:
| บทเรียน | สิ่งที่คุณจะได้เรียนรู้ |
|---|---|
| JavaScript SDK | การติดตั้ง vanilla SDK, การ initialise, การตั้ง attributes และการประเมิน flag ในทุก JS environment |
| React SDK | GrowthBookProvider, hook useFeatureIsOn และ pattern การใช้ feature flag ใน React components |
| Node.js / Server-side | GrowthBook instances แบบ per-request และการประเมินแบบ safe ฝั่ง server |
| Streaming & Caching | การอัปเดต flag แบบ real-time ด้วย Server-Sent Events และตัวเลือก cache strategy |
การ initialise เบื้องต้น
หัวข้อที่มีชื่อว่า “การ initialise เบื้องต้น”ค่า config ที่จำเป็นสองค่าคือ apiHost (CDN endpoint) และ clientKey (SDK key สำหรับ environment ของคุณ ซึ่งหาได้ใน GrowthBook ที่ SDK Connections)
import { GrowthBook } from '@growthbook/growthbook';
const gb = new GrowthBook({
apiHost: 'https://cdn.growthbook.io',
clientKey: 'sdk-abc123',
});
await gb.init({ timeout: 2000 });
// Definitions are now cached locally — evaluate away
console.log(gb.isOn('my-flag')); // true or false, no network call