FabricFabricExperiments
Reference

Web adapters

Pluggable exposure adapters for Snowplow, GA4, and GTM dataLayer.

@fabricorg/experiments-web-adapters is a tiny add-on (1.86 KB ESM) that provides ready-made onExposure handlers for common tracking systems. Use when you want exposures to land in your existing analytics pipeline without writing boilerplate.

Install

pnpm add @fabricorg/experiments-web @fabricorg/experiments-web-adapters

Adapters

snowplowAdapter(options?)

Sends self-describing exposure events to a Snowplow tracker.

import { createClient } from '@fabricorg/experiments-web';
import { snowplowAdapter } from '@fabricorg/experiments-web-adapters';

const client = createClient(manifest, {
  manifestUrl,
  subjectId,
  onExposure: snowplowAdapter({
    schema: 'iglu:io.fabric.experiments/exposure/jsonschema/1-0-0',
  }),
});

By default looks up globalThis.snowplow. Pass tracker to inject a specific tracker function.

gaAdapter(options?)

Sends a GA4 event via gtag.

import { gaAdapter } from '@fabricorg/experiments-web-adapters';

const client = createClient(manifest, {
  ...,
  onExposure: gaAdapter({ eventName: 'experiment_exposure' }),
});

dataLayerAdapter(options?)

Pushes a fx_exposure event to window.dataLayer for GTM tags.

This is the default adapter wired up by the tag-loader bootstrap, so you only need to import this directly if you're using the programmatic SDK.

import { dataLayerAdapter } from '@fabricorg/experiments-web-adapters';
const onExposure = dataLayerAdapter();

compose(...adapters)

Fan out a single exposure to multiple adapters with per-adapter try/catch isolation — one tracker error never breaks the chain:

import { compose, snowplowAdapter, gaAdapter } from '@fabricorg/experiments-web-adapters';

const onExposure = compose(snowplowAdapter(), gaAdapter());

DataLayer event shape

FieldValue
eventfx_exposure
fx_experiment_idexperiment id
fx_variant_keyassigned variant key
fx_subject_idsubject id used for assignment
fx_manifest_versionmanifest version that produced the assignment

On this page