Skip to content
This repository has been archived by the owner on May 5, 2020. It is now read-only.

Latest commit

 

History

History
82 lines (61 loc) · 2.57 KB

README.md

File metadata and controls

82 lines (61 loc) · 2.57 KB

ngx-gtm-cookie-consent

npm Build Status Quality Gate Status

An Angular library to comply with the GDPR and the latest european law regarding cookies 🍪

This project is work-in-progress. Features and Documentation are probably not complete.

Usage

  1. Install dependencies

npm install --save ngx-gtm-cookie-consent ngx-cookieconsent cookieconsent

or

yarn add ngx-gtm-cookie-consent ngx-cookieconsent cookieconsent

  1. Add the following to your angular.json:
{
    "assets": [
        {
            "glob": "**/cookie-consent.js",
            "input": "node_modules/ngx-gtm-cookie-consent/static/js",
            "output": "./ngx-gtm-cookie-consent"
        }
    ],
    "styles": [
        "node_modules/cookieconsent/build/cookieconsent.min.css",
        "node_modules/ngx-gtm-cookie-consent/static/css/main.css"
    ],
    "scripts": [
        "node_modules/cookieconsent/build/cookieconsent.min.js"
    ]
}
  1. Add a script in your index.html head section:
<script src="ngx-gtm-cookie-consent/cookie-consent.js"></script>
  1. Create a cookieConfig object (see ngx-cookieconsent)

  2. Add imports to your AppModule:

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    NgcCookieConsentModule.forRoot(cookieConfig),
    CookieModule.forRoot({
      gtmContainerId: 'GTM-XXXYYY', // Your Google Tag Manager container ID
      enable: true, // Control this from your environment files
      cookieConsentPopUpConfig: cookieConfig
    })
  ]
})
export class AppModule { }
  1. Create a new trigger in Google Tag Manager

Trigger

  1. Use the new trigger to fire tags (e.g. for Google Analytics)

Tag

i18n support

You can change the content of the cookie banner after the initial setup, for example to react to a locale change by the user. The CookieConsentService provides the function setCookieConsentConfig() which can be used to provide an updated config object.