Kilkaya
Kilkaya reports on each page view using the state your page gives it: whether the page was paywalled, whether the user is a subscriber, whether they are signed in. When EdgeKit decides your pages, that state comes from decide and from the EdgeKit sign-in session, and your page passes it to Kilkaya.
EdgeKit sends Kilkaya nothing itself and holds no Kilkaya key. Everything on this page runs in your page’s own script.
Set k5aMeta before Kilkaya’s script loads
Section titled “Set k5aMeta before Kilkaya’s script loads”Kilkaya reads window.k5aMeta once, when its script starts. A value set after that is not in the page view. So:
- Take the decision that gates the page, and read the session state.
- Write the fields below into
window.k5aMeta. - Then add Kilkaya’s script to the page.
Use the decision your page already has: never call decide again for Kilkaya. Every decide request counts again on a
count meter, so a second call spends a second free read on the same article, and its answer can differ from the
one that opened the page. If your paywall code calls decide in the browser, pass its promise into the recipe, as in
the example. Behind the site proxy, read the proxy’s decision from the page, as in
Behind the site proxy.
The browser client waits 2 seconds for decide, then answers unavailable, so waiting for it holds Kilkaya back for
2 seconds at most. Your k5a:* meta tags, such as k5a:paid and k5a:section, come from your CMS and do not change.
The fields
Section titled “The fields”k5aMeta field |
Set it to |
|---|---|
paywall |
"hard" when the decision’s type is deny, "open" when it is allow |
subscriber |
1 when the decision’s reason is grant, which means they hold access to this page, else 0 |
login |
1 when the session state is authenticated, 0 when it is anonymous |
If your Kilkaya reports already use other values for paywall, keep those. The table uses "hard" and "open".
A user whose reason is upgrade holds a grant, but not one for this page. Send subscriber: 1 for them too if your
Kilkaya reports count every paying user.
Leave a field out when EdgeKit has no answer for it: paywall and subscriber when the decision is unavailable or
unknown, paywall also when the decision’s type is neither allow nor deny, such as an outcome of null,
and login when the session state is unavailable or still pending.
Example
Section titled “Example”import { createClient } from '@edgekitcloud/client-browser';
declare global { interface Window { k5aMeta?: Record<string, unknown>; }}
const ek = createClient({ siteId: 'site_example' });
// The page's one paywall decision. Your paywall code awaits this same promise.const decision = ek.decide('paywall', { context: { article_id: 'a-1' } });
// The first settled session state, or undefined after 2 seconds.function signedIn() { return new Promise<boolean | undefined>((resolve) => { setTimeout(() => resolve(undefined), 2000); const stop = ek.id.subscribe((state) => { if (state.status === 'pending') return; resolve( state.status === 'unavailable' ? undefined : state.status === 'authenticated', ); queueMicrotask(() => stop()); }); });}
const [{ paywall }, login] = await Promise.all([decision, signedIn()]);
const meta: Record<string, string | number> = {};if (paywall.status === 'decided') { if (paywall.type === 'deny') meta.paywall = 'hard'; if (paywall.type === 'allow') meta.paywall = 'open'; meta.subscriber = paywall.reason === 'grant' ? 1 : 0;}if (login !== undefined) meta.login = login ? 1 : 0;
window.k5aMeta = { ...window.k5aMeta, ...meta };
const script = document.createElement('script');script.src = 'YOUR_KILKAYA_SCRIPT_URL';script.async = true;document.head.append(script);If your page already reads the session for its header, use that state rather than reading it a second time. Reading
the session is a request to your tenant, and subscribe makes one the first time a page calls it.
Behind the site proxy
Section titled “Behind the site proxy”The site proxy decides paywall on the server and writes the decision into the
page, in a <script type="application/json" id="edgekit-decision">. Read it there instead of calling decide:
const island = document.getElementById('edgekit-decision')?.textContent;const decision = island ? JSON.parse(island).decision : null;decision has the same type and reason as a decided result, with no status. It is null when the proxy did not
decide the page or got no answer: leave paywall and subscriber out then.
Send states, not ids
Section titled “Send states, not ids”The recipe sends no id: not the EdgeKit user id and not the device id. The three fields above carry states only. An
id in k5aMeta, such as subscriberid, ties Kilkaya’s data to one person. Send one only if your consent covers it, and only after the user has agreed.
What this does not do
Section titled “What this does not do”- No server-side feed. EdgeKit sends Kilkaya no events, grants or purchases. To get those into your own analysis, load them into your warehouse.
- No front pages. Kilkaya’s front page tools pick and order stories, and EdgeKit decides nothing about that.
A front page that EdgeKit does not gate needs no decide call: set
loginalone, or nothing.