isHypothesisActive

Check Test Variant Assignment

The isHypothesisActive() method is the core of the Shoplift JavaScript API. It determines whether the current visitor is assigned to the variant (B) or control (A) group of your A/B test and is used in 90% of all Shoplift implementations.

Method Signature

isHypothesisActive(hypothesisId: string): Promise<boolean>

Parameters

Parameter
Type
Required
Description

hypothesisId

string

Yes

The unique identifier for your test variant from the Shoplift dashboard

Returns

Type
Description

Promise<boolean>

Resolves to true if the visitor is in the variant (B), false if in control (A)

Basic Usage

// Simple A/B test
const isVariant = await window.shoplift.isHypothesisActive('aa800953-3e22-4335-a53b-50f61db17538');

if (isVariant) {
  // Visitor sees variant (B)
  showVariantExperience();
} else {
  // Visitor sees control (A)
  showControlExperience();
}

How It Works

The behavior of isHypothesisActive() depends on your test configuration:

Automatic Trigger Tests

For tests with automatic triggers, visitors are assigned immediately on page load:

  1. Page loads → Visitor automatically assigned to A or B

  2. Your code calls isHypothesisActive() → Returns existing assignment

  3. Assignment is already tracked in analytics

Manual Trigger Tests

For tests with manual triggers, visitors are only assigned on the first call:

  1. Page loads → No assignment yet

  2. First isHypothesisActive() call → Assigns visitor to A or B and returns result

  3. Subsequent calls → Return cached assignment

Return Value Scenarios

The method returns true when:

  • Visitor is assigned to the variant (B)

  • URL parameter forces this hypothesis (?slVariant=hypothesis-id)

  • URL parameter forces all variants (?slVariant=true)

The method returns false when:

  • Visitor is assigned to control (A)

  • Test is inactive or paused

  • Visitor doesn't meet targeting criteria

  • Hypothesis ID is invalid or not found

  • An error occurs (fails safe to control)

Last updated

Was this helpful?