Launch offer for the first 500 accounts: $10K MTR free for 24 months + $100 credit →
    .io

    Experiments & A/B Testing

    See it in the demo — Bayesian A/B experiments (~60s)

    Experiments Are Powered by Feature Flags

    In BillDog, an experiment is a feature flag with two or more variants and a conversion goal. The same evaluation engine that decides whether a flag is ON also assigns a user to a variant, so you reuse one targeting and bucketing model across simple rollouts and full A/B/n tests. The @billdog.io/ab-testing module (ABTest) fetches your assignments at init, serves them from a local cache, and emits exposure events for analysis.

    1. Flag & Experiment Types

    A FeatureFlagDefinition can model four common shapes. All four are evaluated by the same deterministic bucketing function, so behavior is consistent whether you ship a kill-switch or a four-arm experiment:

    • Boolean — flag is simply ON or OFF. getFeatureFlag(key) returns true/false.
    • Percentage rollout — rollout_percentage controls what fraction of users see the flag ON (e.g. 25 → 25% of users).
    • Multivariate — a variants[] array (each with a key and rollout_percentage) splits the ON bucket into named arms such as control / v2 / v3.
    • Targeted — targeting_rules[] gate the flag to a subset of users by attribute. ALL rules must match before bucketing runs.
    {
      "key": "new_paywall_layout",
      "active": true,
      "rollout_percentage": 60,
      "variants": [
        { "key": "control", "rollout_percentage": 30 },
        { "key": "compact", "rollout_percentage": 30 }
      ],
      "targeting_rules": [
        { "attribute": "country", "operator": "equals", "value": "US" }
      ],
      "payload": { "headline": "Upgrade today" }
    }

    2. Reading a Flag or Variant In-App

    The abTest singleton exposes synchronous accessors that read from the cache populated at init. Use getFeatureFlag for a boolean check, getFeatureFlagValue to read the chosen multivariate arm, and getFeatureFlagPayload to pull the variant's config. For goal-oriented experiments, getVariant resolves the assignment and getExperiments lists all active ones.

    import { abTest } from '@billdog.io/ab-testing';
    
    // Boolean: is this flag ON for the current user?
    if (abTest.getFeatureFlag('new_paywall_layout')) {
      showRedesignedPaywall();
    }
    
    // Multivariate: which arm was the user bucketed into?
    const arm = abTest.getFeatureFlagValue('new_paywall_layout');
    // → false (off) | true (on, boolean flag) | 'control' | 'compact'
    
    // Pull the matched variant's payload (variant config or flag-level payload)
    const payload = abTest.getFeatureFlagPayload('new_paywall_layout');
    console.log(payload?.headline); // 'Upgrade today'

    3. Local vs Server Evaluation

    By default the client never decides bucketing itself. At init, ABTest POSTs to /experiment-config with the user_id and attributes; the server returns the resolved experiments and a feature_flags map. The client only reads that result. This keeps every platform — web, iOS, Android — in lockstep and prevents targeting logic from leaking to untrusted clients.

    When enabled in a server context, evaluateFlagLocally runs the identical algorithm on every platform: missing/inactive → false; all targeting_rules must match the attributes; then the rollout gate uses rollout_bucket = murmurhash3("flag:{key}:{userId}") % 100 and the flag is ON iff rollout_bucket < rollout_percentage. Multivariate arms are then picked by an independent hash — murmurhash3("flag-variant:{key}:{userId}") % 100, walked by cumulative rollout_percentage. The variant hash is deliberately separate from the rollout hash so a low rollout percentage can never starve the later arms.

    // In-app client: server decides everything.
    // No localEvaluation — assignments come from /experiment-config.
    abTest.configure({
      apiKey: 'bd_public_test_yourApiKey',
      userId: 'user_9928',
      attributes: { country: 'US', tier: 'premium' },
    });
    
    // Reads the server-resolved verdict from cache.
    const enabled = abTest.getFeatureFlag('new_paywall_layout');

    4. Targeting Rules & Variants

    targeting_rules gate enrollment by user attribute. Each rule has an attribute, an operator (equals, not_equals, contains, gt, lt), and a value. Every rule must match before bucketing runs. Once a user is in, variants divide the ON bucket into arms, and each arm can carry its own payload returned by getFeatureFlagPayload.

    {
      "key": "onboarding_flow_exp",
      "active": true,
      "rollout_percentage": 80,
      "targeting_rules": [
        { "attribute": "tier", "operator": "equals", "value": "premium" },
        { "attribute": "signup_age_days", "operator": "lt", "value": 7 }
      ],
      "variants": [
        { "key": "control", "rollout_percentage": 40 },
        { "key": "guided",  "rollout_percentage": 40 }
      ],
      "payload": { "show_checklist": true }
    }

    5. How Experiments Connect to the Rest of BillDog

    Experiments are not an island — assignments flow into Analytics, Surveys, and Paywalls through the shared EventBus and the same flag-targeting model.

    • Analytics (exposure events) — on assignment, ABTest emits ab_variant_assigned on the EventBus with the experiment_id and variant_id. When BillDog serves the paywall (via the paywall/placement endpoints), the exposure and the purchase are tracked automatically — you do not need to call trackImpression or trackConversion. Call them manually only for custom, client-rendered experiments or non-paywall goals; both POST to /experiment-event. Either way your dashboards compute per-variant lift. Impression and conversion events for BillDog-served paywalls are experiment telemetry and are not counted toward your analytics event usage.
    • Surveys — a survey can be targeted by the same flag/attribute conditions, so you can show an NPS prompt only to a specific experiment arm and correlate sentiment with the variant.
    • Paywalls — read getFeatureFlagValue / getVariant to choose which paywall offering or layout to render, turning a flag into a live pricing/layout experiment.
    import { abTest } from '@billdog.io/ab-testing';
    
    // NOTE: only needed for CUSTOM, client-rendered experiments. When BillDog serves the
    // paywall, the impression and the purchase are tracked automatically server-side —
    // calling these as well would double-count that exposure.
    
    // Log that the user was exposed to the variant (fire-and-forget)
    await abTest.trackImpression('checkout_button_exp');
    
    // Later, when the goal is hit, record the conversion (optionally with value)
    await abTest.trackConversion('checkout_button_exp', 49.99, {
      plan: 'yearly',
    });
    
    // 'ab_variant_assigned' is emitted automatically on the EventBus at init,
    // so Analytics enriches downstream events with the variant the user saw.

    6. Automating the Experiment Lifecycle (Dashboard)

    Everything above is the SDK / read side. The dashboard's Automation panel controls how an experiment is run — from “I decide everything” to “pick and ship the winner for me.” No SDK changes are needed: assignments keep resolving through the same server-authoritative path while the engine adjusts variant traffic underneath.

    Automation mode

    • manual (default) — the engine never touches the experiment; you read results and ship a winner yourself.
    • assisted — the engine computes a candidate winner and runs the kill-switch, but only surfaces them (a suggested winner + safety alerts). Nothing changes without your click.
    • full_auto — the engine ships the winner and deprecates a tanking variant automatically once the gates below are met.

    Winner criteria

    A variant is eligible to win only when it clears both gates: a minimum relative improvementover control (min_improvement, default 5%) and a minimum confidence from the significance test (min_confidence, default 95% → z-test at α = 0.05), on the chosen metric (default conversion_rate).

    Staged rollout & kill-switch

    Rather than jump a winner straight to 100%, the engine ramps it none → 10% → 50% → 100%. Between stages a safety gate must pass — a dwell time must elapse AND each arm needs enough samples (min_sample_per_stage, default 100). At every stage the kill-switch watches for a conversion drop beyond max_conversion_drop (default 15%) vs. control, so a winner that tanks at 10% is rolled back before it reaches everyone. During a rollout the winner gets its stage weight, control gets the remainder, and all other variants get 0.

    Ship the winner (one click)

    In any mode you can promote a variant yourself. Ship winner sets that variant to 100% traffic and — when auto_deprecate_losers is on — drops the losers to 0% and marks them deprecated, then records the winning variant on the experiment. In full_auto the engine calls the same action automatically once the winner clears the criteria and the staged rollout completes.

    Was this page helpful?

    Or rate this page:

    We use cookies and process your data to provide our services. By continuing, you agree to our Terms and Privacy Policy.