Targeting Attributes
Targeting Attributes คืออะไร?
หัวข้อที่มีชื่อว่า “Targeting Attributes คืออะไร?”Targeting attribute คือคู่ key-value ที่อธิบายผู้ใช้หรือ session คนปัจจุบัน เช่น id, email, country, หรือ plan เมื่อ SDK ประเมิน flag GrowthBook จะเปรียบเทียบ attribute ของผู้ใช้คนปัจจุบันกับ condition บนแต่ละ rule เพื่อตัดสินว่า rule ใด (ถ้ามี) จะถูกนำมาใช้
attribute ถูกกำหนดโดยคุณทั้งหมด GrowthBook ไม่มีโมเดลผู้ใช้ในตัว คุณเป็นคนบอกว่าจะให้ GrowthBook รู้อะไรเกี่ยวกับผู้ใช้แต่ละคนผ่านการเรียก setAttributes
ขั้นตอนที่ 1 — กำหนด attribute ใน GrowthBook
หัวข้อที่มีชื่อว่า “ขั้นตอนที่ 1 — กำหนด attribute ใน GrowthBook”ก่อนที่ SDK จะ match บน attribute ได้ GrowthBook ต้องรู้ว่ามี attribute นี้อยู่และเก็บข้อมูลประเภทใด
- ในแถบ sidebar ของ GrowthBook คลิก Settings → Attributes
- คลิก Add Attribute
- ใส่ Attribute name (เช่น
country) - เลือก Data Type —
string,number,boolean,secureString, หรือstring[] - ติ๊ก Identifier หาก attribute นี้ระบุตัวผู้ใช้ได้อย่างไม่ซ้ำกัน (ใช้เป็น hash key สำหรับการแบ่ง bucket ใน experiment และ percentage rollout)
- คลิก Save
ทำซ้ำสำหรับทุก attribute ที่ rule ของคุณจะอ้างอิงถึง
ขั้นตอนที่ 2 — ส่ง attribute ให้ SDK
หัวข้อที่มีชื่อว่า “ขั้นตอนที่ 2 — ส่ง attribute ให้ SDK”เรียก setAttributes ก่อนประเมิน flag ใด ๆ GrowthBook จะใช้สิ่งที่ถูกตั้งค่าไว้ ณ เวลาที่ประเมิน ดังนั้นควรเรียกให้เร็วที่สุดเท่าที่จะทำได้ใน lifecycle ของ request หรือ session
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-123', country: 'TH', plan: 'pro',});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-123',
email: '[email protected]',
country: 'TH',
plan: 'pro',
});Identifier กับ attribute ที่ไม่ใช่ identifier
หัวข้อที่มีชื่อว่า “Identifier กับ attribute ที่ไม่ใช่ identifier”Identifier attribute (เช่น id หรือ deviceId) ถูกใช้เป็น hash key เมื่อแบ่ง bucket ผู้ใช้ใน percentage rollout และ A/B test การติ๊กกล่อง Identifier ใน Settings เป็นการบอก GrowthBook ว่า attribute นี้สามารถใช้แบ่ง bucket ได้อย่างเสถียรและเป็นแบบ deterministic ผู้ใช้คนเดิมจะตกลงใน bucket เดิมเสมอ
attribute ที่ไม่ใช่ identifier (เช่น country หรือ plan) ถูกใช้สำหรับการ match targeting condition เท่านั้น ใช้กรองว่า rule จะมีผลกับผู้ใช้คนไหน แต่ไม่ได้ถูกใช้เพื่อกำหนดผู้ใช้ให้กับ variant ของ experiment
ข้อแลกเปลี่ยน
หัวข้อที่มีชื่อว่า “ข้อแลกเปลี่ยน”| ตัวเลือก | Benefit | Cost |
|---|---|---|
| ส่ง attribute ละเอียด | targeting แม่นยำกว่ามาก | เสี่ยง privacy/PII ถ้าส่งข้อมูลที่ไม่จำเป็น |
| ส่ง attribute น้อย เฉพาะที่จำเป็น | ปลอดภัยกว่า | targeting หยาบกว่า |
ข้อผิดพลาดที่พบบ่อย
หัวข้อที่มีชื่อว่า “ข้อผิดพลาดที่พบบ่อย”- ส่ง PII (เช่น email เต็ม) เป็น attribute โดยไม่จำเป็น
- ใช้ attribute ที่เปลี่ยนบ่อย (เช่น timestamp) เป็น targeting key ทำให้ assignment ไม่เสถียร
- ไม่ sync attribute schema ระหว่าง SDK กับที่ตั้งไว้ใน GrowthBook UI
💡 ตัวอย่างจากของจริง
แอป fintech อย่าง Booking.com ส่งเฉพาะ attribute ที่จำเป็นต่อ targeting (เช่น country, plan tier) แทนข้อมูลส่วนตัวเพื่อลดความเสี่ยงด้าน privacy