k.privacy
Read localized Cookie consent settings and inspect third-party script Cookies
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
Api, <script env="server">, CodeBlock | Cookie banner configured under Cookie Management (getJSCookies needs outbound HTTP) | Render custom localized consent banners or inspect Cookies set by external scripts |
Quick Start
k.api.get("cookie-consent", () => {
const setting = k.privacy.cookieConsent.setting
return {
enable: setting.enable,
title: setting.cookieText.title,
theme: setting.uI.theme,
closeActionUS: setting.closeButton.getAction("US")
}
})Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
k.privacy.cookieConsent.setting | Get Cookie consent settings localized for the current request culture | CookieConsentSettingViewModel |
setting.closeButton.getAction(countryCode) | Resolve effective close-button action for a two-letter country code | "accept" | "reject" |
k.privacy.cookieConsent.getJSCookies(JSUrl, LoadingUrl?, tag?) | Call external scanner service to inspect Cookies written by a script | CookieItem[] |
Overview
k.privacy exposes server-side privacy and Cookie compliance utilities. Use k.privacy.cookieConsent to read the site's Cookie consent banner configuration localized for the current request culture (for custom consent banner templates), resolve region-aware close-button defaults, or inspect Cookies set by third-party scripts.
| API | Purpose |
|---|---|
k.privacy.cookieConsent | Read localized Cookie consent settings, categories, close-button action, and script Cookie scans |
k.cookie | Read and write individual HTTP Cookies on the current request/response (see k.cookie) |
cookieConsent.setting
Returns the Cookie consent view model configured under Cookie Management in Kooboo Admin, with banner copy, category names, and Cookie descriptions already localized to the current request culture.
Property Casing Note
In TypeScript IntelliSense, acronym-prefixed properties start with a lowercase letter (uI, hTML, uRL). At runtime, setting.uI and setting.UI (as well as hTML/HTML and uRL/URL) resolve to the exact same property, while all-lowercase setting.ui, html, and url evaluate to undefined. Multi-word properties such as cookieText.title, cookieText.buttons.allowAll, and themeOption.primaryColor work directly in camelCase at runtime.
Returns: CookieConsentSettingViewModel.
k.api.get("cookie-consent-config", () => {
const setting = k.privacy.cookieConsent.setting
return {
enable: setting.enable,
displayRule: setting.displayRule,
categories: setting.category.map((cat) => ({
id: cat.id,
name: cat.name,
required: cat.required,
defaultChecked: cat.defaultChecked
})),
title: setting.cookieText.title,
buttons: {
allowAll: setting.cookieText.buttons.allowAll,
allowSelection: setting.cookieText.buttons.allowSelection,
rejectAll: setting.cookieText.buttons.rejectAll
},
ui: {
typeAndPosition: setting.uI.typeAndPosition,
theme: setting.uI.theme,
floatBall: setting.uI.floatBall,
primaryColor: setting.uI.themeOption.primaryColor
}
}
})closeButton.getAction()
Resolves the effective privacy action when a visitor closes the consent banner without making an explicit choice.
- When
closeButton.actionis"default","US"returns"accept"and any other country code returns"reject". - When
closeButton.actionis explicitly"accept"or"reject", that configured value is returned directly.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
countryCode | string | yes | Two-letter country/region code (for example "US", "DE", or "CN") |
Returns: string ("accept" or "reject").
k.api.get("close-action", () => {
const closeBtn = k.privacy.cookieConsent.setting.closeButton
return {
show: closeBtn.show,
configuredAction: closeBtn.action,
usAction: closeBtn.getAction("US"),
deAction: closeBtn.getAction("DE")
}
})cookieConsent.getJSCookies()
Calls an external headless-browser Cookie scanner service to inspect Cookies generated when a target script or resource loads.
External Service Dependency and Timeout
getJSCookies() sends an outbound request to an external headless-browser Cookie scanning service with a 120-second timeout. It requires outbound connectivity and availability of that remote scanner service; wrap calls in try / catch to handle remote browser or network errors gracefully.
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
JSUrl | string | yes | - | Target external script or resource URL to analyze |
LoadingUrl | string | no | Current site BaseUrl | Host page URL used when loading the script; falls back to "https://www.kooboo.com" if site BaseUrl is empty |
tag | string | no | "script" | HTML tag context ("script", "iframe", "img", "link") |
Returns: CookieItem[].
k.api.get("scan-js-cookies", () => {
const jsUrl = k.request.queryString.get("jsUrl")
if (!jsUrl) {
return { ok: false, message: "jsUrl is required" }
}
try {
const items = k.privacy.cookieConsent.getJSCookies(
jsUrl,
k.site.info.baseUrl,
"script"
)
return { ok: true, items: items }
} catch (error) {
return { ok: false, message: String(error) }
}
})TypeScript Definitions
Show full TypeScript definitions
interface KPrivacy {
cookieConsent: KCookieConsent;
}
interface KCookieConsent {
setting: CookieConsentSettingViewModel;
getJSCookies(JSUrl: string, LoadingUrl?: string, tag?: string): CookieItem[];
}
interface CookieConsentSettingViewModel {
enable: boolean;
displayRule: DisplayRule;
category: CookieCategoryViewModel[];
cookieText: CookieText;
resource: CategoryResourceViewModel[];
closeButton: closeButtonAction;
uI: CookieUI;
}
interface CookieCategoryViewModel {
id: string;
name: string;
description: string;
required: boolean;
defaultChecked: boolean;
resource: CategoryResourceViewModel[];
}
interface CategoryResourceViewModel {
cookieCategory: string;
uRL: string;
cookieItems: CookieItemViewModel[];
}
interface CookieItemViewModel {
name: string;
description: string;
expireMinutes: number;
}
interface DisplayRule {
isInclude: boolean;
type: string; // "All" | "EU" | "Custom"
countries: any; // Collection of country codes
}
interface closeButtonAction {
show: boolean;
action: string; // "default" | "accept" | "reject"
getAction(countryCode: string): string;
}
interface CookieUI {
customTemplate: boolean;
hTML: string;
typeAndPosition: string; // "banner-bottom" | "banner-top" | "modal-center" | "inline-top" | "inline-bottom"
floatBall: boolean;
theme: string; // "light" | "dark" | "custom"
themeOption: CustomTheme;
}
interface CustomTheme {
primaryColor: string;
backgroundColor: string;
textColor: string;
buttonColor: string;
buttonTextColor: string;
}
interface CookieText {
title: string;
description: string;
introduction: string;
iframeFallback: string;
buttons: ButtonText;
links: LinkText;
}
interface ButtonText {
allowAll: string;
allowSelection: string;
rejectAll: string;
}
interface LinkText {
privacyPolicy: LinkObject;
cookiePolicy: LinkObject;
settings: LinkObject;
}
interface LinkObject {
url: string;
anchorText: string;
}
interface CookieItem {
name: string;
value: string;
domain: string;
path: string;
description: string;
privacyLink: string;
vendor: string;
category: string;
expiresMinutes?: number;
}Related Docs
- k.cookie — Read and write HTTP Cookies for the current request/response
- Cookie Management (Admin Settings) — Configure banners, categories, translations, and custom templates