Official integration to handle consents with the Ketch consent management platform when using the Krenalis JavaScript SDK.
withKetch(krenalis) wraps the load method of the Krenalis SDK, so that:
- The SDK is loaded only once the user's choice is known. Until then, the calls to the SDK (
page,track, ...) are queued, and the SDK neither stores data on the device nor sends events. The SDK is loaded when Ketch has communicated the user's consent and either:- the Ketch consent experience (the banner) is closed, because the user has made a choice or has closed it, or it is not shown at all, typically because the user has already made a choice in a previous visit;
- no purpose of the user's jurisdiction requires the user's opt-in (for example, where the banner is just a notice), so there is no choice to wait for.
- Every event includes the user's consent choices in
context.consents. This includes events queued before Ketch reported consent and events generated from the query string. The field records the user's choice for each Ketch purpose, for example{ "analytics": true, "advertising": false }. - Changes of the consent made by the user later are forwarded through
setConsentsand applied to the subsequent events.
The Ketch tag can be added to the page before or after the SDK: if it is not there yet, the integration waits for it.
The integration also handles initialization after Ketch has already resolved the consent or closed the banner. Ketch sends the current consent to new consent listeners as soon as it is available, even if resolved before registration, so no separate lookup is needed. A one-time hideExperienceReasonUpdated listener recovers the last known reason, including willNotShow when no banner is needed. The regular hideExperience listener handles subsequent closures, including repeated closures with the same reason.
| Case | When the SDK is loaded |
|---|---|
| New user, a purpose requires opt-in (e.g. GDPR) | when the user makes a choice or closes the banner |
| New user, no purpose requires opt-in | as soon as Ketch communicates the consent |
| Returning user | as soon as Ketch communicates the stored consent |
| The user never interacts with the banner | never |
| Ketch is never loaded (e.g. blocked by the browser) | never |
The integration works with the Krenalis snippet; installing the SDK as an npm package is not supported.
In the Krenalis admin, the page of the JavaScript connection generates the snippet with the integration when Consent management is set to Ketch.
To set it up manually:
-
Add the Ketch Smart Tag to the page, as described in the Ketch documentation.
-
Add this script before the Krenalis snippet:
<script src="https://cdn.krenalis.com/krenalis-ketch.min.js"></script>
-
In the Krenalis snippet, replace the
loadcall:krenalis.load("<event write key>", "<endpoint>");
with:
withKetch(krenalis).load("<event write key>", "<endpoint>");
Warning
If the snippet still calls krenalis.load(...) directly, the SDK is loaded without waiting for the consent.
You'll need Node.js (with npm). See engines.node in package.json for compatible versions; CI uses Node.js 24.
Install the development dependencies with:
npm ciThe project uses Prettier to format files. Run it with:
npm run formatThe README and generated files are excluded from formatting.
Before committing, run:
npm ci # install the dependencies from package-lock.json
npm run format # format the files with Prettier
npm run build # lint with ESLint and build dist/krenalis-ketch.min.js (ES5)Or run the same sequence with a single command:
npm run commitThe build uses esbuild for bundling and minification, and SWC for transpilation to ES5.
This project is released under the MIT License. © 2026 Open2b
The script distributed in dist/krenalis-ketch.min.js keeps the license notice in its header; keep it when you copy or redistribute the script.
Ketch is a trademark of Ketch Kloud Inc. This integration is not affiliated with or endorsed by Ketch Kloud Inc.