Skip to main content

JavaScript SDK

The biskoui JavaScript SDK provides a simple, synchronous API for managing user consent and controlling third-party services on your website. Once installed via the quick start guide, the SDK automatically handles consent collection and service activation.

How It Works

The biskoui SDK operates through two main mechanisms:

  1. Global API - Synchronous methods for programmatic control
  2. DOM Events - Automatic notifications when services become available

For automatic script execution based on consent, see the Script Blocking guide.

Global API

The SDK exposes a global window.biskoui object with synchronous methods:

// Show the consent banner
biskoui.showBanner();

// Hide the consent banner
biskoui.hideBanner();

// Accept all non-necessary services
biskoui.acceptAll();

// Reject all non-necessary services
biskoui.rejectAll();

// Accept a specific service (additive to existing consent)
biskoui.acceptService('google_analytics');

// Check if a specific service has been accepted
const hasAnalytics = biskoui.hasAcceptedService('google_analytics');

All methods are available immediately after the SDK loads. Call them from click handlers or after DOMContentLoaded.

Service Activation Events

The SDK fires events when services become available for use:

Per-Service Events

Each service configured in your biskoui dashboard fires its own activation event:

// Listen for Google Maps activation
window.addEventListener('biskoui:google_maps_activated', function() {
console.log('Google Maps is now allowed');
initGoogleMaps();
});

// Listen for YouTube activation
window.addEventListener('biskoui:youtube_activated', function() {
console.log('YouTube embeds are now allowed');
loadYouTubeEmbeds();
});

Event names follow the pattern: biskoui:<service_key>_activated

Initialization Event

The SDK fires a special event when it has finished loading and is ready to use:

window.addEventListener('biskoui:ready', function() {
console.log('Biskoui SDK is fully initialized');
// SDK methods are now available
});

This event is useful if you need to ensure the SDK is loaded before calling any API methods or checking consent status.

Usage Examples

Manual Banner Control

<button onclick="biskoui.showBanner()">Review Cookie Settings</button>
<button onclick="biskoui.acceptAll()">Accept All Cookies</button>
<button onclick="biskoui.rejectAll()">Reject All</button>
<button onclick="biskoui.acceptService('google_analytics')">Accept Analytics</button>

Event-Driven Service Loading

window.addEventListener('biskoui:google_maps_activated', function() {
// Initialize Google Maps when consent is granted
const map = new google.maps.Map(document.getElementById('map'), {
center: { lat: 46.8182, lng: 8.2275 },
zoom: 8
});
});
document.addEventListener('DOMContentLoaded', function() {
if (biskoui.hasAcceptedService('google_maps')) {
// Google Maps already allowed - initialize immediately
initGoogleMaps();
}

if (biskoui.hasAcceptedService('youtube')) {
// YouTube already allowed - load embeds
loadYouTubeEmbeds();
}
});

Granular Service Acceptance

// Accept individual services additively
function enableAnalytics() {
biskoui.acceptService('google_analytics');
}

function enableVideoEmbeds() {
biskoui.acceptService('youtube');
biskoui.acceptService('vimeo');
}

// Accept service based on user interaction
function handleServiceToggle(serviceKey, isEnabled) {
if (isEnabled) {
biskoui.acceptService(serviceKey);
}
// Note: There's no rejectService method - use rejectAll() or showBanner() for changes
}

Service Keys and Naming

Service keys use snake_case format (e.g., google_maps, youtube, vimeo). These keys must match exactly across:

  • Service configuration in your biskoui dashboard
  • Event names: biskoui:<service_key>_activated
  • Service queries: biskoui.hasAcceptedService('<service_key>')
  • Script blocking attributes (see Script Blocking)