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/vue

v1.0.1

Published

Vue 3 cookie consent & CMP for ConsentX — GDPR, CCPA, DPDPA. Paste your Site Key and the widget installs itself.

Readme


@consentx/vue is the official ConsentX integration for Vue 3. It injects the self-contained ConsentX embed into your app and gives you a reactive useConsent() composable for the visitor's choice.

This package uses the Site Key model (Model C): there is no server-side redirect handshake. You copy your Site Key from the ConsentX dashboard (Websites → your site) and pass it to the plugin or component. Make sure your domain is on that site's allowlist in the dashboard (the dashboard "Add website" flow handles this). Then the embed loads and the banner appears.

Features

  • One self-contained embed — the widget injects its own CSS + JS and renders the banner into #consentx-cookie-consent.
  • <ConsentX> component + app.use() plugin + useConsent() composable.
  • Reactive consent state: granted category slugs, hasConsent('analytics').
  • Optional Google Consent Mode v2 denied-by-default seeding.
  • SPA-safe: the embed is injected after hydration so Vue's DOM reconciliation does not strip the widget node.
  • TypeScript types, ESM + CJS builds, Vue as a peer dependency. Zero runtime deps.

Install

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

Requires vue@^3.3.

Usage

1. Register the plugin (recommended)

// main.ts
import { createApp } from 'vue';
import { ConsentXPlugin } from '@consentx/vue';
import App from './App.vue';

createApp(App)
  .use(ConsentXPlugin, {
    siteKey: 'YOUR_SITE_KEY',   // ConsentX dashboard → Websites → your site
    consentMode: true,          // optional: seed Google Consent Mode v2 defaults
    // appHost: 'https://app.consentx.io', // override for staging / self-hosted
  })
  .mount('#app');

Then drop the component once near the root of your app (e.g. in App.vue). It inherits the Site Key from the plugin:

<template>
  <ConsentX />
  <RouterView />
</template>

2. Or configure it entirely on the component

No app.use() needed — import and register the component locally and pass the key as a prop:

<script setup lang="ts">
import { ConsentX } from '@consentx/vue';
</script>

<template>
  <ConsentX site-key="YOUR_SITE_KEY" :consent-mode="true" />
</template>

useConsent()

React to the visitor's consent choice anywhere in your component tree:

<script setup lang="ts">
import { watch } from 'vue';
import { useConsent } from '@consentx/vue';

const { granted, ready, hasConsent, openPreferences } = useConsent();

// Load analytics only after consent is granted for that category.
watch(
  () => hasConsent('analytics'),
  (allowed) => {
    if (allowed) loadAnalytics();
  },
);
</script>

<template>
  <button @click="openPreferences()">Cookie preferences</button>
  <p v-if="ready">Granted: {{ granted.join(', ') }}</p>
</template>

useConsent() subscribes to the widget's cx:consent event and automatically unsubscribes when the component unmounts. detail.granted is an array of granted category slugs.

API

ConsentXPlugin (default export)

app.use(ConsentXPlugin, options)

| Option | Type | Default | Description | | ------------------- | --------- | --------------------------- | ------------------------------------------------------------------ | | siteKey | string | '' | Default Site Key (overridable per component). | | appHost | string | https://app.consentx.io | App host override for staging / self-hosted ConsentX. | | consentMode | boolean | false | Seed Google Consent Mode v2 denied-by-default before the embed. | | registerComponent | boolean | true | Auto-register the global <ConsentX> component. | | componentName | string | ConsentX | Name used when auto-registering. |

<ConsentX> component

| Prop | Type | Default | Description | | ------------- | --------- | ------------------ | -------------------------------------------------------- | | site-key | string | plugin default | Site Key from the ConsentX dashboard. | | app-host | string | plugin default | App host override. | | consent-mode| boolean | plugin default | Seed Consent Mode v2 defaults before injecting. |

Emits @consent="(detail) => …" on every cx:consent event.

useConsent(onChange?)

Returns { consent, granted, ready, hasConsent, openPreferences } — all reactive refs except the two helper functions.

Low-level helpers

injectEmbed, injectConsentModeDefaults, embedSrc, isEmbedInjected, onConsent, openPreferences, normalizeDetail, plus the constants DEFAULT_APP_HOST, GLOBAL_KEY_VAR, MOUNT_ID, CONSENT_EVENT.

How the embed works

Under the hood the package appends one ES module to <head>:

<script type="module" src="https://app.consentx.io/api/YOUR_SITE_KEY/embed.js"></script>

embed.js is self-contained: it injects the scoped widget CSS + JS, renders the banner into a #consentx-cookie-consent div it appends to document.body, reads geo/config from the server, exposes window.ConsentX (open preferences), and emits the cx:consent event.

Build (contributors)

npm install
npm run build      # vite library build (ESM + CJS) + vue-tsc d.ts
npm run typecheck

License

MIT © ConsentX