Home

Awesome

@localia/ngx-cookie-consent

Angular multi-language module to display a cookie consent banner without other dependencies.

Open in Codeflow

Works since Angular v14!
Available languages: English, German, Italian, Portuguese, Francais and custom language ready.

Versions

VersionAngular Version
v1.1.0Angular v14 (not maintained)
v1.2.0Angular v15 (not maintained)
v1.3.0Angular v16 (not maintained)
v2.0.0Angular v17 (not maintained)
v3.0.0+Angular v18 maintained

Installation

Install the package via npm:

npm install @localia/ngx-cookie-consent --save

Install the package with yarn:

yarn add @localia/ngx-cookie-consent

Usage

Import the module

import { NgxCookieConsentModule } from '@localia/ngx-cookie-consent';

// use your configuration or leave it empty
// const cookieConfig = {};

@NgModule({
    imports: [
        // using own configuration pass the config object  
        NgxCookieConsentModule.forRoot(),
    ],
})

Add the cookie consent component to your template at the top for all pages eg. app.component.html

<ngx-cookie-consent></ngx-cookie-consent>
<router-outlet></router-outlet>

Usage in templates to check if the user has accepted the cookie consent

<div *ngxIfConsent="'functional_google_maps'">
    This content is only visible if functional_google_maps consent is given.
    (In this example functional_google_maps is the name of the cookie configured in the config object)
</div>

Configuration

NameTypeDefaultDescription
privacyPolicyUrlstring | TranslatableString'#'URL to your privacy policy ⚠ required ⚠
imprintUrlstring | TranslatableString'#'URL to your imprint ⚠ required ⚠
defaultLanguagestring'en'Default language for the cookie consent banner
availableLanguagesstring[]['en', 'de', 'it']Available languages for the cookie consent banner
customLanguageCustomLanguageConfig | nullnullCustom language for the cookie consent banner
showLanguageSwitcherbooleantrueShow language switcher
showBadgeOpenerbooleantrueShow badge opener
openerPositionenum'left-bottom'Position of the badge eg. 'left-top', 'right-top' , 'left-bottom' , 'right-bottom'
customOpenerClassstring''Custom class for the badge opener
customClassstring''Custom class for the cookie consent banner
cookiePrefixstring'cookieconsent_'Prefix for the cookie consent banner
cookieExpiryDaysnumber365Expiry days for the cookie consent banner
showCookieDetailsbooleanfalseShow cookie details
showFunctionalCookiesbooleantrueShow functional cookies
functionalCookiesCookieItem[][]Functional cookies
showMarketingCookiesbooleantrueShow marketing cookies
marketingCookiesCookieItem[][]Marketing cookies
showEssentialCookiesbooleantrueShow essential cookies
essentialCookiesCookieItem[][]Essential cookies
showOtherToolsbooleantrueShow other tools
otherToolsCookieItem[][]Other tools
excludeRoutesstring[][]Exclude routes eg. ['/privacy-policy']

CustomLanguageConfig interface

NameTypeDescription
languageKeystringKey for the custom language eg. 'custom'
languageNamestringName for the custom language eg. 'Custom'
customIconPathstring | nullPath to the custom icon eg. 'assets/images/custom-icon.svg'
translationstranslations: { [key: string]: string };Translations for the custom language as object please copy a example in languages folder.

CookieItem interface

NameTypeDescription
keystringKey for the cookie eg. 'functional_google_analytics'
namestring | TranslatableStringName for the cookie eg. 'Google Analytics'
descriptionstring | TranslatableStringDescription for the cookie eg. 'Google Analytics is a web analytics service offered by Google that tracks and reports website traffic.'
privacyPolicyUrlstring | TranslatableStringURL to the privacy policy for the cookie eg. 'https://policies.google.com/privacy'
cookiesCookieDetail[]Cookie details for the cookie

CookieDetail interface

NameTypeDescription
namestringName for the saved cookie eg. '_ga'
descriptionstring | TranslatableStringDescription for the saved cookie eg. 'This cookie is used to distinguish users.'
durationstring | TranslatableStringDuration for the saved cookie eg. '2 years'

TranslatableString interface

The TranslatableString interface is used to define a string that can be translated into multiple languages. It is optional to use this interface. If you don't use it, the string will be used as it is.

⚠ The TranslatableString interface if used, will automatically fall back to defaultLanguage used if no translation key defined for the desired language.

NameTypeDescription
enstringEnglish string for the specified key
destringGerman string for the specified key
itstringItalian string for the specified key
ptstringPortuguese string for the specified key
frstringFrancais string for the specified key

Contributing

This project has a maintainer that actively monitors its issue queue and responds in a timely manner. This means that bug reports, tasks, feature requests and support request posted in the project's issue should receive timely attention from project's maintainers. Other community members are also welcome to resolve issues posted to the issue queue.

License

ngx-cookie-consent is licensed under the MIT license.