RevTurbineCustomerSdk
The core RevTurbine customer-facing SDK.
Provides methods for:
- Identity —
identify(),resetIdentity() - Placements —
registerPlacement(),getPlacementDecision(),getPlacement() - Entitlements —
checkEntitlement(),updateUsage() - Trials —
getTrialStatus() - Events —
capture(),trackEvent(),emitSemantic() - Interactions —
trackTreatmentInteraction(),dismiss(),convert() - Context —
setUserContext(),setPageContext(),refreshPageContext()
Example
Section titled “Example”const sdk = initRevTurbine({ tenantId: 'tenant_abc', apiKey: 'rt_live_xxx', endpoint: 'https://api.revturbine.io', mode: 'react',});
sdk.identify('user_123', { plan: 'pro' });const decision = await sdk.getPlacementDecision({ placementId, userId: 'user_123' });Methods
Section titled “Methods”can(
handle,context?):Promise<{ }>
Check whether the user can do something — the advertised alias of
checkEntitlement. Returns the rich EntitlementResult
(allowed, status, reason, limits, enforcement). For billing-critical
entitlements, confirm enforcement === 'server_required' on your backend.
Parameters
Section titled “Parameters”handle
Section titled “handle”string
context?
Section titled “context?”RevTurbineEntitlementContext
Returns
Section titled “Returns”Promise<{ }>
Example
Section titled “Example”const access = await rt.can('generate_image');if (!access.allowed) showUpgrade();dispose()
Section titled “dispose()”dispose():
void
Stop background clickstream flushing and release page-unload listeners. Flushes any buffered events one last time. Call when tearing down an SDK instance (e.g. SPA unmount) to avoid a dangling interval/listeners.
Returns
Section titled “Returns”void
emitTrigger()
Section titled “emitTrigger()”emitTrigger(
trigger,payload?,options?):Promise<void>
Emit a canonical trigger event recognised by the decision engine.
Convenience wrapper over emitSemantic that constrains the event name to RevTurbineTriggerEvent and attaches standard context (user_id, plan, timestamp) automatically.
Parameters
Section titled “Parameters”trigger
Section titled “trigger”"trial_midpoint" | "trial_expiring" | "trial_expired" | "usage_limit_approaching" | "usage_limit_reached" | "credit_balance_low" | "seat_limit_reached" | "feature_gated" | "cancel_intent" | "payment_failed" | "auto_renewal_reminder" | "onboarding_complete" | "invite_teammate_prompt" | "referral_offer" | "plan_upgrade_nudge"
payload?
Section titled “payload?”options?
Section titled “options?”RevTurbineEventOptions
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”await sdk.emitTrigger('usage_limit_approaching', { usage_percent: 85, threshold: 80 });await sdk.emitTrigger('trial_expiring', { days_remaining: 2 });await sdk.emitTrigger('feature_gated', { feature: 'advanced_automation' });explainPlacementDecision()
Section titled “explainPlacementDecision()”explainPlacementDecision(
input):Promise<RevTurbinePlacementDecisionExplanation>
Explain why a placement decision was selected.
Returns a structured diagnostic payload that includes:
- Segment membership evaluation with predicate-level pass/fail details
- Entitlement-rule matching outcomes for current targeting context
- Placement decision metadata (
rule_id, reason codes, suppression)
Useful for debuggers, QA tooling, and customer-facing explainability UIs.
Parameters
Section titled “Parameters”RevTurbinePlacementDecisionInput
Returns
Section titled “Returns”Promise<RevTurbinePlacementDecisionExplanation>
fetchUserContext()
Section titled “fetchUserContext()”fetchUserContext(
userId):Promise<UserTargetingContext>
Fetch the resolved user context from the decision API. Returns the user’s matched segments, traits, plan, and usage — used to determine which placement payloads are eligible for display.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<UserTargetingContext>
flushEvents()
Section titled “flushEvents()”flushEvents():
Promise<void>
Flush any buffered clickstream events to POST /api/track immediately.
Called on the size threshold, the RevTurbineEventBatchingOptions interval timer, and page-unload. Best-effort and non-throwing — delivery failures are swallowed (plan 95 REQ-3). Safe to call when the buffer is empty (no-op).
Returns
Section titled “Returns”Promise<void>
gate()
Section titled “gate()”gate<
T>(action,fn,context?):Promise<RevTurbineGateResult<T>>
Gate an action behind an entitlement — the advertised gate(action, fn) verb.
Checks the entitlement for action; if allowed, runs fn and returns its
result; otherwise does NOT run fn and returns the entitlement so the caller
can surface a paywall (e.g. render an <RTSlot>). See RevTurbineGateResult.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”action
Section titled “action”string
() => T | Promise<T>
context?
Section titled “context?”RevTurbineEntitlementContext
Returns
Section titled “Returns”Promise<RevTurbineGateResult<T>>
Example
Section titled “Example”const gated = await rt.gate('export_pdf', () => exportPdf());if (!gated.ran) openPaywall(gated.entitlement);getEntitlements()
Section titled “getEntitlements()”getEntitlements():
Record<string,EntitlementResult>
Return the SDK-resolved entitlement snapshot for the active user.
The returned object is keyed by entitlement handle and reflects the latest results from local/runtime checks tracked by the SDK.
Returns
Section titled “Returns”Record<string, EntitlementResult>
getExportedConfig()
Section titled “getExportedConfig()”getExportedConfig(): { } |
undefined
Returns the RevTurbineConfig snapshot loaded at initialization, if any.
Available only in local_only mode when exportedConfig was provided.
Returns
Section titled “Returns”{ } | undefined
getPersonalizationTokens()
Section titled “getPersonalizationTokens()”getPersonalizationTokens(
payload?):RevTurbinePersonalizationTokens
Return the SDK-resolved personalization token map.
Reads from the transient personalization map on the user context,
which holds both SDK-derived tokens (plan_name, usage_current, etc.)
and app-provided tokens set via setPersonalization() or identify().
Pass the placement’s payload (its recommendation_strategy /
recommendation_plan_override fields) to resolve the
{{recommended_plan_handle}} / {{recommended_plan_name}} tokens for
that specific placement (plan #47, Appendix C.3). Without a payload the
map carries the user-level next_tier_up default; with one, the
placement’s authored strategy (e.g. a custom forced plan) overlays
those two tokens. All other tokens are unaffected.
Parameters
Section titled “Parameters”payload?
Section titled “payload?”Optional placement payload carrying the per-placement recommendation strategy. Omit for the user-level default.
recommendation_plan_override?
Section titled “recommendation_plan_override?”string | null
recommendation_strategy?
Section titled “recommendation_strategy?”RecommendationStrategy | null
Returns
Section titled “Returns”RevTurbinePersonalizationTokens
getPolicy()
Section titled “getPolicy()”getPolicy():
RevTurbinePolicySnapshot
Return current SDK policy snapshot.
Returns
Section titled “Returns”getTargeting()
Section titled “getTargeting()”getTargeting():
RevTurbineTargeting
Return the SDK-resolved targeting snapshot for the active user.
Includes user id, segment ids, traits, plan, and merged usage so demo surfaces can display the same context used by placement eligibility.
Returns
Section titled “Returns”getUsage()
Section titled “getUsage()”getUsage():
RevTurbineUsageSnapshot
Return the SDK-resolved usage snapshot for the active user.
Keys are usage units (derived from configured usage token prefixes when available), and values include current usage plus optional limit when known.
Returns
Section titled “Returns”getUserContext()
Section titled “getUserContext()”getUserContext():
object
Build the full persistence-ready UserContext from the current
SDK state. Includes tenant_id and user_id required for API storage.
Returns
Section titled “Returns”object
hydrate()
Section titled “hydrate()”hydrate(
payload):void
Hydrate the SDK with a server-evaluated payload.
Call this on the client after receiving a ServerEvaluationPayload
from the server-side SDK. Pre-populates the decision cache,
entitlements, trial status, and user context so the client SDK
avoids redundant API calls.
Parameters
Section titled “Parameters”payload
Section titled “payload”Returns
Section titled “Returns”void
Example
Section titled “Example”// In your React component / page hydration:const sdk = initRevTurbine({ tenantId, apiKey, endpoint, mode: 'react' });sdk.hydrate(serverPayload);recordClickThru()
Section titled “recordClickThru()”recordClickThru(
placementId,payloadId?,surfaceTemplateId?,metadata?):Promise<void>
Record a placement click-through — the user engaged with the CTA. The placement is permanently retired for this user.
Parameters
Section titled “Parameters”placementId
Section titled “placementId”string
The placement’s stable rule_id.
payloadId?
Section titled “payloadId?”string
Optional payload variant id.
surfaceTemplateId?
Section titled “surfaceTemplateId?”string
Optional surface template id.
metadata?
Section titled “metadata?”Optional metadata persisted with the record.
Returns
Section titled “Returns”Promise<void>
recordDismissal()
Section titled “recordDismissal()”recordDismissal(
placementId,payloadId?,surfaceTemplateId?,metadata?):Promise<void>
Record a placement dismissal — the user explicitly closed it.
The placement is permanently retired for this user; subsequent
getPlacementDecision calls return visible: false.
Parameters
Section titled “Parameters”placementId
Section titled “placementId”string
The placement’s stable rule_id.
payloadId?
Section titled “payloadId?”string
Optional payload variant id.
surfaceTemplateId?
Section titled “surfaceTemplateId?”string
Optional surface template id.
metadata?
Section titled “metadata?”Optional metadata persisted with the record.
Returns
Section titled “Returns”Promise<void>
recordImpression()
Section titled “recordImpression()”recordImpression(
placementId,payloadId?,surfaceTemplateId?,metadata?):Promise<void>
Record that a placement was rendered to the user. Plan 43 TASK-9.
Writes an impressed record to the SDK’s ImpressionHistory,
which persists to localStorage via StorageImpressionStore
(or in-memory storage in non-browser environments). The
impression contributes to:
- Frequency caps (
cap.v1) — once-per-period limits count this impression against the user’s quota for the placement. - Trial milestone supersession analytics — for trial_progress
ladders, the supersession diagnostic uses delivery state
to distinguish “replaced an undelivered placement” (counts
in
superseded_placement_ids) from “lower threshold was already shown” (NOT counted — spec §3.5 “supersession only applies to undelivered placements”). - Generic milestone supersession (
content.milestone_order) — the order-based variant inapplyContentMilestoneSupersession.
Call this from consumer code when the placement is actually
shown to the user (e.g., from a React component’s useEffect
on mount, or after the rendering call returns). The SDK does
NOT auto-record impressions — surfaces are rendered by consumer
code, so only the consumer knows when a placement was actually
presented (vs. fetched but not displayed).
Safe to call multiple times for the same placement — duplicates append additional impression records (used by frequency caps to count delivery events).
Parameters
Section titled “Parameters”placementId
Section titled “placementId”string
The placement’s stable rule_id (e.g.
'pl_trial_progress_70'). Match decision.output.rule_id
from getPlacementDecision.
payloadId?
Section titled “payloadId?”string
Optional payload variant id, for variant-level analytics.
surfaceTemplateId?
Section titled “surfaceTemplateId?”string
Optional surface template id, for per-surface cap accounting.
metadata?
Section titled “metadata?”Optional metadata persisted with the record.
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”const decision = await sdk.getPlacementDecision({ placementId: 'slot_trial_modal' });if (decision.visible && decision.output?.rule_id) { renderBanner(decision.output); await sdk.recordImpression(decision.output.rule_id, decision.output.output_id);}registerPlacement()
Section titled “registerPlacement()”registerPlacement(
config):Promise<string>
Parameters
Section titled “Parameters”config
Section titled “config”Returns
Section titled “Returns”Promise<string>
reset()
Section titled “reset()”reset():
void
Clear the current user — the advertised alias of resetIdentity (e.g. on sign-out).
Returns
Section titled “Returns”void
resetUserContext()
Section titled “resetUserContext()”resetUserContext():
void
Hard-reset the user context to a blank slate — removes EVERY user-context
value (id, plan, email, account_id, custom, usage,
entitlements, personalization) plus usage balances, and clears the
decision cache, interaction state, and impression history.
Unlike resetIdentity (a sign-out that re-infers anonymous context
when the inferUser policy is on), this performs no inference, so the
resulting context is guaranteed empty. Mostly for demo / fixture flows that
reset cleanly between scenarios.
Returns
Section titled “Returns”void
Example
Section titled “Example”// Between demo personas:rt.resetUserContext();rt.identify('demo_pro', { plan: { id: 'pro', name: 'Pro' } });track()
Section titled “track()”track(
name,data?):Promise<void>
Track an event — the advertised alias of trackEvent. Powers analytics, frequency caps, attribution, and experiments.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”rt.track('ai_generation_completed', { credits: 3 });trackControlPlaneEvent()
Section titled “trackControlPlaneEvent()”trackControlPlaneEvent(
eventType,payload?,options?):Promise<void>
Emit a typed control-plane semantic event (plan 112).
The dogfood-faithful surface for RevTurbine’s own product activity:
eventType is constrained to the canonical ControlPlaneEventType
taxonomy and the system/workflow source classification is stamped
automatically. Forwards through the same ingest + consumer path as
capture — so the event lands in clickstream AND any registered
analytics resolver (e.g. a PostHog provider from
createPostHogAnalyticsProvider).
Identity comes from the active user context set via identify /
setUserContext: the operator is user_id and the acting RevTurbine
customer tenant is account_id. tenant_id is stamped server-side and is
never carried on the event (plan 112 REQ-3/REQ-4).
Parameters
Section titled “Parameters”eventType
Section titled “eventType”"web_signed_up" | "web_signed_in" | "cli_signed_up" | "cli_signed_in" | "cli_command_executed" | "changeset_submitted" | "changeset_approved" | "changeset_rejected" | "changeset_deployed" | "changeset_launched" | "changeset_parked" | "changeset_resumed" | "changeset_discarded" | "changeset_archived" | "config_imported" | "config_exported" | "entity_created" | "entity_updated" | "entity_deleted"
A canonical control-plane event type.
payload?
Section titled “payload?”SdkEventProperties = {}
Optional event-specific properties (e.g. { resource, resource_id }).
options?
Section titled “options?”RevTurbineEventOptions
Emit options, e.g. { immediate: true } to bypass batching.
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”sdk.identify('operator_42', { account_id: 'tn_acme' });await sdk.trackControlPlaneEvent('changeset_deployed', { change_set_id: 'cs_9' });update()
Section titled “update()”update(
patch):void
Patch customer-reported usage — the advertised update({ usage }) verb,
delegating to updateUsage. For identity or full user-context changes
use identify / setUserContext.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Example
Section titled “Example”rt.update({ usage: { generations: 25 } });validateUiPathResolvers()
Section titled “validateUiPathResolvers()”validateUiPathResolvers(
options?):Promise<RevTurbineUiPathResolverValidationReport>
Validate that each configured UI path action has a resolver implementation.
By default this validates localRuntime.exportedConfig.content_ui_paths (when present)
against:
uiPathResolverspassed at SDK init- optional
resolverspassed to this method - CTA handlers from domain providers (
domain: 'cta'), unless disabled
Parameters
Section titled “Parameters”options?
Section titled “options?”RevTurbineUiPathResolverValidationOptions = {}
Returns
Section titled “Returns”Promise<RevTurbineUiPathResolverValidationReport>