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

tinyconsent-webcomponent

v1.0.1

Published

Web Component for TinyConsent cookie consent banners. Use <tiny-consent> in any HTML page or framework.

Readme

tinyconsent-webcomponent

npm version License: MIT TypeScript

Cookie consent banner as a Web Component. Works in any HTML page or framework.

A framework-agnostic Web Component for adding TinyConsent cookie consent banners. Use <tiny-consent> anywhere - vanilla HTML, Vue, Angular, Svelte, or any other framework.

Why TinyConsent Web Component?

  • 🌐 Framework agnostic - Works everywhere: HTML, Vue, Angular, Svelte, etc.
  • 🚀 One element - Just <tiny-consent script-id="..." />
  • 📦 Tiny - Under 1KB, loads the actual banner async
  • Cookie consent handling - Loads your TinyConsent banner and lets you wire consent into your tracking scripts
  • 🔧 Designed for Google Consent Mode v2 - Works with GA4-style implementations
  • 🎨 Customizable - Configure via dashboard, no code changes
  • 🔌 Auto-registers - Just import and use

Get your script ID: tinyconsent.com/cookie-banner-generator

Installation

npm install tinyconsent-webcomponent
yarn add tinyconsent-webcomponent
pnpm add tinyconsent-webcomponent

Or use via CDN:

<script type="module">
  import 'https://esm.sh/tinyconsent-webcomponent';
</script>

Quick Start

HTML

<!DOCTYPE html>
<html>
<head>
  <script type="module">
    import 'tinyconsent-webcomponent';
  </script>
</head>
<body>
  <tiny-consent script-id="your-script-id"></tiny-consent>
  
  <!-- Your content -->
</body>
</html>

CDN (No Build Step)

<!DOCTYPE html>
<html>
<head>
  <script type="module">
    import 'https://esm.sh/tinyconsent-webcomponent';
  </script>
</head>
<body>
  <tiny-consent script-id="your-script-id"></tiny-consent>
</body>
</html>

That's it! Your cookie consent banner will appear automatically.

What It Does

The <tiny-consent> element injects:

<script src="https://scripts.tinyconsent.com/api/scripts/your-script-id" async></script>

No internal logic, no bloat - just loads your cookie banner script on connectedCallback.

API Reference

<tiny-consent> Element

| Attribute | Type | Default | Description | |-----------|------|---------|-------------| | script-id | string | Required | Your TinyConsent script ID | | async | string | "true" | Load script asynchronously | | defer | string | "false" | Defer script execution |

Events

| Event | Detail | Description | |-------|--------|-------------| | load | - | Fired when script loads | | error | Error | Fired if script fails to load |

const consent = document.querySelector('tiny-consent');
consent.addEventListener('load', () => console.log('Banner loaded!'));
consent.addEventListener('error', (e) => console.error(e.detail));

JavaScript API

import { registerTinyConsent, getTinyConsentScriptUrl } from 'tinyconsent-webcomponent';

// Register with custom tag name (optional)
registerTinyConsent('my-cookie-banner');

// Get script URL
const url = getTinyConsentScriptUrl('your-script-id');

Programmatic Creation

const consent = document.createElement('tiny-consent');
consent.setAttribute('script-id', 'your-script-id');
document.body.appendChild(consent);

Framework Examples

Vue.js

<template>
  <div>
    <tiny-consent script-id="your-script-id"></tiny-consent>
    <!-- Your app -->
  </div>
</template>

<script setup>
import 'tinyconsent-webcomponent';
</script>

Angular

// app.module.ts
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import 'tinyconsent-webcomponent';

@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  // ...
})
export class AppModule {}
<!-- app.component.html -->
<tiny-consent script-id="your-script-id"></tiny-consent>

Svelte

<script>
  import 'tinyconsent-webcomponent';
</script>

<tiny-consent script-id="your-script-id"></tiny-consent>

Lit

import { LitElement, html } from 'lit';
import 'tinyconsent-webcomponent';

class MyApp extends LitElement {
  render() {
    return html`
      <tiny-consent script-id="your-script-id"></tiny-consent>
      <div>My App</div>
    `;
  }
}

