Personalization and testing with the Svelte SDK
Developer preview
Personalization and A/B testing are configured in the Uniform dashboard and evaluated automatically by the SDK. When UniformSlot encounters a personalization or test container in the composition tree, it renders the appropriate Personalize or Test component from @uniformdev/context-svelte.
How personalization works#
- The personalization manifest is downloaded locally (see Manifest management) and passed to the Context in the root layout.
- The
UniformContextprovider creates aContextinstance and makes it available to the entire component tree. - When
UniformSlotencounters a personalization container, it evaluates the visitor's scores against the variant criteria and renders the winning variant(s). - Score updates happen through enrichment tracking (
Trackcomponent) and route-based signals.
Output types#
The outputType prop on UniformContext controls how variants are rendered:
standard(default): Evaluates personalization during SSR or on the client. Only the winning variant HTML is included. Best for development and most deployments.edge: Outputs all variants as NESI placeholders. An edge middleware selects the winning variant before the response reaches the browser. Best for production with edge personalization (see Edge personalization).
Change outputType to edge only when the NESI hook is in place.
Edge personalization#
outputType="edge" writes every personalization and test variant into the HTML as NESI placeholders. A hook in src/hooks.server.ts reads that HTML and keeps the visitor's variant. The hook runs in vite dev and in production.
@uniformdev/context-edge and @uniformdev/context-edge-sveltekit are private packages. To install them, you need an npm access token from Uniform. If you don't have an access token, request one from Uniform Support.
Add an .npmrc file to the project root that reads the token from NPM_TOKEN:
Set NPM_TOKEN to your token and install the edge packages:
Set the output type on UniformContext:
Add the NESI hook after createUniformHandle. Skip responses that are not HTML. __data.json, API routes, and assets do not contain placeholders.