Runtime API
Reference the Apex SDK runtime functions for initialization, tracking, consent, flags, diagnostics, and assignment state.
Import runtime functions from @drip-apex/sdk, or call the browser globals after the hosted script has loaded. The hosted script exposes window.drip, window.Drip, window.Apex, and window.apexTools compatibility surfaces.
Initialization and state
| Function | Signature | Use |
|---|---|---|
init | (config: InitConfig) => Assignment[] | Initialize the SDK with inline experiments or fetched config. |
reInit | (forceReapply?: boolean) => Assignment[] | Re-evaluate assignments manually, optionally forcing mutations to reapply. |
recheckPrerequisites | () => void | Re-run project prerequisite gates and start or stop analytics if consent or state changed. |
getAssignments | () => Assignment[] | Read current active assignments. |
getExperiments | () => Experiment[] | Read loaded experiment configs. |
getRuntimeTools | () => ApexRuntimeTools | Get the runtime tools object used by custom JS and page triggers. |
getDiagnostics | () => SdkDiagnostics | Read public diagnostics; debug-only fields appear only when debug mode is enabled. |
Tracking
| Function | Signature | Use |
|---|---|---|
track | (type: string, data?: Record<string, unknown>, experimentId?: string, variationId?: string) => void | Send a custom event and trigger matching custom goals. Defaults to the first active assignment when IDs are omitted. |
trackStep | (name: string, data?: Record<string, unknown>) => void | Send a virtual funnel step as funnel_step; dedupes once per session unless data.oncePerSession is false. |
trackGoal | (goalId: string, data?: Record<string, unknown>) => void | Trigger a configured Apex goal by ID for current assignments. |
trackRevenue | (revenue: number, data?: RevenueEventData) => void | Send a revenue goal with goal ID __revenue__ for every active assignment. |
flush | () => Promise<void> | Start analytics if ready and flush queued events. Resolves immediately when no tracker exists. |
ts
import { flush, track, trackGoal, trackRevenue, trackStep } from "@drip-apex/sdk";
track("add_to_cart", { product_id: "example-product", value: 49 });
trackStep("postcode_submitted");
trackGoal("checkout-started");
trackRevenue(119, { orderId: "order-example-1002", currency: "EUR" });
await flush();Consent
| Function | Signature | Use |
|---|---|---|
setConsent | (granted: boolean) => void | Persist consent state, clear storage when denied, and recheck assignment/tracking prerequisites. |
Feature flags
| Function | Signature | Use |
|---|---|---|
evaluateFlag | (flagId: string, context?) => boolean | Return true when the visitor is assigned to a non-control variation. |
evaluateFlagValue | evaluateFlagValue<T>(flagId, fallback?, context?) | Return the assigned variation value, or the fallback when unavailable. |
ts
import { evaluateFlag, evaluateFlagValue } from "@drip-apex/sdk";
const enabled = evaluateFlag("checkout-progress-ui");
const ctaCopy = evaluateFlagValue("checkout-cta-copy", "Continue to checkout");Diagnostics
ts
import { getDiagnostics } from "@drip-apex/sdk";
const diagnostics = getDiagnostics();
console.log({
initialized: diagnostics.initialized,
assignments: diagnostics.assignments,
configSource: diagnostics.configSource,
runtime: diagnostics.runtime
});getDiagnostics() is safe for support tooling because it redacts consent and tracking-block details unless SDK debug mode is enabled.