Plain HTML with Events

<tiny-consent 
  script-id="your-script-id"
  id="cookie-consent"
></tiny-consent>

<script type="module">
  import 'tinyconsent-webcomponent';
  
  const consent = document.getElementById('cookie-consent');
  
  consent.addEventListener('load', () => {
    console.log('Cookie banner is ready!');
  });
  
  consent.addEventListener('error', (event) => {
    console.error('Failed to load banner:', event.detail);
  });
</script>

Cookie Banners vs. Full Compliance

What a Cookie Banner Does

A cookie banner handles the consent collection part of privacy compliance:

  • Displays a notice about cookies and tracking
  • Collects user consent preferences
  • Blocks non-essential scripts until consent is given
  • Stores consent choices

What Full Compliance Requires

Cookie consent is just one part of privacy law compliance. Full compliance also includes:

  • Privacy Policy - Document explaining your data practices
  • Data Processing Records - Internal documentation
  • User Rights Handling - Ability to handle data access/deletion requests
  • Legal Basis - Proper justification for data processing

TinyConsent helps with cookie consent. For your privacy policy, use: tinyconsent.com/privacy-policy-generator

GDPR Cookie Consent Requirements

The GDPR (General Data Protection Regulation) requires:

  1. Prior consent - Get consent BEFORE setting non-essential cookies
  2. Informed consent - Tell users what cookies do
  3. Granular options - Let users choose cookie categories
  4. Easy withdrawal - Make it easy to change preferences
  5. No pre-ticked boxes - Consent must be affirmative

Learn more: GDPR Cookie Requirements

CCPA Requirements

The CCPA (California Consumer Privacy Act) requires:

  1. Notice at collection - Disclose what data you collect
  2. Opt-out right - "Do Not Sell My Personal Information" option
  3. Non-discrimination - Can't penalize users who opt out

Learn more: CCPA Cookie Requirements

FAQ

How do I get a script ID?

  1. Visit tinyconsent.com/cookie-banner-generator
  2. Enter your email
  3. Copy your script ID

Does this work with all frameworks?

Yes! Web Components work in any framework: React, Vue, Angular, Svelte, Lit, or plain HTML.

Does it block tracking scripts?

Yes. TinyConsent blocks Google Analytics, Facebook Pixel, and other trackers until the user consents.

Does it support Google Consent Mode v2?

Yes. Google Consent Mode is automatically integrated.

Can I customize the banner appearance?

Yes! All customization is done in your TinyConsent Dashboard.

Do I need a privacy policy?

Yes, privacy regulations require one. Generate yours: tinyconsent.com/privacy-policy-generator

Is a cookie banner enough for GDPR compliance?

No. A cookie banner handles consent collection, but full GDPR compliance requires a privacy policy, data processing records, and more. TinyConsent helps with the cookie consent part.

Troubleshooting

Element not recognized

Make sure you import the module before using the element:

<script type="module">
  import 'tinyconsent-webcomponent';
</script>

Banner not appearing

  1. Check your script ID is correct
  2. Ensure the import is loading (check Network tab)
  3. Test in incognito mode
  4. Check browser console for errors

TypeScript types not found

The package includes TypeScript definitions. If you have issues:

/// <reference types="tinyconsent-webcomponent" />

Vue/Angular custom element warnings

Configure your framework to recognize custom elements:

Vue 3:

// vite.config.js
export default {
  vue: {
    compilerOptions: {
      isCustomElement: tag => tag === 'tiny-consent'
    }
  }
}

Angular:

@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})

TypeScript

Full TypeScript support:

import { 
  TinyConsentElement,
  registerTinyConsent,
  getTinyConsentScriptUrl,
  TinyConsentAttributes
} from 'tinyconsent-webcomponent';

// Type the element
const element = document.querySelector('tiny-consent') as TinyConsentElement;
console.log(element.loaded); // boolean

Related Packages

Resources

License

MIT © TinyConsent


Keywords: cookie banner, cookie consent, web component, custom element, GDPR, CCPA, cookie banner generator, cookie consent script, one line cookie banner, lightweight cookie consent, cookie banner npm, vanilla js, framework agnostic, privacy, consent management