OptinStack

JavaScript API

Complete reference for the window.OptinStack programmatic API.

The SDK exposes a full API at window.OptinStack for programmatic control over consent, UI, and events.

OptinStack.version

Returns the SDK version string.

console.log(window.OptinStack.version); // e.g. "1.2.0"

OptinStack.consent

Read and modify consent state programmatically.

consent.get()

Returns the current consent choices as an object.

const choices = window.OptinStack.consent.get();
// { necessary: true, analytics: false, marketing: false, preferences: true }

Individual Getters

Each category is available as a readonly getter:

window.OptinStack.consent.necessary; // always true
window.OptinStack.consent.analytics; // boolean
window.OptinStack.consent.marketing; // boolean
window.OptinStack.consent.preferences; // boolean

consent.accept()

Accepts all consent categories. Equivalent to the user clicking "Accept All" on the banner.

window.OptinStack.consent.accept();

This sets all categories to true, hides the banner, and triggers a server sync.

consent.reject()

Rejects all optional categories. Only necessary remains true.

window.OptinStack.consent.reject();

consent.update(choices)

Partially updates consent choices. Only the provided categories are changed — others keep their current value. The necessary category is always forced to true.

window.OptinStack.consent.update({
  analytics: true,
  marketing: false,
});

Setting necessary: false in the update object is silently whitelisted — necessary consent is always true.

consent.renew()

Resets consent to default choices (as if the user hasn't interacted yet) and re-shows the banner.

window.OptinStack.consent.renew();

This is useful for implementing a "Manage Cookies" link that lets returning users reconsider their choices.

OptinStack.config

Access the resolved configuration for the current page.

config.project

The full project configuration object, including storage settings, providers, trackers, rules, and locales.

const projectId = window.OptinStack.config.project.projectId;

config.rule

The matched rule for the current region — contains the banner mode, type, regions, pages, and animation settings.

const mode = window.OptinStack.config.rule.bannerRule;
// "opt-in" | "opt-out" | "informational" | "dont-sell"

config.gpcApplied

Whether the Global Privacy Control signal was detected and applied.

if (window.OptinStack.config.gpcApplied) {
  console.log('GPC is active');
}

OptinStack.push(...callbacks)

Queues callbacks that execute after the SDK initializes. Safe to call before or after initialization.

// Before SDK loads
window.OptinStack = window.OptinStack || [];
window.OptinStack.push(function (os) {
  console.log(os.consent.get());
});

// After SDK loads — executes immediately
window.OptinStack.push(function (os) {
  os.consent.accept();
});

Multiple callbacks can be pushed at once:

window.OptinStack.push(
  function (os) {
    console.log('First');
  },
  function (os) {
    console.log('Second');
  }
);

OptinStack.destroy()

Tears down the SDK completely — removes all DOM elements, event listeners, mutation observers, and blocking behavior.

window.OptinStack.destroy();
After calling destroy(), the SDK cannot be restarted without reloading the page.

On this page