Targeting Conditions
Targeting Conditions
หัวข้อที่มีชื่อว่า “Targeting Conditions”targeting condition คือตัวกรองที่ตัดสินว่า rule จะใช้กับผู้ใช้คนไหน แต่ละ rule บน Feature สามารถมี condition ได้ตั้งแต่ศูนย์ตัวขึ้นไป ทุก condition บน rule ต้องเป็นจริง rule นั้นจึงจะ match กับผู้ใช้คนปัจจุบัน หาก condition ใดเป็นเท็จ ผู้ใช้คนนั้นจะไม่ match rule นั้นและ GrowthBook จะไปทำ rule ถัดไป
การเพิ่ม condition ใน GrowthBook UI
หัวข้อที่มีชื่อว่า “การเพิ่ม condition ใน GrowthBook UI”- ในหน้ารายละเอียดของ Feature คลิก Add Rule (หรือคลิกไอคอนรูปดินสอบน rule ที่มีอยู่)
- ในตัวแก้ไข rule คลิก Add Condition
- เลือก Attribute จาก dropdown (เช่น
country) - เลือก Operator (equals, not equals, contains, regex และอื่น ๆ)
- ใส่ Value (เช่น
TH) - คลิก Save Rule
คุณสามารถเพิ่ม condition ได้มากเท่าที่ต้องการ แต่ละ condition ที่เพิ่มเข้ามาจะจำกัด audience ให้แคบลงไปอีก
Condition operators
หัวข้อที่มีชื่อว่า “Condition operators”GrowthBook รองรับ operator หลากหลายเพื่อ match attribute หลายประเภท:
- equals / does not equal — match แบบตรงทั้งหมดบน string, number, หรือ boolean
- contains / does not contain — match substring สำหรับ string
- matches regex — ทดสอบ string กับ regular expression
- is greater than / is less than — การเปรียบเทียบเชิงตัวเลข
- is in list / is not in list — ตรวจสอบว่าค่าปรากฏอยู่ในชุดที่คั่นด้วยจุลภาคหรือไม่
Advanced JSON mode
หัวข้อที่มีชื่อว่า “Advanced JSON mode”สำหรับ power user GrowthBook รองรับ condition JSON แบบ MongoDB-style ที่เป็นรูปแบบเดียวกับที่ engine การประเมินใช้ภายใน คลิก Advanced ในตัวแก้ไข rule เพื่อป้อน JSON ดิบแทนการใช้ visual builder
match ผู้ใช้ที่ country เป็น TH และ plan เป็น pro:
{ "country": "TH", "plan": "pro"}match ผู้ใช้ที่ email ลงท้ายด้วย @company.com:
{ "email": { "$regex": "@company\\.com$" }}ตัวแก้ไขแบบ advanced มีประโยชน์สำหรับนิพจน์ที่ซับซ้อน (เช่น $or, $and, $not แบบซ้อนกัน) ที่ visual builder ไม่ได้เปิดให้ใช้
import { GrowthBook } from '@growthbook/growthbook';
const gb = new GrowthBook({
apiHost: 'https://cdn.growthbook.io',
clientKey: 'sdk-YOUR_DEV_KEY',
});
await gb.init({ timeout: 2000 });
gb.setAttributes({
id: 'user-456',
country: 'TH',
email: '[email protected]',
});
// Returns the feature value if the user matches all conditions on a rule,
// or the default value ('false') if no rule matches.
const isBetaEnabled = gb.getFeatureValue('beta-feature', false);
console.log('beta-feature:', isBetaEnabled);ข้อแลกเปลี่ยน
หัวข้อที่มีชื่อว่า “ข้อแลกเปลี่ยน”| ตัวเลือก | Benefit | Cost |
|---|---|---|
| Targeting condition ซับซ้อน | แม่นยำกว่ามาก | debug ยากกว่าเมื่อผลลัพธ์ไม่ตรงคาด |
| Condition เรียบง่าย | debug ง่ายกว่า | หยาบกว่า ครอบคลุม use case น้อยกว่า |
ข้อผิดพลาดที่พบบ่อย
หัวข้อที่มีชื่อว่า “ข้อผิดพลาดที่พบบ่อย”- เขียน condition ที่ขัดแย้งกันเอง (เช่น country = TH AND country = US) ทำให้ไม่มี user คนไหน match เลย
- ซ้อน condition หลายชั้นจนไม่มีใครในทีมอ่านเข้าใจ
- ไม่เทสต์ condition กับ user จริงก่อนปล่อยใช้งาน
💡 ตัวอย่างจากของจริง
ทีม growth ที่ Booking.com ใช้ targeting condition ผสมกันหลายชั้น (country + device + subscription tier) เพื่อปล่อย feature เฉพาะ segment ที่มีโอกาสได้ผลดีที่สุดก่อน