4.0.0 • Published 26 days ago

@halloverden/ngx-cookiebot v4.0.0

Weekly downloads
19
License
MIT
Repository
github
Last release
26 days ago

NgxCookiebot

An Angular wrapper around the Cookiebot SDK.

Angular support

VersionAngular support
^4.0.0^17.0.0
^3.0.0^16.0.0
2.3.08.2.14 - 15

Installation

npm i @halloverden/ngx-cookiebot -S

Setup

Prerequisites

A Cookiebot account.

1. Configure service

Configure the service according to the Cookiebot developer docs. The package also ships with custom config not defined in the Cookiebot developer docs. See below for deets.

// cookiebot.config.ts
import { NgxCookiebotConfig } from '@halloverden/ngx-cookiebot';

export class CookiebotConfig extends NgxCookiebotConfig {
  blockingMode: 'auto' | 'manual' | string;
  consentMode?: 'disabled';
  cbId: string;
  cdn: 'com' | 'eu' | string;
  culture?: string;
  framework?: string;
  level?: string;
  loadScript: boolean;
  type?: string;
  widgetEnabled?: boolean;
  widgetPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | string;
  widgetDistanceVertical?: number;
  widgetDistanceHorizontal?: number;
}

Custom config

In addition to the config defined in the Cookiebot developer docs, the package also supports this custom config:

cdn

Choose what version of the cookiebot CDN you want to use (https://support.cookiebot.com/hc/en-us/articles/4530208762396-Cookiebot-CMP-European-CDN-solution):

ConfigCDN
comconsent.cookiebot.com
euconsent.cookiebot.eu
loadScript

The package injects the script in the head tag through Angular. This can lead to high script loading time. If your app is time sensitive, you can opt out of the package setting the script tag, and set it yourself. You can use the module for everything else but the script embedding.

NB! If you set this config to false, no other config parameter will have effect, and you need to config them yourself.

2. Import package

// app.module.ts
import { NgxCookiebotModule } from '@halloverden/ngx-cookiebot';
import { CookiebotConfig } from '@config/cookiebot.config';

@NgModule({
  imports: [
    NgxCookiebotModule.forRoot(CookiebotConfig)
  ]
})

Usage

Consent box

The script will now automatically append itself to the head tag, which in turn will prompt the cookie consent box.

To interact with the "cookiebot" object, NgxCookiebot comes with a service that exposes it, which is ready for use after the service is ready (the script is injected):

// whatever.ts
...
constructor(private _cookieBotService: NgxCookiebotService) {}
...
this._cookieBotService.onServiceReady$.pipe(
  filter((ready: boolean) => {
    return ready;
  })
).subscribe(() => {
  // this._cookieBotService.cookiebot is available
});
...

Reference the Cookiebot docs for a list of properties, methods and callbacks available through the cookiebot object.

If you prefer to use observables, the NgxCookiebotService exposes an observable for every available method and callback on the cookiebot object:

Methods

MethodObservable
CookiebotOnConsentReadyonConsentReady$
CookiebotOnLoadonLoad$
CookiebotOnAcceptonAccept$
CookiebotOnDeclineonDecline$
CookiebotOnDialogInitonDialogInit$
CookiebotOnDialogDisplayonDialogDisplay$
CookiebotOnTagsExecutedonTagsExecuted$

Callbacks

CallbackObservable
CookiebotCallback_OnLoadonLoadCallback$
CookiebotCallback_OnAcceptonAcceptCallback$
CookiebotCallback_OnDeclineonDeclineCallback$
CookiebotCallback_OnDialogInitonDialogInitCallback$
CookiebotCallback_OnDialogDisplayonDialogDisplayCallback$
CookiebotCallback_OnTagsExecutedonTagsExecutedCallback$

Usage example:

// whatever.ts
...
this._cookieBotService.onConsentReady$.subscribe(
  // Consent ready
  console.log(this._cookieBotService.cookiebot.consent)
)
...

Cookie declaration

The NgxCookiebot package exposes a component to insert the cookie consent declaration. Use the component where you want the declaration to appear:

// my.component.html

<ngx-cookiebot-declaration></ngx-cookiebot-declaration>

License

MIT © Hallo Verden

4.0.0

26 days ago

3.1.0

6 months ago

3.1.0-rc.1

9 months ago

3.0.0-rc.1

12 months ago

3.0.0

12 months ago

2.3.0-rc.1

1 year ago

2.1.0-rc.1

1 year ago

2.3.0

1 year ago

2.2.0

1 year ago

2.1.0

1 year ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.2-rc.2

2 years ago

2.0.2-rc.1

2 years ago

2.0.0-rc.2

2 years ago

2.0.0-rc.3

2 years ago

2.0.0-rc.4

2 years ago

2.0.0-rc.5

2 years ago

2.0.0-rc.1

2 years ago

2.0.0

2 years ago

1.2.0-rc.1

2 years ago

1.1.0

2 years ago

1.1.0-rc.1

2 years ago

1.0.10-rc.1

2 years ago

1.0.10

2 years ago

1.0.9

3 years ago

1.0.9-rc.1

3 years ago

1.0.8

3 years ago

1.0.8-rc.1

3 years ago

1.0.7

3 years ago

1.0.7-rc.11

3 years ago

1.0.7-rc.9

3 years ago

1.0.7-rc.10

3 years ago

1.0.7-rc.8

3 years ago

1.0.7-rc.7

3 years ago

1.0.7-rc.6

3 years ago

1.0.7-rc.5

3 years ago

1.0.7-rc.3

3 years ago

1.0.7-rc.4

3 years ago

1.0.7-rc.1

3 years ago

1.0.7-rc.2

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago