A/B��������

A/B��������ģ�����ɣ����������������ʵ�����

?? ʵ������
?? ����������
?? �����

Feature Flag����

// A/B��������
const experiment = {
  id: 'checkout-redesign',
  variants: [
    { name: 'control', weight: 50 },
    { name: 'variant-a', weight: 50 }
  ],
  metric: 'conversion_rate',
  traffic: 0.5
};

// �������
function getVariant(userId, experiment) {
  const hash = hashCode(userId + experiment.id);
  const bucket = Math.abs(hash) % 10000;
  const threshold = experiment.traffic * 10000;
  if (bucket >= threshold) return null; // ������ʵ��
  
  let cumulative = 0;
  for (const v of experiment.variants) {
    cumulative += v.weight;
    if (bucket < (cumulative / 100) * threshold) {
      return v.name;
    }
  }
  return 'control';
}

Google Analytics �¼�

// ʵ���ع�
gtag('event', 'experiment_impression', {
  experiment_id: 'checkout-redesign',
  variant_id: 'variant-a'
});

// ת���¼�
gtag('event', 'purchase', {
  experiment_id: 'checkout-redesign',
  variant_id: 'variant-a',
  value: 99.99
});

LaunchDarkly ʵ��

const variation = client.variationDetail(
  'checkout-redesign',
  { key: user.id },
  'control'
);

// �����ع��¼�
client.track('experiment_exposure', {
  experimentKey: 'checkout-redesign',
  variation: variation.variationIndex
});