
Security News
MCP Steering Committee Launches Official MCP Registry in Preview
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
@owntag/consent
Advanced tools
A lightweight, customizable cookie consent banner, as currently in use on owntag.eu. Feel free to use it as well or as a starting point for your own implementation.
npm install owntag-consent
Using owntag-consent
is designed to be as simple as possible. Just import the ConsentBanner
class and instantiate it. The banner will automatically handle its own CSS injection and will appear for new visitors without any extra effort.
import { ConsentBanner } from 'owntag-consent';
new ConsentBanner({
logo: '/path/to/your/logo.svg',
title: 'Cookie Settings',
description: 'We use cookies to improve your experience. Please select your preferences below.',
// For a full list of configuration options, please refer to the source.
});
Once instantiated, the consent banner exposes a global API through window.owntagCMP
that allows you to interact with the consent state programmatically.
Method | Description | Returns |
---|---|---|
show() | Shows the consent banner | void |
hide() | Hides the consent banner | void |
getConsents() | Returns an array of consented service IDs | string[] |
setConsents(consents) | Sets the consent state for services | void |
clear() | Clears all consents and shows the banner | void |
hasFullConsent() | Checks if user has consented to all categories and services | boolean |
runWithFullConsent(callback) | Executes callback only if user has full consent | void |
The banner provides specialized methods to handle scenarios where you need complete user consent across all categories and services.
hasFullConsent()
Returns true
if the user has consented to all services across all categories (both essential and non-essential).
if (window.owntagCMP.hasFullConsent()) {
console.log('User has given complete consent!');
// Initialize privacy-sensitive features
}
runWithFullConsent(callback)
Executes the provided callback function only if the user has given full consent. If full consent hasn't been achieved yet, the callback is queued and will execute immediately when the user grants full consent (e.g., by clicking "Accept All"). This is useful for conditionally loading third-party scripts, analytics, or other privacy-sensitive code.
// This code runs when user has consented to everything
// If called before consent: queued until user clicks "Accept All"
// If called after consent: executes immediately
window.owntagCMP.runWithFullConsent(() => {
// Load third-party tracking scripts
loadGoogleAnalytics();
loadFacebookPixel();
// Initialize advanced features
initializeChatWidget();
loadPersonalizationEngine();
});
Full consent means:
Queue callbacks early (recommended):
// Call this anywhere in your code - callbacks are automatically queued
window.owntagCMP.runWithFullConsent(() => {
// Runs immediately if consent exists, or when user grants consent
initializeAdvancedTracking();
loadThirdPartyScripts();
});
Check on page load:
document.addEventListener('DOMContentLoaded', () => {
window.owntagCMP.runWithFullConsent(() => {
// This runs immediately if user previously gave full consent
initializeAllFeatures();
});
});
React to consent changes:
document.addEventListener('consentBanner.accept', (event) => {
// Check if this accept action resulted in full consent
if (window.owntagCMP.hasFullConsent()) {
initializeAdvancedTracking();
}
});
git clone https://github.com/your-username/owntag-consent.git
cd owntag-consent
npm install
To see the consent banner in action, run the demo:
npm run demo
This will start a local development server. Open the URL provided in your terminal to see the banner in action.
To run the test suite:
npm test
This project is licensed under the MIT License.
The consent banner uses several modern CSS features to ensure complete isolation from host websites:
all: initial
for complete style resetcontain: layout style paint
for performance isolation!important
declarations to override any conflicting stylesThe ConsentBanner
can be configured by passing an object to the constructor. Below is a list of all available options:
Option | Type | Default | Description |
---|---|---|---|
logo | string | '/vite.svg' | The path to your logo file. |
title | string | (i18n) | The main title of the banner. Overrides the i18n value. |
description | string | (i18n) | The main description text of the banner. Overrides the i18n value. |
cookieName | string | 'owntag_consent' | The name of the cookie used to store consent preferences. |
cookiePath | string | '/' | The path for the consent cookie. |
cookieDomain | string | (auto-detect) | The domain for the consent cookie. Defaults to the eTLD+1 of the current host. |
activeColor | string | '#4F46E5' | The accent color used for buttons and toggles. |
footer | string | undefined | Custom HTML to be rendered in the footer of the banner. |
imprintUrl | string | undefined | URL for the Imprint link. If provided, the link will be displayed. |
privacyPolicyUrl | string | undefined | URL for the Privacy Policy link. If provided, the link will be displayed. |
categories | array | (see default) | An array of consent categories and their associated services. |
language | string | 'en' | The language for the banner's text. Supported defaults are 'en' and 'de' . |
translations | object | {} | A custom translations object to override the defaults. See the i18n section. |
The banner comes with built-in translations for English (en
) and German (de
). You can select a language using the language
option.
new ConsentBanner({
language: 'de' // Use German translations
});
To provide your own translations or support a different language, you can pass a translations
object. The object key should be the language code.
new ConsentBanner({
language: 'fr',
translations: {
fr: {
title: 'Paramètres des cookies',
description: 'Nous utilisons des cookies pour améliorer votre expérience de navigation.',
acceptAll: 'Tout accepter',
denyAll: 'Tout refuser'
}
}
});
git clone https://github.com/your-username/owntag-consent.git
cd owntag-consent
npm install
To see the consent banner in action, run the demo:
npm run demo
This will start a local development server. Open the URL provided in your terminal to see the banner in action.
To run the test suite:
npm test
This project is licensed under the MIT License.
FAQs
A lightweight, customizable cookie consent banner.
We found that @owntag/consent demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.