npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@consentx/angular

v1.0.1

Published

ConsentX cookie consent & CMP for Angular — GDPR, CCPA, DPDPA. Inject the ConsentX embed and read consent state from a service. Site-key model, no server handshake.

Readme

@consentx/angular

Cookie consent & CMP for Angular — GDPR, CCPA, DPDPA.

Drop ConsentX into any Angular app. The package injects the ConsentX embed into <head> on app init and gives you a service to read the visitor's consent state reactively. No backend, no redirect handshake — you supply your Site Key and the banner installs itself.

  • Renders the ConsentX banner (the widget appends #consentx-cookie-consent to document.body and reads geo/config from the server).
  • Exposes consent decisions via the cx:consent event as Angular observables.
  • Optional Google Consent Mode v2 denied-by-default defaults.
  • SSR-safe (Angular Universal): no-op on the server, injects after browser boot.
  • Works with both NgModule and standalone (bootstrapApplication) apps.

How connect works (site-key model)

ConsentX for Angular uses the site-key model (Model C in the ConsentX Connect spec). There is no server-side OAuth-style redirect:

  1. In the ConsentX dashboard go to Websites → your site and copy the Site Key.
  2. Make sure your site's domain is on that website's allowlist (the dashboard "Add website" flow handles this).
  3. Pass the Site Key to ConsentXModule.forRoot() / provideConsentX().

That's it — the embed (https://app.consentx.io/api/SITE_KEY/embed.js) loads on app init and the banner appears.


Install

npm install @consentx/angular
# or
yarn add @consentx/angular
# or
pnpm add @consentx/angular

Peer dependencies: @angular/core, @angular/common (>= 15), rxjs (>= 7).


Usage

Standalone apps (bootstrapApplication)

// main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { provideConsentX } from '@consentx/angular';
import { AppComponent } from './app/app.component';

bootstrapApplication(AppComponent, {
  providers: [
    provideConsentX({ siteKey: 'YOUR_SITE_KEY' }),
  ],
});

NgModule apps

// app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ConsentXModule } from '@consentx/angular';
import { AppComponent } from './app.component';

@NgModule({
  imports: [
    BrowserModule,
    ConsentXModule.forRoot({ siteKey: 'YOUR_SITE_KEY' }),
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

The embed is injected automatically on app init. There is no component to add to your template — the ConsentX widget mounts itself into #consentx-cookie-consent on document.body.


Reading consent state

Inject ConsentXService anywhere and react to the visitor's choice:

import { Component } from '@angular/core';
import { AsyncPipe, NgIf } from '@angular/common';
import { ConsentXService } from '@consentx/angular';

@Component({
  selector: 'app-analytics',
  standalone: true,
  imports: [AsyncPipe, NgIf],
  template: `
    <div *ngIf="analyticsAllowed$ | async">
      <!-- analytics-dependent UI -->
    </div>
    <button (click)="consentx.openPreferences()">Cookie settings</button>
  `,
})
export class AnalyticsComponent {
  // Stream of granted category slugs, e.g. ['analytics', 'marketing'].
  readonly granted$ = this.consentx.granted$;

  readonly analyticsAllowed$ = this.consentx.state$;

  constructor(public consentx: ConsentXService) {
    this.consentx.granted$.subscribe((granted) => {
      if (granted.includes('analytics')) {
        // load your analytics SDK here
      }
    });
  }
}

Synchronous accessors are available too:

this.consentx.hasConsent('analytics'); // boolean
this.consentx.getGranted();            // string[]
this.consentx.getState();              // { loaded, decided, granted, detail }

Configuration

provideConsentX(config) and ConsentXModule.forRoot(config) accept:

| Option | Type | Default | Description | | ------------- | --------- | --------------------------- | -------------------------------------------------------------------------------------------- | | siteKey | string | — (required) | Your ConsentX Site Key (dashboard → Websites → your site). | | appUrl | string | https://app.consentx.io | Override the ConsentX app host (e.g. staging). | | consentMode | boolean | false | Print the Google Consent Mode v2 denied-by-default stub before any analytics tag fires. | | manualLoad | boolean | false | Skip auto-injection on init; call consentx.load() yourself at a custom point. |

Google Consent Mode v2

provideConsentX({ siteKey: 'YOUR_SITE_KEY', consentMode: true });

The denied-by-default defaults are pushed to dataLayer before the embed loads. The ConsentX widget then emits the gtag('consent','update',…) calls on the visitor's choice.

Staging / self-hosted host

provideConsentX({
  siteKey: 'YOUR_SITE_KEY',
  appUrl: 'https://consentx1.satyamrastogi.com',
});

Manual / deferred load

provideConsentX({ siteKey: 'YOUR_SITE_KEY', manualLoad: true });
// ...later, e.g. inside a route guard or after consent UX is mounted:
this.consentx.load();

Service API

| Member | Returns | Description | | ---------------------------- | ---------------------- | ------------------------------------------------------------------ | | state$ | Observable<State> | Full consent state stream. | | granted$ | Observable<string[]> | Granted category slugs (distinct). | | getState() | ConsentXState | Synchronous full snapshot. | | getGranted() | string[] | Synchronous granted slugs. | | hasConsent(slug) | boolean | Whether a given category is granted. | | load() | void | Inject the embed (idempotent). | | openPreferences() | boolean | Re-open the ConsentX preferences dialog (window.ConsentX.open). |

ConsentXState is { loaded, decided, granted, detail }.


SSR (Angular Universal)

The service guards every DOM call behind isPlatformBrowser, so on the server it is a no-op. The embed is injected via APP_INITIALIZER, which runs after the app boots in the browser — the SPA-safe load point that prevents Angular's DOM reconciliation from stripping the appended #consentx-cookie-consent div.


Build

npm install
npm run build   # ng-packagr → ./dist

The build produces an Angular Package Format (APF) distributable in dist/, publishable to npm.


License

MIT © ConsentX