Skip to main content
userTourKit
@tour-kit/coreHooks

useSegmentationContext

Low-level hook returning the raw SegmentationContextValue — registered segments, userContext, and currentUserId. Use useSegment / useSegments for typical lookups.

domidex01Published

Direct access to the raw SegmentationContextValue. Most consumers should reach for useSegment (single segment) or useSegments (bulk read) — this hook is the escape hatch for custom integrations, headless filters, and debug panels.

Usage

import { useSegmentationContext } from '@tour-kit/core';

function SegmentDebugPanel() {
  const { segments, userContext, currentUserId } = useSegmentationContext();
  return (
    <aside>
      <p>User: {currentUserId ?? 'anonymous'}</p>
      <p>Registered segments: {Object.keys(segments).join(', ')}</p>
      <pre>{JSON.stringify(userContext, null, 2)}</pre>
    </aside>
  );
}

useSegmentationContext never throws — when no <SegmentationProvider> is mounted it returns the default context (segments: {}, userContext: undefined, currentUserId: undefined). Anonymous-user code paths stay stable.

Return Value

FieldTypeDescription
segmentsRecord<string, SegmentSource>Registered segments. Each value is either a SegmentDefinition (condition array, AND-joined) or a StaticSegment (user-id roster).
userContextRecord<string, unknown> | undefinedAudience targeting context — same shape used by useResolvedText for interpolation.
currentUserIdstring | undefinedResolved against StaticSegment.userIds; required for static-cohort lookups.

Internal use

Tour Kit packages call useSegmentationContext to thread userContext into useResolvedText and useResolveLocalizedText, so consumer-authored 'Hi {{user.name}}' templates interpolate against the same data driving audience matching.

For typical segment membership checks, prefer useSegment — it returns a boolean and tracks segment registration changes. Use useSegmentationContext only when you need the whole context (debug UIs, custom filters, headless integrations).

Free & open source

Ship onboarding, not config.

npm i @tour-kit/core is MIT and free. The Pro packages work unlicensed too — a one-time $99 license removes the production watermark when you ship.

MIT-licensed — no signup, no credit card. Pay once, only when you ship.