JavaScript SDK Reference

Programmatically control the Mine CMP banner and consent state from your site's JavaScript.

The Mine CMP exposes a MineCMP global object that lets you control the consent banner, read and update the user's consent state, and react to consent changes from your own JavaScript.

This article documents every available method, property, and event on MineCMP.

When the SDK is available

MineCMP becomes available on window after the CMP configuration finishes loading. Any calls you make to the SDK before it has finished initializing are automatically queued and executed once the CMP is ready, so you do not need to defer your code manually.

If you do need to wait for initialization explicitly — for example, to read consent state on page load — use MineCMP.onReady():

MineCMP.onReady(() => {
  console.log('CMP is ready');
  console.log('Current consent:', MineCMP.getConsent());
});

If the CMP is already initialized when you call onReady(), the callback fires immediately.

Actions

Actions let you control the banner and modify the user's consent state.

MineCMP.show(layer?, bannerId?)

Shows the consent banner. Both arguments are optional.

  • layer (optional) — which layer to open. Accepts 'first' or 'second'. Defaults to the second layer (the detailed preferences panel).
  • bannerId (optional) — the ID of a specific banner to display. If omitted, the banner determined by rule matching is used.
// Open the detailed preferences panel
MineCMP.show();

// Open the first layer (initial consent banner)
MineCMP.show('first');

// Open a specific banner by ID
MineCMP.show('first', 'banner-eu');

This is also the method to call from a "Cookie Settings" link, especially for SoftOptIn banners configured with firstLayerHideBanner: true, where the banner does not auto-display on page load.

MineCMP.hide()

Hides the banner if it is currently visible.

MineCMP.hide();

MineCMP.acceptAll()

Grants consent for all available cookie categories.

MineCMP.acceptAll();

MineCMP.accept(categories[])

Grants consent for a specific list of categories. Categories not included in the array are left in their current state.

MineCMP.accept(['analytics', 'functional']);

MineCMP.withdrawAll()

Withdraws consent for all categories.

MineCMP.withdrawAll();

MineCMP.withdraw(categories[])

Withdraws consent for a specific list of categories.

MineCMP.withdraw(['marketing']);

MineCMP.clearConsent()

Clears the stored consent record for the current banner. After calling this, the user is treated as if they had never made a consent choice for the banner, and the banner will auto-show on the next eligible page load.

MineCMP.clearConsent();

MineCMP.switchLayer(layer)

Switches the visible banner from one layer to another without closing it. Accepts 'first' or 'second'.

MineCMP.switchLayer('second');

Properties

Read-only methods that return the current state of the CMP.

MineCMP.getConsent()

Returns the user's current consent state for all categories, or null if no consent choice has been made yet.

Returns: CategoryConsent | null

const consent = MineCMP.getConsent();
if (consent) {
  // Inspect which categories the user has consented to
}

MineCMP.isReady()

Returns true if the CMP has finished initializing, false otherwise.

if (MineCMP.isReady()) {
  // Safe to read consent state synchronously
}

MineCMP.getBannerState()

Returns an object describing the current banner state.

Returns: { visible, layer, bannerId }

  • visible — whether the banner is currently displayed
  • layer — the layer currently shown ('first' or 'second')
  • bannerId — the ID of the banner currently in use
const state = MineCMP.getBannerState();
console.log(state.visible, state.layer, state.bannerId);

MineCMP.hasConsentChoice()

Returns true if the user has made a consent decision for the current banner, false if they have not yet interacted with it.

if (!MineCMP.hasConsentChoice()) {
  // User has not yet made a choice
}

Events

Subscribe to CMP lifecycle and consent change events.

MineCMP.onReady(callback)

Registers a callback that fires when the CMP is initialized. If the CMP is already initialized at the time of the call, the callback fires immediately.

MineCMP.onReady(() => {
  // CMP is ready to use
});

MineCMP.onConsentChange(callback)

Registers a callback that fires every time the user's consent state changes. Returns an unsubscribe function — call it to stop receiving updates.

const unsubscribe = MineCMP.onConsentChange((consent) => {
  console.log('Consent changed:', consent);
});

// Later, to stop listening:
unsubscribe();

Not yet implemented

The following SDK members are planned but not currently available. Do not rely on them in production code.

MineCMP.onScriptsUnblocked(callback)

Will be called after scripts for a category are unblocked — useful for loading analytics or other vendor scripts immediately after consent is granted. The callback will receive the unblocked category.

As an alternative, a cmp:scriptsUnblocked custom event will be dispatched on window with detail: { category }.

Quick reference

MemberTypePurpose
show(layer?, bannerId?)ActionShow the banner
hide()ActionHide the banner
acceptAll()ActionConsent to all categories
accept(categories[])ActionConsent to specific categories
withdrawAll()ActionWithdraw consent for all categories
withdraw(categories[])ActionWithdraw consent for specific categories
clearConsent()ActionClear stored consent for the current banner
switchLayer(layer)ActionSwitch between first and second layer
getConsent()PropertyGet consent state for all categories
isReady()PropertyCheck if CMP is initialized
getBannerState()PropertyGet current banner state
hasConsentChoice()PropertyCheck if user has made a consent choice
onReady(callback)EventFires when CMP is initialized
onConsentChange(callback)EventFires when consent state changes