ข้ามไปยังเนื้อหา

Variations และ Assignment

เมื่อ GrowthBook รัน experiment จะต้องแบ่งผู้ใช้ออกเป็น variation ต่างๆ อย่างสม่ำเสมอ โดยใช้กระบวนการ deterministic hashing ที่ขับเคลื่อนด้วยค่าคอนฟิกสองตัว ได้แก่ hashAttribute และ traffic coverage/split

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 ไหน

GrowthBook ใช้อัลกอริทึม Fowler–Noll–Vo (FNV) hash เมื่อ input string เหมือนกัน hash จะให้ผลลัพธ์เหมือนกันเสมอ ดังนั้นผู้ใช้ที่ได้รับ assignment เป็น variation B จะเห็น variation B เสมอ ไม่ว่าจะโหลดหน้าใหม่กี่ครั้ง ใช้กี่ session หรือกี่ device ตราบใดที่ id ยังเหมือนเดิม

การกระจาย 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

เพราะ hash คำนวณจาก input ที่มีความคงที่ (ค่า attribute และ experiment key) assignment จึงสม่ำเสมออย่างสมบูรณ์:

  • ผู้ใช้คนเดิมจะเห็น variation เดิมเสมอสำหรับ experiment เดียวกัน
  • การรีเฟรชหน้าหรือ reinitialise SDK ไม่ทำให้ assignment เปลี่ยนแปลง
  • คุณ cache หรือ server-side render ผลลัพธ์ของ experiment ได้อย่างปลอดภัยโดยไม่ต้องประสานงานเพิ่มเติม

การรู้ว่าผู้ใช้เห็น 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 });
ตัวเลือกBenefitCost
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 ได้

hashAttribute ใน GrowthBook ใช้ทำอะไร?
ทำไม variation assignment ใน GrowthBook ถึงเป็น deterministic?
trackingCallback ทำอะไร?