Docs

Getting Values

Retrieve split test assignments by type

Last updated:

Test Types

Split tests come in three types. The get() method returns a different shape depending on the test type configured in the dashboard.

ID Tests (component branching)

Returns the variation key as a string. Use this when different variations map to different code paths or components.

typescript
const checkout = SplitTesting.get('checkout-flow', 'control');

if (checkout === 'single-page') {
  renderSinglePageCheckout();
} else {
  renderDefaultCheckout();
}

Text Tests (copy testing)

Returns the variation text directly. Use this for headline, CTA, or copy experiments where the only difference is wording.

typescript
const headline = SplitTesting.get('hero-headline', 'Welcome to Acme');
document.getElementById('hero').textContent = headline;

JSON Tests (structured data)

Returns a parsed JSON object. Use this when variations need multiple values (layout config, theme settings, pricing tiers).

typescript
const layout = SplitTesting.get('pricing-layout', { columns: 3, showToggle: true });

renderPricingPage(layout.columns, layout.showToggle);

Default Values

The second argument to get() is the default value. It is returned when:

  • The test does not exist
  • The visitor is not included in the test’s traffic allocation
  • The SDK has not been initialized yet
  • The SDK is in the no-session state (consent not granted, or withdrawn)

Always provide a sensible default so your UI works even if the SDK fails to load or the visitor hasn’t granted consent yet.

Variant allocation hashes the visitor’s persistent ID against the test salt, so the same visitor always buckets to the same variation. The hash bucket survives a setConsent(false)setConsent(true) cycle: returning users see the same variant on both sides of the gap.

Exposures are session-scoped. The audit record sent to the server carries sessionId, not visitorId. When there’s no active session cookie (ss_sid), get() returns the default value and no exposure is recorded; your control path runs in place of the variant until the user’s session opens.

Exposure Tracking

Exposures are tracked automatically. Each call to get() for an active test fires an exposure event (deduplicated per test per session). These exposures power the results dashboard, so you only need to call get() where the user actually sees the variation.

Tracking conversions

The Split Testing SDK doesn’t expose its own conversion API. Track conversions with the Goals SDK instead. Goal fires on a session that’s been exposed to a test are automatically attributed to the assigned variation in the results dashboard.

Refreshing

To fetch fresh test configuration from the server:

typescript
// Force a fresh fetch from the server
await SplitTesting.refresh();

// Assignments are now updated
const variant = SplitTesting.get('checkout-flow', 'control');

This is useful if your app is long-lived (single-page apps, dashboards) and you want to pick up new tests or changed traffic allocations without a full page reload.

Reading All Assignments

typescript
const assignments = SplitTesting.getAssignments();
// { 'checkout-flow': 0, 'hero-headline': 1, 'pricing-layout': 0 }

Returns a map of test keys to variation indexes. This is primarily useful for SSR bootstrap.

Updating Attributes

typescript
// Set attributes after init (e.g., after login)
SplitTesting.setAttributes({ plan: 'pro', country: 'US' });

Attributes are sent with exposure and conversion events for server-side targeting. Calling setAttributes merges into the existing attributes.