OptinStack

Getting Started

Install and configure OptinStack on your website.

Installation

Add the OptinStack script tag to your page. The server injects your project configuration and serves the runtime bundle automatically:

<script src="https://api.optinstack.com/banner/{siteId}.js" defer></script>

Replace {siteId} with your project's site ID from the OptinStack dashboard.

Versioned Scripts

You can pin to a specific version for stability:

<script src="https://api.optinstack.com/banner/v1/{siteId}.js" defer></script>

How It Works

When the script loads, the SDK:

  1. Reads the server-injected configuration from window.optinstackConfig and window.optinstackMeta
  2. Detects the user's region and matches the appropriate consent rule
  3. Checks for existing consent stored in cookies
  4. Renders the consent banner inside a Shadow DOM (isolated from your page styles)
  5. Blocks third-party scripts and iframes that require consent
  6. Integrates with Google Consent Mode v2 (if GTM is present)

Callback Queue

Before the SDK loads, window.OptinStack acts as a callback queue. Push functions into it and they'll execute once the SDK is ready:

window.OptinStack = window.OptinStack || [];

window.OptinStack.push(function (os) {
  // Runs after the SDK is fully initialized
  console.log('SDK version:', os.version);
  console.log('Current consent:', os.consent.get());
});

After initialization, push() still works — callbacks execute immediately:

// This works both before and after SDK init
window.OptinStack.push(function (os) {
  os.events.on('consent-updated', function (detail) {
    console.log('Consent changed:', detail.choices);
  });
});

OptinStack uses four fixed consent categories:

CategoryDefaultDescription
necessaryAlways trueEssential cookies — cannot be declined
analyticsVaries by modeAnalytics and performance tracking
marketingVaries by modeAdvertising and marketing cookies
preferencesVaries by modeFunctionality and personalization

The necessary category is always true and cannot be set to false — this is enforced by the SDK at every level.

The consent banner behavior depends on the configured mode for the matched region:

ModeBehavior
opt-inAll optional categories default to false. User must explicitly accept.
opt-outAll optional categories default to true. User can reject.
informationalBanner is informational only — no accept/reject actions.
dont-sellSimilar to opt-out with "Do Not Sell" compliance language.

Global Privacy Control

When the browser sends a Global Privacy Control signal (navigator.globalPrivacyControl === true), the SDK automatically sets all optional category defaults to false, regardless of the banner mode.

You can check whether GPC was detected:

window.OptinStack.push(function (os) {
  if (os.gpc) {
    console.log('GPC signal detected — optional categories defaulted to false');
  }
});

On this page