@cascayd/experiment 0.3.9 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/client.js +14 -2
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -41,7 +41,9 @@ function seededRandom(seed) {
41
41
  return seed / m;
42
42
  }
43
43
  function chooseByWeight(variants, experimentId) {
44
+ console.log('[cascayd-sdk] chooseByWeight called with variants:', variants);
44
45
  const total = variants.reduce((s, v) => s + v.weight, 0);
46
+ console.log('[cascayd-sdk] chooseByWeight total weight:', total);
45
47
  // Create a seed based on current time (milliseconds) and experiment ID
46
48
  // This makes it change over time while being deterministic for the same millisecond
47
49
  const now = Date.now();
@@ -55,19 +57,29 @@ function chooseByWeight(variants, experimentId) {
55
57
  }
56
58
  // Use seeded random instead of Math.random()
57
59
  const r = seededRandom(Math.abs(hash)) * total;
60
+ console.log('[cascayd-sdk] chooseByWeight seed:', seedString, 'hash:', Math.abs(hash), 'random value:', r, 'total:', total);
58
61
  let acc = 0;
59
62
  for (const v of variants) {
60
63
  acc += v.weight;
61
- if (r <= acc)
64
+ console.log('[cascayd-sdk] chooseByWeight checking variant:', v.id, 'weight:', v.weight, 'acc:', acc, 'r <= acc?', r <= acc);
65
+ if (r <= acc) {
66
+ console.log('[cascayd-sdk] chooseByWeight selected:', v.id);
62
67
  return v.id;
68
+ }
63
69
  }
64
- return variants[variants.length - 1]?.id ?? 'control';
70
+ const fallback = variants[variants.length - 1]?.id ?? 'control';
71
+ console.log('[cascayd-sdk] chooseByWeight fallback to:', fallback);
72
+ return fallback;
65
73
  }
66
74
  export async function assignVariant(experimentId) {
67
75
  const baseStatus = await getVariantStatus(experimentId, 'control');
68
76
  const weights = baseStatus.weights || {};
77
+ console.log('[cascayd-sdk] assignVariant weights received:', weights);
78
+ console.log('[cascayd-sdk] assignVariant weights entries:', Object.entries(weights));
69
79
  const variants = Object.entries(weights).map(([id, weight]) => ({ id, weight }));
80
+ console.log('[cascayd-sdk] assignVariant variants array:', variants);
70
81
  let candidate = chooseByWeight(variants.length > 0 ? variants : baseStatusToVariants(baseStatus), experimentId);
82
+ console.log('[cascayd-sdk] assignVariant candidate selected:', candidate);
71
83
  let finalStatus = null;
72
84
  if (candidate) {
73
85
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascayd/experiment",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "description": "A lightweight A/B testing SDK for React applications with server-side analytics integration",
5
5
  "keywords": [
6
6
  "ab-testing",