Code-owned definitions and `.drip.config.ts`
Define experiments and feature flags in TypeScript, then pair them with Apex CLI GitOps push.
The SDK exports helpers for typed, validated code-owned experiment definitions. Use them when experiments live near application code or when feature flags need typed values.
defineExperiment
ts
import { defineExperiment, init } from "@drip-apex/sdk";
const productBadge = defineExperiment({
slug: "product-page-trust-badge",
name: "Product page trust badge",
trafficAllocation: 0.5,
variations: [
{
id: "control",
weight: 0.5,
isControl: true,
mutations: []
},
{
id: "badge",
weight: 0.5,
mutations: [
{
selector: "[data-add-to-cart]",
action: "insertAfter",
html: "<p data-apex-trust-badge>Secure checkout and fast support.</p>"
}
]
}
],
goals: [
{ id: "add-to-cart-click", type: "click", selector: "[data-add-to-cart]" }
]
});
init({
experiments: [productBadge],
endpoint: "https://events.drip-apex.com"
});defineExperiment returns a frozen Experiment object with the slug as the experiment ID. It throws ExperimentDefinitionError when required fields, variation weights, control variation rules, or click goal selectors are invalid.
defineExperiments
ts
import { defineExperiments } from "@drip-apex/sdk";
export const experiments = defineExperiments([
{
slug: "homepage-proof-copy",
name: "Homepage proof copy",
variations: [
{ id: "control", weight: 0.5, isControl: true },
{ id: "proof", weight: 0.5, mutations: [] }
]
},
{
slug: "cart-empty-state",
name: "Cart empty state",
variations: [
{ id: "control", weight: 0.5, isControl: true },
{ id: "helpful-links", weight: 0.5, mutations: [] }
]
}
]);defineFlagExperiment
ts
import { defineFlagExperiment } from "@drip-apex/sdk";
export const progressUiFlag = defineFlagExperiment({
slug: "checkout-progress-ui",
name: "Checkout progress UI",
rolloutPercent: 25,
offValue: false,
onValue: true
});defineFlagExperiment creates a two-variation experiment where control is off and enabled is on. rolloutPercent is clamped between 0 and 100.
.drip.config.ts
Pair code-owned definitions with the CLI when you want GitOps sync into Apex:
ts
import { defineExperiments, defineFlagExperiment } from "@drip-apex/sdk";
export default {
experiments: [
...defineExperiments([
{
slug: "homepage-proof-copy",
name: "Homepage proof copy",
variations: [
{ id: "control", weight: 0.5, isControl: true },
{ id: "proof", weight: 0.5, mutations: [] }
]
}
]),
defineFlagExperiment({
slug: "checkout-progress-ui",
name: "Checkout progress UI",
rolloutPercent: 25
})
]
};Then push with the CLI:
bash
apex push --config ./.drip.config.ts --dry-run
apex push --config ./.drip.config.ts