Compliance Dialog Trigger Rules and State Management
Key takeawayThis section defines the structure template, field dictionary, integration points and compliance boundaries for 「Compliance Dialog Trigger Rules and State Management」 in COMPLIANCE BANNER SPEC. Templates are for reference only; verify local regulations and platform rules before launch.
Industries and use cases
- Sites that deploy several compliance dialogs at once
- Scenarios where dialogs interfere with each other and degrade the experience
- Template sites that need a unified dialog management mechanism
- Multilingual sites that must show different dialogs by region
Template / code snippethtml
<!-- 统一弹窗调度器:按优先级与地区决定显示哪一个 -->
<script>
(function () {
/* 优先级:必须先于其他弹窗显示的合规要求在前 */
var RULES = [
{
id: 'age',
priority: 10,
scope: 'all',
requires: '${ageRequired}', /* 该品类是否需要年龄确认 */
requiresConsent: true,
blocking: true /* 阻塞页面交互 */
},
{
id: 'prop65',
priority: 20,
scope: 'US-CA',
requires: '${prop65Required}',
requiresConsent: false,
blocking: false
},
{
id: 'cookie',
priority: 30,
scope: 'regions-requiring-consent',
requires: '${cookiesRequired}',
requiresConsent: true,
blocking: false
},
{
id: 'epr',
priority: 40,
scope: 'EU',
requires: '${eprRequired}',
requiresConsent: false,
blocking: false
}
];
var STORE = 'compliance_state_v1';
var state = {};
try { state = JSON.parse(localStorage.getItem(STORE)) || {}; } catch (e) {}
function region() {
/* 由服务端按 IP 判断后写入,避免前端判断不准 */
return document.documentElement.getAttribute('data-region') || 'GLOBAL';
}
function inScope(rule) {
if (rule.scope === 'all') return true;
if (rule.scope === 'EU') return ['DE','FR','ES','IT','NL','PL'].indexOf(region()) >= 0;
if (rule.scope === 'US-CA') return region() === 'US-CA';
if (rule.scope === 'regions-requiring-consent') {
return ['EU','UK','CH','NO','BR'].indexOf(region()) >= 0;
}
return true;
}
var queue = RULES
.filter(function (r) { return r.requires && inScope(r); })
.filter(function (r) { return !state[r.id]; })
.sort(function (a, b) { return a.priority - b.priority; });
/* 每次只显示一个,关闭后再显示下一个 */
function next() {
var r = queue.shift();
if (!r) return;
var el = document.getElementById(r.id + 'Modal');
if (!el) return next();
el.hidden = false;
if (r.blocking) document.body.classList.add('modal-blocking');
el.querySelectorAll('[data-close]').forEach(function (b) {
b.addEventListener('click', function () {
el.hidden = true;
document.body.classList.remove('modal-blocking');
state[r.id] = true;
try { localStorage.setItem(STORE, JSON.stringify(state)); } catch (e) {}
next();
});
});
}
next();
})();
</script>
<!-- 地区判定由服务端写入 html 标签:
<html data-region="US-CA"> -->
| Field / parameter | Type | Description and values |
|---|---|---|
| Dialog ID | Text | Unique, matching the component root element id |
| Priority | Number | Lower values display first |
| Scope | Enum | all / EU / US-CA / specific regions |
| Trigger condition | Boolean | Configured by category and page type |
| Blocking | Boolean | Whether page interaction is blocked |
| State storage key | Text | One versioned key so rule changes can re-ask |
| Region detection | Note | Server-side IP lookup written into an attribute |
SEO and structured-data notes
| Show one dialog at a time | Stacked dialogs hurt the experience and leave users unable to make a meaningful choice |
|---|---|
| Blocking dialogs take the highest priority | Age confirmation and minor-protection requirements should not be delayed by a cookie banner |
| Detect region on the server | Browser language or time zone is unreliable for jurisdiction and misses where real users are |
| Manage state centrally | A single storage key lets all stored states be invalidated together when rules change |
| Non-blocking dialogs can wait | Informational notices can appear after the user has spent some time on the page |
| Every dialog must be closable | A dialog with no close path is judged non-compliant outright in some reviews |
Compliance risk notes
- Jurisdiction must not be inferred from browser language
- Several compliance dialogs must not be stacked at the same time
- A dialog must not be impossible to close
- Marketing content must not be mixed into a compliance dialog
- Old state must be invalidated and consent re-requested after a rule change
Do not reuse this template verbatim in regulated contexts; verify local regulations and platform rules before going live.
Modification example
<!-- Modification example: turn hard-coded dialog logic into a configuration-driven rule table -->
<!-- Original: each dialog decides on its own, unaware of the others -->
<script>
if (needAge) showAge();
if (needCookie) showCookie();
</script>
<!-- Modified: one rule table plus a priority queue -->
<script>
var RULES = [
{ id: 'age', priority: 10, scope: 'all', required: ${ageRequired} },
{ id: 'prop65', priority: 20, scope: 'US-CA', required: ${prop65Required} },
{ id: 'cookie', priority: 30, scope: 'EU,UK,CH', required: ${cookiesRequired} }
];
function region() {
return document.documentElement.getAttribute('data-region') || 'GLOBAL';
}
function inScope(scope) {
if (scope === 'all') return true;
return scope.split(',').indexOf(region()) >= 0;
}
var queue = RULES
.filter(function (r) { return r.required && inScope(r.scope); })
.sort(function (a, b) { return a.priority - b.priority; });
(function next() {
var r = queue.shift();
if (!r) return;
var el = document.getElementById(r.id + 'Modal');
if (!el) return next();
el.hidden = false;
el.querySelectorAll('[data-close]').forEach(function (b) {
b.addEventListener('click', function () {
el.hidden = true;
var st = {};
try { st = JSON.parse(localStorage.getItem('cs')) || {}; } catch (e) {}
st[r.id] = true;
localStorage.setItem('cs', JSON.stringify(st));
next();
});
});
})();
</script>
<!-- Key improvements:
1. rules live in a single table; adding another market
means adding one scope line, not changing the logic
2. priority sets the display order,
blocking compliance requirements come before informational ones
3. dialogs display one at a time
4. the region is written by the server after an IP lookup into data-region,
so the jurisdiction is not misjudged from browser language
These four points make the inevitable "dialogs fighting each other" problem manageable. -->FAQ
Do dialogs really conflict?
Yes. When a cookie banner and an age gate appear together, users do not know which to handle first. A priority queue that runs them in sequence solves it.
Is server-side region detection required?
When accuracy matters, yes. A server-side IP lookup written into an HTML attribute is the most reliable approach.
Should every dialog store state?
Consent and confirmation dialogs should. Informational notices may reappear, though frequent repetition hurts the experience.
Do these dialogs hurt search performance?
As long as the content is in the HTML source and the main content is not covered, there is no negative effect on crawling or indexing.
Version notes2026-11-20: first release, compiled from official Google documentation and public technical sources; updated as engine rules change. Engine behaviour details follow the latest official Google documentation.
Related reading
Cookie Consent Banner Components and Consent Management RulesCalifornia Proposition 65 Warning Component RulesGDPR Data Notice and Rights Request Component RulesEU Extended Producer Responsibility Notice Component RulesEU Responsible Person Information Component RulesNote: this page is a summary of publicly documented search-engine rules and is for self-check reference only. Engine behaviour is subject to the latest official Google documentation; verify against your own Search Console data.