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
hypothesisId
string
Yes
The unique identifier for your test variant from the Shoplift dashboard
Returns
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:
Page loads → Visitor automatically assigned to A or B
Your code calls isHypothesisActive() → Returns existing assignment
Assignment is already tracked in analytics
Manual Trigger Tests
For tests with manual triggers, visitors are only assigned on the first call:
Page loads → No assignment yet
First isHypothesisActive() call → Assigns visitor to A or B and returns result
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?