Skip to content

The snippet, explained

The Quickstart snippet has five parts when you load Google tags yourself, and four when bridges.google.tagId is configured. Understanding each means you can adapt it to any stack confidently.

<link rel="preconnect" href="https://cmp.lightning-consent.io" />

Opens the TLS connection to the edge early so the first GET /config is fast. Pure performance; optional but recommended.

Section titled “The Consent Mode default (when Google is site-hosted)”
gtag("consent", "default", {
ad_storage: "denied",
/* … */ wait_for_update: 500,
});

Tells every site-hosted Google tag “assume denied until I say otherwise.” wait_for_update: 500 gives the CMP up to 500 ms to resolve the stored decision before Google tags act. This block must run before any site-hosted Google tag.

If you configure bridges.google.tagId for GTM, GA4, or Ads, leave this block out. The Google bridge pushes the default itself immediately before it loads the tag, so duplicating the default only adds config noise.

!(function (c) {
c.lightning =
c.lightning ||
function () {
(c.lightning.q = c.lightning.q || []).push(arguments);
};
})(window);

Defines a temporary lightning() that records calls into a queue; when cmp.js loads it replays them in order. This is what lets you load the SDK async and still call lightning('init', …) immediately, without race conditions.

<script
async
src="https://cmp.lightning-consent.io/v1/cmp.js?k=YOUR_LICENSE_KEY"
></script>
<script>
lightning("init", { theme: "light" });
</script>

The SDK (~12 KB gzipped), async, never render-blocking. The ?k= license key authorises backend calls and carries your siteId, so you rarely set it in init().