Each site has an app configuration beside its banner script: a JSON file with the categories, texts, region rules and Google Consent Mode mapping your app needs to draw its consent screens. It is built from the same banner settings as your website's banner, and Kukie.io writes it again whenever those settings change.
The address
https://cdn.kukie.io/s/YOUR-SITE-KEY/app.json
Replace YOUR-SITE-KEY with your site key, the part of your banner snippet between /s/ and /c.js. The file needs no API key and is the same for every person.
Caching and refreshing
- Keep the last good copy in your app's storage, and use it when the app starts.
- Fetch a fresh copy in the background when the app starts or comes to the foreground. When the fetch fails, keep using the copy you have.
- Ship a copy inside the app for its very first start without a network.
What it holds
| Member | What it is |
|---|---|
object, schema_version | app_config and 1 today. Kukie.io raises schema_version only when it removes a member or changes its meaning; new members can appear at any time, so ignore the ones you don't know. If schema_version is higher than the one you wrote your code for, keep your last good copy and update your app. |
enabled | false when the site's banner is switched off in the Banner Editor, or the site is frozen and its grace period has ended. The file then holds only object, schema_version, site_key and enabled, and your website's banner shows nothing and records nothing. |
version | The banner settings' version. Send it as banner_version with each record. |
categories_version, consent_version | Keep both with the person's choice. When either changes, you may need to ask again (below). |
consent_log_enabled | false when the site's consent log is switched off. Don't send records then. |
consent_endpoint, geo_endpoint | The addresses for recording a choice and for the region lookup. |
consent_mode | per_category, or per_service when the site asks for consent per service. |
default_language, texts | The banner's texts for each language it ships, keyed by language code, and the language to use when the person's language has no entry. |
categories | The categories in the banner's order, each with its slug and whether it is required. On a per_service site each one also lists its services. |
regions | The site's region rules (below). |
google_consent_mode | enabled says whether your website's banner sends Google Consent Mode signals. types_by_category maps each category to Google's consent types: Google Consent Mode in Firebase apps. |
google_privacy_url | Present while Google's banner text is applied to the site: https://business.safety.google/privacy/. |
Showing the texts
Each language in texts has the first screen's strings (banner_title, banner_description, accept_all, reject_all, manage_preferences), the preferences screen's strings (preferences_title, preferences_description, save_preferences), each category's name and description under categories, the Do Not Sell or Share link's text (dnsmpi_link), and your privacy and cookie policy links (privacy_policy and cookie_policy, each with a text and a url, or null when the site has switched that link off or no address applies to that language, whether its own, the default language's or a policy you published in Kukie.io). banner_description and preferences_description are HTML, with links, line breaks and emphasis only. banner_description_text and preferences_description_text are the same texts as plain text: show them as text, never as HTML. The plain text has no links, so when google_privacy_url is present, show it as a link in your first screen. Where the site has no text in a language for a title, a button or a link, the configuration carries the text your website's banner shows in its place, so these always have text. Only the descriptions can be empty, when the site has none in that language: the two descriptions and their plain-text copies, and a category's description.
The person's region
A site can have a rule for each region. To find the rule for the person:
- Call
https://app.kukie.io/api/v1/geo(the file'sgeo_endpoint) with a short timeout. It answers with the person'scountryandregion, for example{"country": "DE", "region": "eu-de"}. - Take the rule whose
region_codeequalsregion. - If there is none and the code has a hyphen, take the rule for the part before the hyphen (
euforeu-de). - If there is still none, take the rule
default. A site without one asks first, as underopt_in. - If the lookup fails, take the site's strictest rule, in this order from the strictest:
opt_in,opt_out,notice_only,hidden. On a tie, the first rule in the list wins.
This is the order your website's banner uses, so a person in one place gets the same rule on your website and in your app.
The models, as your website's banner applies them:
opt_in: ask before any optional category is used.opt_out: optional categories are allowed until the person refuses them, and the banner shows the choice. A choice the person has already made is applied first while it is valid (below), and the banner doesn't show. Where the site respects Do Not Track, a browser that sends it, with no valid stored choice, gets only the required categories and still sees the banner; nothing is recorded until the person uses it. Where the site respects Global Privacy Control, a browser that sends it, with no valid stored choice, gets only the required categories, its refusal is recorded once and no banner shows. The signal also overrides a stored choice that allows more than the required categories, unless the person made it in the Do Not Sell or Share dialog or the preferences while the signal was on.notice_only: the banner informs. When the notice closes by itself, afterdismiss_timeout_secondswhere the rule'sdismiss_on_timeoutistrue, or when the person scrolls the page where the rule asks for that, it records an implied acceptance. Once the person starts using the notice, it no longer closes by itself and stays until they choose. A button records the choice it names, and the close button, where the site shows one, records Reject all. A choice the person has already made is applied first while it is valid (below), and the notice doesn't show. Where the site respects Do Not Track, a browser that sends it, with no valid stored choice, gets only the required categories, and nothing is recorded when the notice closes by itself. Global Privacy Control works as underopt_out: with no valid stored choice, the refusal is recorded once and no notice shows.hidden: no banner. Every category is allowed until the person makes a choice through a link on your website, such as Do Not Sell or Share (where the rule'sshow_dnsmpi_linkistrue) or a link that opens the preferences. That choice is recorded and applied until it expires, even when the browser sends a privacy signal, with one exception: where the site respects Global Privacy Control, the signal overrides a stored choice that allows more than the required categories, unless the person made it in the Do Not Sell or Share dialog or the preferences while the signal was on. Where the site respects Global Privacy Control or Do Not Track, a browser that sends the signal, with no stored choice that applies, gets only the required categories, and a Global Privacy Control refusal is recorded once.
Each rule also says which buttons the banner shows (show_accept_all, show_reject_all, show_preferences), whether it shows a Do Not Sell or Share link (show_dnsmpi_link; the link's text is dnsmpi_link in each language of texts) and how many days a choice lasts (consent_duration_days). Record a choice the person makes in your app under any rule, hidden included, like any other.
When to ask again
Show your consent screen again when the stored choice:
- is older than the rule's
consent_duration_days; - was made under another
categories_version, and the rule'sreconsent_on_changeistrue; - was made under another
consent_version(you used Renew now under Renew user consents in the site's settings); - was made under a less strict rule than the one that applies now, for example a person who travelled.
Under a hidden rule only the first reason applies. No consent screen shows there, so keep a choice made under it until it expires, whatever its categories_version or consent_version: dropping a refusal would put back the grant every category gets before a choice. Your website's banner does the same. There, a Global Privacy Control signal the site respects can also end a stored choice earlier, as the hidden model above says.
Samples
Swift, with URLSession and Codable:
import Foundation
// The members of app.json this sample reads. Decoding ignores the others.
struct AppConfig: Decodable {
struct Category: Decodable {
let slug: String
let required: Bool
}
struct RegionRule: Decodable {
let regionCode: String
let consentModel: String
let consentDurationDays: Int?
enum CodingKeys: String, CodingKey {
case regionCode = "region_code"
case consentModel = "consent_model"
case consentDurationDays = "consent_duration_days"
}
}
struct GoogleConsentMode: Decodable {
let typesByCategory: [String: [String]]
enum CodingKeys: String, CodingKey {
case typesByCategory = "types_by_category"
}
}
let schemaVersion: Int
let enabled: Bool
let version: Int?
let categoriesVersion: String?
let consentVersion: Int?
let consentLogEnabled: Bool?
let consentEndpoint: URL?
let geoEndpoint: URL?
let categories: [Category]?
let regions: [RegionRule]?
let googleConsentMode: GoogleConsentMode?
enum CodingKeys: String, CodingKey {
case schemaVersion = "schema_version"
case enabled
case version
case categoriesVersion = "categories_version"
case consentVersion = "consent_version"
case consentLogEnabled = "consent_log_enabled"
case consentEndpoint = "consent_endpoint"
case geoEndpoint = "geo_endpoint"
case categories
case regions
case googleConsentMode = "google_consent_mode"
}
}
enum AppConfigLoader {
static let knownSchemaVersion = 1
// Returns the configuration and the raw file. Save the file as your last
// good copy; on any failure, keep using that copy.
static func fetch(from url: URL) async throws -> (AppConfig, Data) {
let (data, response) = try await URLSession.shared.data(from: url)
guard (response as? HTTPURLResponse)?.statusCode == 200 else {
throw URLError(.badServerResponse)
}
let config = try JSONDecoder().decode(AppConfig.self, from: data)
guard config.schemaVersion <= knownSchemaVersion else {
throw URLError(.cannotDecodeContentData)
}
return (config, data)
}
}
struct GeoAnswer: Decodable {
let country: String?
let region: String?
}
enum Regions {
// The order Kukie.io's web banner uses, strictest first.
static let strictestFirst = ["opt_in", "opt_out", "notice_only", "hidden"]
// The person's region code, or nil when the lookup fails.
static func lookUp(at endpoint: URL) async -> String? {
let request = URLRequest(url: endpoint, timeoutInterval: 3)
guard let result = try? await URLSession.shared.data(for: request),
(result.1 as? HTTPURLResponse)?.statusCode == 200,
let answer = try? JSONDecoder().decode(GeoAnswer.self, from: result.0) else {
return nil
}
return answer.region
}
// The consent model for a region code: the exact rule, then the parent
// (the part before the hyphen), then "default". A failed lookup (nil)
// gets the strictest rule, the first one on a tie. No rule: opt-in.
static func consentModel(for region: String?, in rules: [AppConfig.RegionRule]) -> String {
guard let region else {
var strictest: AppConfig.RegionRule?
for rule in rules where strictest == nil || rank(rule) < rank(strictest!) {
strictest = rule
}
return strictest?.consentModel ?? "opt_in"
}
func rule(_ code: String) -> AppConfig.RegionRule? {
rules.first { $0.regionCode == code }
}
var match = rule(region)
if match == nil, let dash = region.firstIndex(of: "-") {
match = rule(String(region[..<dash]))
}
return (match ?? rule("default"))?.consentModel ?? "opt_in"
}
private static func rank(_ rule: AppConfig.RegionRule) -> Int {
strictestFirst.firstIndex(of: rule.consentModel) ?? strictestFirst.count
}
}
Kotlin, with HttpURLConnection and org.json, both part of Android:
import org.json.JSONObject
import java.net.HttpURLConnection
import java.net.URI
import java.net.URL
// Call these from a background thread: Android refuses network calls on the main thread.
object AppConfigLoader {
const val KNOWN_SCHEMA_VERSION = 1
// Returns the text of app.json, or null. Save it as your last good copy
// and read it with JSONObject(text); on a null, keep using that copy.
fun fetch(url: URL): String? {
val connection = url.openConnection() as HttpURLConnection
return try {
connection.connectTimeout = 5000
connection.readTimeout = 5000
if (connection.responseCode != 200) return null
val text = connection.inputStream.bufferedReader().use { it.readText() }
if (JSONObject(text).optInt("schema_version") > KNOWN_SCHEMA_VERSION) null else text
} catch (e: Exception) {
null
} finally {
connection.disconnect()
}
}
}
object Regions {
// The order Kukie.io's web banner uses, strictest first.
private val strictestFirst = listOf("opt_in", "opt_out", "notice_only", "hidden")
// The person's region code, or null when the lookup fails.
fun lookUp(geoEndpoint: String): String? {
val connection = URI(geoEndpoint).toURL().openConnection() as HttpURLConnection
return try {
connection.connectTimeout = 3000
connection.readTimeout = 3000
if (connection.responseCode != 200) return null
val text = connection.inputStream.bufferedReader().use { it.readText() }
JSONObject(text).optString("region").ifEmpty { null }
} catch (e: Exception) {
null
} finally {
connection.disconnect()
}
}
// The consent model for a region code: the exact rule, then the parent
// (the part before the hyphen), then "default". A failed lookup (null)
// gets the strictest rule, the first one on a tie. No rule: opt-in.
fun consentModel(config: JSONObject, region: String?): String {
val list = config.optJSONArray("regions")
val rules = if (list == null) emptyList() else (0 until list.length()).map { list.getJSONObject(it) }
if (region == null) {
return rules.minByOrNull { rank(it.optString("consent_model")) }?.optString("consent_model") ?: "opt_in"
}
val rule = { code: String -> rules.firstOrNull { it.optString("region_code") == code } }
val parent = if (region.contains('-')) region.substringBefore('-') else null
val match = rule(region) ?: parent?.let { rule(it) } ?: rule("default")
return match?.optString("consent_model") ?: "opt_in"
}
private fun rank(model: String): Int =
strictestFirst.indexOf(model).let { if (it < 0) strictestFirst.size else it }
}
Next: Record consent from an app.
