JavaScript API
Once cmp.js has loaded, the API lives on window.LightningCMP. Before it loads,
use the queue-safe lightning('method', args) dispatcher (see
Quickstart).
Methods
Section titled “Methods”| Method | Signature | Purpose |
|---|---|---|
init |
init(config) |
Boot the CMP. See the Config reference. Idempotent — calling twice is a no-op. |
openPreferences |
(): void |
Open the preferences modal, e.g. from a footer “Cookie settings” link. |
getConsent |
(): ConsentState | null |
Current consent state, or null before init. |
onConsentChange |
(fn) => () => void |
Subscribe to changes; returns an unsubscribe function. |
acceptAll |
(): void |
Grant all categories. |
rejectAll |
(): void |
Withhold all optional categories. |
reset |
(): void |
Clear the stored decision and re-show the banner. |
renderCookieList |
(target, options?) => Promise<void> |
Paint the categorised cookie inventory into a page element. See Cookie declaration. |
debug |
(): DebugReport | null |
Console snapshot: consent, Consent Mode signals, gated-script table. |
audit |
(): Promise<AuditReport | null> |
Behavioural self-audit of cookies/requests actually observed. |
defineBridge |
(id, factory) => void |
Register a custom bridge. |
version |
string |
The build version. |
BRIDGE_API_VERSION |
number |
Custom-bridge contract version. |
Example
Section titled “Example”// React to consent from app code.const off = LightningCMP.onConsentChange((state) => { if (state.choices.statistics) startAnalytics();});
// Later, from a settings screen:LightningCMP.openPreferences();