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

Targeting Conditions

targeting condition คือตัวกรองที่ตัดสินว่า rule จะใช้กับผู้ใช้คนไหน แต่ละ rule บน Feature สามารถมี condition ได้ตั้งแต่ศูนย์ตัวขึ้นไป ทุก condition บน rule ต้องเป็นจริง rule นั้นจึงจะ match กับผู้ใช้คนปัจจุบัน หาก condition ใดเป็นเท็จ ผู้ใช้คนนั้นจะไม่ match rule นั้นและ GrowthBook จะไปทำ rule ถัดไป

  1. ในหน้ารายละเอียดของ Feature คลิก Add Rule (หรือคลิกไอคอนรูปดินสอบน rule ที่มีอยู่)
  2. ในตัวแก้ไข rule คลิก Add Condition
  3. เลือก Attribute จาก dropdown (เช่น country)
  4. เลือก Operator (equals, not equals, contains, regex และอื่น ๆ)
  5. ใส่ Value (เช่น TH)
  6. คลิก Save Rule

คุณสามารถเพิ่ม condition ได้มากเท่าที่ต้องการ แต่ละ condition ที่เพิ่มเข้ามาจะจำกัด audience ให้แคบลงไปอีก

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 — ตรวจสอบว่าค่าปรากฏอยู่ในชุดที่คั่นด้วยจุลภาคหรือไม่

สำหรับ 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);
ตัวเลือกBenefitCost
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 ที่มีโอกาสได้ผลดีที่สุดก่อน

rule หนึ่งมีสอง condition: `country equals TH` และ `plan equals pro` ผู้ใช้คนหนึ่งมี `country: TH` และ `plan: free` rule นี้ match หรือไม่?
ตัวแก้ไข Advanced JSON condition ของ GrowthBook ใช้รูปแบบใด?
ผู้ใช้คนหนึ่งไม่ match condition ใดเลยบน rule หนึ่ง จะเกิดอะไรขึ้นต่อไป?