Variations และ Assignment
GrowthBook กำหนด variation ให้ผู้ใช้อย่างไร
หัวข้อที่มีชื่อว่า “GrowthBook กำหนด variation ให้ผู้ใช้อย่างไร”เมื่อ GrowthBook รัน experiment จะต้องแบ่งผู้ใช้ออกเป็น variation ต่างๆ อย่างสม่ำเสมอ โดยใช้กระบวนการ deterministic hashing ที่ขับเคลื่อนด้วยค่าคอนฟิกสองตัว ได้แก่ hashAttribute และ traffic coverage/split
hashAttribute คืออะไร
หัวข้อที่มีชื่อว่า “hashAttribute คืออะไร”hashAttribute คือ property ของผู้ใช้ที่ GrowthBook นำไปเป็น input ให้กับ hash function โดยทั่วไปจะเป็น identifier ที่มีความคงที่ เช่น user ID หรือ device ID GrowthBook อ่านค่านี้จาก object attributes ที่คุณส่งเข้าไปใน SDK
const gb = new GrowthBook({ apiHost: 'https://cdn.growthbook.io', clientKey: 'sdk-YOUR_KEY', attributes: { id: 'user-123', // ค่า hashAttribute country: 'TH', },});เมื่อ SDK ประเมิน experiment จะนำ hashAttribute + experiment.key มา hash รวมกันเพื่อให้ได้ตัวเลขระหว่าง 0 ถึง 1 ซึ่งตัวเลขนี้จะเป็นตัวกำหนดว่าผู้ใช้จะเห็น variation ไหน
Deterministic hashing คืออะไร
หัวข้อที่มีชื่อว่า “Deterministic hashing คืออะไร”GrowthBook ใช้อัลกอริทึม Fowler–Noll–Vo (FNV) hash เมื่อ input string เหมือนกัน hash จะให้ผลลัพธ์เหมือนกันเสมอ ดังนั้นผู้ใช้ที่ได้รับ assignment เป็น variation B จะเห็น variation B เสมอ ไม่ว่าจะโหลดหน้าใหม่กี่ครั้ง ใช้กี่ session หรือกี่ device ตราบใดที่ id ยังเหมือนเดิม
Traffic coverage และ split
หัวข้อที่มีชื่อว่า “Traffic coverage และ split”การกระจาย traffic ควบคุมด้วยการตั้งค่าสองอย่าง:
| การตั้งค่า | สิ่งที่ควบคุม |
|---|---|
| Coverage | เปอร์เซ็นต์ของผู้ใช้ที่เข้าร่วม experiment (0–100%) ผู้ใช้ที่อยู่นอก coverage จะได้รับค่า control |
| Split | วิธีแบ่ง traffic ที่เข้าร่วมออกเป็น variation ต่างๆ (เช่น 50/50 หรือ 33/33/34) โดย split ทั้งหมดต้องรวมกันได้ 100% |
ผู้ใช้ที่มีค่า hash ต่ำกว่า threshold ของ coverage จะถูกนำเข้า experiment และ variation ที่แน่นอนจะถูกกำหนดจากตำแหน่งที่ hash ตกอยู่ใน split ranges
Assignment ที่สม่ำเสมอ
หัวข้อที่มีชื่อว่า “Assignment ที่สม่ำเสมอ”เพราะ hash คำนวณจาก input ที่มีความคงที่ (ค่า attribute และ experiment key) assignment จึงสม่ำเสมออย่างสมบูรณ์:
- ผู้ใช้คนเดิมจะเห็น variation เดิมเสมอสำหรับ experiment เดียวกัน
- การรีเฟรชหน้าหรือ reinitialise SDK ไม่ทำให้ assignment เปลี่ยนแปลง
- คุณ cache หรือ server-side render ผลลัพธ์ของ experiment ได้อย่างปลอดภัยโดยไม่ต้องประสานงานเพิ่มเติม
ติดตาม exposure ด้วย trackingCallback
หัวข้อที่มีชื่อว่า “ติดตาม exposure ด้วย trackingCallback”การรู้ว่าผู้ใช้เห็น variation ไหนเป็นสิ่งจำเป็นสำหรับการคำนวณการเปลี่ยนแปลงของ metric GrowthBook ไม่ส่ง analytics event โดยอัตโนมัติ — คุณต้องเชื่อมต่อ trackingCallback ที่จะ fire ทุกครั้งที่ผู้ใช้ได้รับ assignment ให้กับ variation ของ experiment
callback รับ argument สองตัว:
experiment— คำนิยาม experiment (รวมถึงexperiment.key)result— ผลลัพธ์ของ assignment (รวมถึงresult.variationIdและresult.value)
import { GrowthBook } from '@growthbook/growthbook';
const gb = new GrowthBook({
apiHost: 'https://cdn.growthbook.io',
clientKey: 'sdk-YOUR_KEY',
trackingCallback: (experiment, result) => {
// Send exposure event to your analytics
analytics.track('Experiment Viewed', {
experimentId: experiment.key,
variationId: result.variationId,
});
},
});
await gb.init({ timeout: 2000 });ข้อแลกเปลี่ยน
หัวข้อที่มีชื่อว่า “ข้อแลกเปลี่ยน”| ตัวเลือก | Benefit | Cost |
|---|---|---|
| Deterministic hashing | ไม่ต้องเก็บ state ฝั่ง server, scale ง่าย | override เฉพาะ user ยากกว่า |
| เก็บ assignment ไว้ใน database | ควบคุมและ override ได้ง่ายกว่า | ต้องดูแล infrastructure เพิ่ม |
ข้อผิดพลาดที่พบบ่อย
หัวข้อที่มีชื่อว่า “ข้อผิดพลาดที่พบบ่อย”- ใช้ attribute ที่เปลี่ยนได้ (เช่น session ID ใหม่ทุกครั้ง) เป็น hash key ทำให้ user ถูก assign ใหม่ทุกครั้งที่เข้า
- ไม่เข้าใจว่า traffic percentage ที่ตั้งไม่ใช่ “sample size” แต่คือสัดส่วนของ eligible user
- เปลี่ยนสัดส่วน variation กลาง experiment ทำให้ analysis เพี้ยน
💡 ตัวอย่างจากของจริง
GrowthBook และแพลตฟอร์ม experimentation อื่นๆ (เช่นของ Facebook) ใช้ deterministic hash ของ user ID เป็นมาตรฐานอุตสาหกรรมสำหรับ assignment ที่เสถียรและ scale ได้