Skip to content

Preview an outcome on your site

An outcome preview opens your site in your own browser, answered from the staged preview, with one feature pinned to one row’s outcome. Use it to see what your pages render for that outcome: the panel, the offer, the redirect. It does not tell you whether a user reaches the row; Try it with Preview in the builder does that.

Only the browser that opened the link gets the preview. Every other request to your site is answered from the deployed document.

In Revenue › Decision Engine › Features, open a feature. Each rule, else and on error has an eye to the left of its … menu.

  1. Save your changes. The eye is disabled while the builder has unsaved changes.
  2. Select the eye on the row whose outcome you want to see. If the feature runs on more than one site, pick the site.
  3. The console stages the saved draft and opens the site’s domain in a new tab, as https://<domain>/?edgekitPreview=<token>.

The eye needs the Stage permission and is hidden without it. Like Stage the draft, it replaces your organization’s one preview, for everyone. If the gate refuses the draft, nothing is staged and no tab opens: the refusal appears beside the eye and names what failed. See Stage and deploy a change.

The token in the link is good for 30 minutes, on that one site. Until it expires, every decide from that browser on that site:

  • is answered from the staged preview, not the deployed document;
  • answers the pinned feature with the row’s outcome, whoever the user is. The canvas’s entry and the row’s conditions are not read;
  • evaluates every other feature it asks for against the preview, as usual.

The pinned feature counts on no meter and records no exposure. Its meters still show what the user has really read and the allowance their own rules would give, without counting this view. Every other feature counts and records exactly as on any request, on your own device or user.

The decide response says what answered it: preview is true, previewHash names the preview, and pin repeats the pin with matched. See The response.

  • The link shows whatever is staged now. A later stage by anyone, automatic staging included, changes what an open link shows.
  • For about a minute after a stage, some requests can still be answered from the previous preview. The devtools panel says when this happens; reload after a minute.
  • A pin that names no row in the preview is ignored. The rule was deleted, or the preview was staged again without it. matched is false and the feature is evaluated as usual.
  • An expired token, or one for another site, is never an error. Decide answers from the deployed document.

The first page that sees ?edgekitPreview= stores the token in a cookie, edgekit_preview, on your site’s own domain. The preview then follows you from page to page, from an article to its paywall to checkout. The browser client stores it when the page creates a client. The site proxy stores it on every page it sends, including pages it does not ask decide about.

  • It is Secure, SameSite=Lax and Path=/, and not HttpOnly, so the browser client can read it.
  • It expires with the token, at most 30 minutes after the link was made.
  • It covers every tab of that browser on that site, including links you open in a new tab.

A page that neither creates the browser client nor passes through the site proxy does not store the token, and it is lost when you leave that page. Add the same ?edgekitPreview= to the URL of a page that does.

To end the preview early, open any page of the site with ?edgekitPreview=off, or select Clear preview in the devtools panel. Both delete the cookie, and later requests are answered from the deployed document.

The token is a credential for your undeployed configuration on that site. It ends up in browser history, in the page URLs your analytics records and in your servers’ access logs. Share a link only with people who may see undeployed changes.

The link also opens the browser client’s devtools panel in that tab. The panel stays open in that tab until ?edgekitPreview=off, even after the preview ends. Other tabs get the preview without the panel.

At the top of the panel’s Decisions tab:

  • The pin: feature, canvas and row. The row is the rule’s id, (otherwise) for else or (onError) for on error.
  • The time left, counting down. At zero the preview is over and the panel shows production.
  • Clear preview deletes the cookie. Later decides are answered from the deployed document, and the panel stays open.

The panel reads the pin and the time left from the token without checking it. Only decide’s answer says what was served. Under each decide, the panel can show:

Line Meaning
served … · expected … The start of the hash of the preview that answered, and of the one the link was made for
previous preview — reload in a minute The two differ: the newer preview has not reached every location yet, or someone staged again since
pinned row not in the served preview The pin names no row in the preview, so the feature was evaluated as usual
this tenant ignores pins Your organization runs an EdgeKit release older than pins, so the feature was evaluated as usual
token refused: production Decide did not accept the token, because it expired or is for another site, and answered from the deployed document

The panel comes with the browser client, @edgekitcloud/client-browser. A page served through the site proxy alone has no panel, and the preview still applies.

The server client never reads a URL or a cookie. Pass the token from your own incoming request as preview on each decide call (ServerDecideOptions), and keep it across pages with the same cookie:

import { createServerClient } from '@edgekitcloud/client-server';
const edgekit = createServerClient({
baseUrl: 'https://<tenant>.edgekit.ai',
apiKey: process.env.EDGEKIT_API_KEY,
siteId: 'site_example',
});
const ATTRIBUTES = 'Path=/; Secure; SameSite=Lax';
// The token's remaining life in seconds, from its own `exp`; 0 for anything
// that is not a token. Only decide verifies it.
function secondsLeft(token: string) {
if (!/^[\w-]+\.[\w-]+\.[\w-]+$/.test(token)) return 0;
try {
const [, payload = ''] = token.split('.');
const claims = JSON.parse(
atob(payload.replaceAll('-', '+').replaceAll('_', '/')),
);
return Math.floor(claims.exp - Date.now() / 1000) || 0;
} catch {
return 0;
}
}
export async function handle(request: Request, userId?: string) {
const param = new URL(request.url).searchParams.get('edgekitPreview');
const cookie = /(?:^|;\s*)edgekit_preview=([^;]+)/.exec(
request.headers.get('cookie') ?? '',
)?.[1];
const preview = param === 'off' ? undefined : param || cookie;
const results = await edgekit.decide('paywall', { asUser: userId, preview });
const response = renderPage(results); // your own page
if (param === 'off') {
response.headers.append(
'set-cookie',
`edgekit_preview=; Max-Age=0; ${ATTRIBUTES}`,
);
} else if (param) {
const maxAge = secondsLeft(param);
// The cookie expires with the token; an expired one is not stored.
if (maxAge > 0) {
response.headers.append(
'set-cookie',
`edgekit_preview=${param}; Max-Age=${maxAge}; ${ATTRIBUTES}`,
);
}
}
if (preview) response.headers.set('cache-control', 'private, no-store');
return response;
}

A page decided with a preview must never reach a shared cache, so send it with Cache-Control: private, no-store. A value that cannot be sent as a header is dropped. An invalid or expired token is answered from the deployed document, with no error.

Behind the site proxy, you need none of this. The proxy reads ?edgekitPreview= from the page URL, else the cookie, sends the token to decide, stores or deletes the cookie on the page response, and sends that response with Cache-Control: private, no-store.

A journey feature’s redirect is a link to /v1/decide/forward. Following a link sends no header, so decide reads the token from the cookie. The cookie belongs to your site’s domain, so it reaches decide only through /edgekit/ on that same domain. If your pages call a separate tenant host, such as edgekit.example.com, a pinned journey feature redirects as deployed. Decides the browser client sends there still carry the preview, as a header. See Call the tenant host directly.

edgekit.ai