JavaScript API v3

|

Indhold

Bemærk:
Dette indhold er desværre ikke tilgængeligt på dit sprog i øjeblikket. Lige nu kan du kun læse det på engelsk. Tak for din forståelse!

This documentation is intended for developers with extensive JavaScript knowledge.

Content Blockers

JavaScript Types

ContentBlockerItem

ContentBlockerItem {
  description: string;
  hosts: string[];
  id: string;
  javaScriptGlobal: string;
  javaScriptInitialization: string;
  name: string;
  providerId: string;
  serviceId: string | null;
}

Content Blocker Information by Content Blocker ID

window.BorlabsCookie.ContentBlocker.findByContentBlockerId(contentBlockerId: string): ContentBlockerItem | null

Dialog

Reopen the Dialog

There is no JavaScript API function available to reopen the dialog.

As an alternative, you can use the CSS class borlabs-cookie-open-dialog-preferences. This class can be assigned to any HTML element. Once assigned, Borlabs Cookie automatically registers a click event for that element.

<span class="borlabs-cookie-open-dialog-preferences" data-borlabs-cookie-title="Lorem ipsum"></span>

Consents

Grant Consent for a Service

window.BorlabsCookie.Consents.addConsent(serviceId: string, serviceGroupId: string): boolean

Check Consent for a Service

window.BorlabsCookie.Consents.hasConsent(serviceId: string, serviceGroupId?: string): boolean

Check Consent for a Service Group

window.BorlabsCookie.Consents.hasConsentForServiceGroup(serviceGroupId: string): boolean

Events

borlabs-cookie-after-init

This event is triggered after Borlabs Cookie has initialized all core components. It fires before it is determined whether the dialog should be displayed and before any opt-in code is executed or blocked content is unblocked.

window.addEventListener('borlabs-cookie-after-init', () => {});

borlabs-cookie-before-content-unblocked[{key}]

This event is triggered before a Content Blocker is unblocked. The detail object contains the initiator property, which has either the value unblock-button or accept-service-button. Available since Borlabs Cookie version 3.4.

window.addEventListener('borlabs-cookie-before-content-unblocked[youtube-content-blocker]', function (e) {
  console.log(`The clicked button (initiator) was: ${e.detail.initiator}`);
});

borlabs-cookie-consent-saved

This event is triggered after a consent change has been made and the consent cookie has been updated. It is fired before blocked code is unblocked.

window.addEventListener('borlabs-cookie-consent-saved', () => {});

borlabs-cookie-content-unblocked[{key}]

This event is triggered after a Content Blocker has been unblocked. The unblocked element is available in target. Available since Borlabs Cookie version 3.4.

window.addEventListener('borlabs-cookie-content-unblocked[youtube-content-blocker]', function (e) {
  console.log("The content was unblocked", e.target);
});

borlabs-cookie-dialog-closing

This event is triggered shortly before the dialog is closed. Available since Borlabs Cookie version 3.4.

window.addEventListener('borlabs-cookie-dialog-closing', () => {});

borlabs-cookie-dialog-opening

This event is triggered shortly before the dialog is opened. Available since Borlabs Cookie version 3.4.

window.addEventListener('borlabs-cookie-dialog-opening', () => {});

borlabs-cookie-handle-unblock

This event is triggered when the unblocking of blocked code is performed.

window.addEventListener('borlabs-cookie-handle-unblock', () => {});

The borlabs-cookie-consent-saved event also executes the same unblocking routines that are triggered by borlabs-cookie-handle-unblock.

The borlabs-cookie-consent-saved event also executes the same unblocking routines that are triggered by borlabs-cookie-handle-unblock.

window.BorlabsCookie.Unblock.unblockServiceOptInCode();
window.BorlabsCookie.Unblock.unblockInlineCode('service-group');
window.BorlabsCookie.Unblock.unblockInlineCode('service');
window.BorlabsCookie.Unblock.unblockByContentBlockerServiceConsents();

These functions are intended exclusively for Borlabs Cookie and are therefore not documented further.

Logs

Logs in Chronological Order

window.BorlabsCookie.Log.logsChronical

Logs by Log Level

window.BorlabsCookie.Log.logs

Providers

JavaScript Types

ProviderItem

ProviderItem {
  address: string;
  contentBlockerIds: string[];
  cookieUrl: string;
  description: string;
  iabVendorId: number | null;
  id: string;
  name: string;
  optOutUrl: string;
  partners: string;
  privacyUrl: string;
  serviceIds: string[];
}

Provider Information by Content Blocker ID

window.BorlabsCookie.Providers.findByContentBlockerId(contentBlockerId: string): ProviderItem | null

Provider Information by IAB TCF Vendor ID

window.BorlabsCookie.Providers.findByIabVendorId(iabVendorId: number): ProviderItem | null

Provider Information by Provider ID

window.BorlabsCookie.Providers.findByProviderId(providerId: string): ProviderItem | null

Provider Information by Service ID

window.BorlabsCookie.Providers.findByServiceId(serviceId: string): ProviderItem

Script Blockers

Unblock by Script Blocker ID

window.BorlabsCookie.Unblock.unblockScriptBlockerId(scriptBlockerId: string): boolean

Services

JavaScript Types

ServiceCookie

 ServiceCookie {
  description: string;
  hostname: string;
  lifetime: string;
  name: string;
  purpose: string;
  type: string;
}

ServiceItem

ServiceItem {
  cookies: ServiceCookie[];
  description: string;
  hosts: ServiceHost[];
  id: string;
  name: string;
  optInCode: string;
  optOutCode: string;
  options: ServiceOption[];
  providerId: string;
  serviceGroupId: string;
  settings: Record;
}

ServiceList

ServiceList = Record

ServiceOption

ServiceOption {
  name: string;
  type: string;
}

Service Information by Provider ID

window.BorlabsCookie.Services.findByProviderId(providerId: string): ServiceList

Service Information by Service ID

window.BorlabsCookie.Services.findByServiceId(serviceId: string): ServiceItem

Service Information by Service Group ID

window.BorlabsCookie.Services.findByServiceGroupId(serviceGroupId: string): ServiceList

Service Groups

JavaScript Types

ServiceGroupItem

ServiceGroupItem {
  description: string;
  id: string;
  name: string;
  preSelected: boolean;
  serviceIds: string[];
}

Service Group Information by Service Group ID

window.BorlabsCookie.ServiceGroups.findByServiceGroupId(serviceGroupId: string): ServiceGroupItem

Style Blocker

Unblock by Style Blocker ID

window.BorlabsCookie.Unblock.unblockStyleBlockerId(styleBlockerId: string): void

Tools

cloneObject

Clones a JavaScript object without references.

window.BorlabsCookie.Tools.cloneObject(obj: any): any

inArray

JavaScript equivalent of PHP's in_array()-function.

window.BorlabsCookie.Tools.inArray(needle: number | string, haystack: Array)

onExist

This method is intended for executing code that depends on external JavaScript loaded asynchronously during the unblocking process. To prevent errors caused by race conditions, this helper function checks whether the specified obj exists before executing the callback function passed to it.

window.BorlabsCookie.Tools.onExist(obj: any, callback: Function): void

Var denne artikel nyttig?

Nyttig
Ikke nyttig

Kunne du ikke finde det, du ledte efter? Vores supportteam er klar til at hjælpe.