Skip to main content

JavaScript API Reference

Complete reference for the biskoui JavaScript SDK API methods, events, and data structures.

Global API Methods

All methods are available on the global window.biskoui object and are synchronous.

biskoui.showBanner()

Shows the consent banner to the user.

biskoui.showBanner();

Returns: void

Use case: Allow users to review or change their consent choices.


biskoui.hideBanner()

Hides the consent banner if currently visible.

biskoui.hideBanner();

Returns: void

Use case: Programmatically close the banner (rare use case).


biskoui.acceptAll()

Accepts all non-necessary categories and services. Necessary services remain always active. Automatically closes the consent banner.

biskoui.acceptAll();

Returns: void

Use case: Implement custom "Accept All" buttons or automatic acceptance flows.


biskoui.rejectAll()

Rejects all non-necessary categories and services. Only necessary services remain active. Automatically closes the consent banner.

biskoui.rejectAll();

Returns: void

Use case: Implement custom "Reject All" buttons or privacy-focused flows.


biskoui.acceptService(serviceId)

Accepts the specified service in addition to any previously accepted services. Does not affect other services' consent status. Necessary services remain always active. Automatically closes the consent banner.

biskoui.acceptService("google_analytics");
biskoui.acceptService("youtube");

Parameters:

  • serviceId (string): Service key to accept (must match dashboard configuration)

Returns: void

Use case: Implement progressive consent flows, feature-specific opt-ins, or additive consent controls.


biskoui.hasAcceptedService(serviceId)

Checks if a specific service has been accepted by the user.

const hasAnalytics = biskoui.hasAcceptedService("google_analytics");
const hasMaps = biskoui.hasAcceptedService("google_maps");

Parameters:

  • serviceId (string): The service key to check (must match dashboard configuration)

Returns: boolean

  • true if the service has been explicitly accepted
  • false if the service has been declined or no decision has been made yet

Use case: Check current consent status to conditionally load services or show UI elements.

Events

Service Activation Events

Per-Service Events

Fired when a specific service becomes activated (either through new consent or existing consent on page load).

Event Name Pattern: biskoui:<service_key>_activated

window.addEventListener("biskoui:google_maps_activated", function (event) {
// Google Maps is now allowed to run
initGoogleMaps();
});

window.addEventListener("biskoui:youtube_activated", function (event) {
// YouTube embeds are now allowed
loadYouTubeEmbeds();
});

Event Detail: None

Timing: Fires once per page load per service. If consent already exists, fires after SDK initialization.

GTM / dataLayer Service Activation Event

For services configured with the Google Tag Manager (GTM) integration mode, biskoui pushes the configured activation event to window.dataLayer when the service is accepted:

window.dataLayer.push({
event: "biskoui_activate_facebook_pixel",
});

Event Name: biskoui_activate_<service_key> by default, or the custom activation event configured for the service.

Timing: Fires once per page load per accepted service. If the visitor has already accepted the service, the event fires during SDK initialization on every page load. If the visitor accepts the service on the current page, the event fires immediately after acceptance. The event is not fired on rejection and is deduplicated during a single page load.

Use this event as the primary GTM Custom Event trigger for tags that must only run after consent. For page-specific marketing events, combine the activation event with page URL or page-type trigger conditions instead of relying on GTM Tag Sequencing as the consent gate.

Initialization Events

GTM / dataLayer Ready Event

When Google Tag Manager is present, biskoui pushes a biskoui_ready event to window.dataLayer once the SDK has finished loading, the consent state has been loaded, and the public API is safe to use.

window.dataLayer.push({
event: "biskoui_ready",
acceptedServices: ["google_analytics", "google_maps"],
});

Data Layer Fields:

  • event ("biskoui_ready"): custom event name for GTM triggers
  • acceptedServices (string[]): service keys accepted at initialization time

Use this event as a GTM Custom Event trigger when a tag depends on biskoui being fully loaded. When biskoui_ready is emitted, window.biskoui is available and biskoui.hasAcceptedService(serviceKey) is synchronized with the acceptedServices payload. You do not need to add an arbitrary timeout before reading consent state.

Browser Ready Event

Fired when the biskoui SDK has finished loading and the public API is safe to use.

Event Name: biskoui:ready

window.addEventListener("biskoui:ready", function (event) {
console.log("Biskoui SDK is ready");
console.log("Accepted services:", event.detail.acceptedServices);

// All SDK methods are now available
const hasAnalytics = biskoui.hasAcceptedService("google_analytics");
});

Event Detail:

{
acceptedServices: string[];
}

Timing: Fires once per page load after the SDK has completed initialization and loaded the user's existing consent state. At this point all public API methods are safe to call.

Script Blocking

Automatic Script Execution

Scripts with type="text/plain" and data-biskoui attributes are automatically executed when their corresponding service is activated.

<script type="text/plain" data-biskoui="google_analytics">
gtag('config', 'GA_MEASUREMENT_ID');
</script>

<script type="text/plain" data-biskoui="facebook_pixel">
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>

Attributes

type="text/plain" (required)

  • Prevents the browser from executing the script initially

data-biskoui="<service_key>" (required)

  • Links the script to a specific service configured in your biskoui dashboard
  • Service key must match exactly (snake_case format)

Behavior

  • Scripts execute once per page load when their service is activated
  • Execution is idempotent - duplicate scripts are ignored
  • Scripts execute in document order
  • Works for any service key present in your biskoui configuration

Service Key Format

All service keys use snake_case format and must be consistent across:

  • Dashboard service configuration
  • Event names: biskoui:<service_key>_activated
  • Script blocking: data-biskoui="<service_key>"
  • State object: state.services.<service_key>

Common Service Keys

  • google_analytics
  • google_maps
  • youtube
  • vimeo
  • facebook_pixel
  • google_ads
  • hotjar

Service keys are available in the services page in your biskoui dashboard.