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

Targeting Attributes

Targeting attribute คือคู่ key-value ที่อธิบายผู้ใช้หรือ session คนปัจจุบัน เช่น id, email, country, หรือ plan เมื่อ SDK ประเมิน flag GrowthBook จะเปรียบเทียบ attribute ของผู้ใช้คนปัจจุบันกับ condition บนแต่ละ rule เพื่อตัดสินว่า rule ใด (ถ้ามี) จะถูกนำมาใช้

attribute ถูกกำหนดโดยคุณทั้งหมด GrowthBook ไม่มีโมเดลผู้ใช้ในตัว คุณเป็นคนบอกว่าจะให้ GrowthBook รู้อะไรเกี่ยวกับผู้ใช้แต่ละคนผ่านการเรียก setAttributes

ก่อนที่ SDK จะ match บน attribute ได้ GrowthBook ต้องรู้ว่ามี attribute นี้อยู่และเก็บข้อมูลประเภทใด

  1. ในแถบ sidebar ของ GrowthBook คลิก Settings → Attributes
  2. คลิก Add Attribute
  3. ใส่ Attribute name (เช่น country)
  4. เลือก Data Typestring, number, boolean, secureString, หรือ string[]
  5. ติ๊ก Identifier หาก attribute นี้ระบุตัวผู้ใช้ได้อย่างไม่ซ้ำกัน (ใช้เป็น hash key สำหรับการแบ่ง bucket ใน experiment และ percentage rollout)
  6. คลิก Save

ทำซ้ำสำหรับทุก attribute ที่ rule ของคุณจะอ้างอิงถึง

เรียก 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 (เช่น 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

ตัวเลือกBenefitCost
ส่ง 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

จุดประสงค์ของการเรียก `gb.setAttributes(...)` ใน SDK คืออะไร?
attribute แบบ "Identifier" ใน GrowthBook ถูกใช้ทำอะไร?
คุณกำหนด attribute ที่ rule ของ GrowthBook สามารถเจาะกลุ่มได้ที่ไหน?