
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@usercentrics/cmp-web-sdk
Advanced tools
Please visit our official [https://usercentrics.com/docs/web/implementation/sdk/][docs] (alpha version, not to be used in production).
Please visit our official [https://usercentrics.com/docs/web/implementation/sdk/][docs] (alpha version, not to be used in production).
# npm
npm install @usercentrics/cmp-web-sdk
# yarn
yarn install @usercentrics/cmp-web-sdk
import CmpWebSdk from '@usercentrics/cmp-web-sdk';
(async () => {
const cmpWebSdk = new CmpWebSdk(); // init the sdk
const cmpController = await cmpWebSdk.initBySetting('YOUR_SETTINGS_ID'); // get the cmp controller
// your custom cmp ui logic
})();
// accept all
await cmpWebSdk.acceptAllConsents();
// deny all
await cmpWebSdk.denyAllConsents();
// update services consent
await cmpWebSdk.updateServicesConsent({
id: 'SERVICE_ID', // the service id
consent: true, // the consent state true | false
});
// update categories consent
await cmpWebSdk.updateCategoryConsent([{
id: 'CATEGORY_ID', // the category id
consent: true, // the consent state true | false
}]);
/* IMPORTANT:
all above methods just change the consent state internally,
to persist the user decision (e.g. after a save consent button click by the user)
you need to persist/save the consents */
await cmpWebSdk.saveConsents();
// gets services
await cmpWebSdk.getServices();
// gets categories
await cmpWebSdk.getCategories();
// gets languages
await cmpWebSdk.getLanguages();
// changes the language
await cmpWebSdk.changeLanguage('en');
// returns true if all consents are accepted
await cmpWebSdk.areAllConsentsAccepted();
// returns true if all consents are denied
await cmpWebSdk.areAllConsentsDenied();
// returns true if a decision consent is required
await cmpWebSdk.getIsConsentRequired();
// import GDPR optimized GdprWebSdk
import { GdprWebSdk, GdprCmpController, UiView } from '@usercentrics/cmp-web-sdk';
// simple vanilla js view
class CmpView {
private cmpController: GdprCmpController;
private cmpElement: HTMLDivElement;
constructor(cmpController: GdprCmpController) {
this.cmpController = cmpController;
}
public async init() {
// create and attach the ui view
const cmpElement = document.createElement('div');
cmpElement.id = 'cmp';
if (typeof cmpElement.attachShadow === 'function') {
// optional -> attach shadow
cmpElement.attachShadow({ mode: 'open' });
}
this.cmpElement = (cmpElement.shadowRoot as HTMLDivElement) || cmpElement;
this.setView(this.cmpController.ui.initialView || 'none');
return new Promise((resolve) => {
if (document.body) {
document.body.appendChild(cmpElement);
resolve();
}
document.addEventListener('DOMContentLoaded', () => {
document.body.append(cmpElement);
resolve();
});
});
}
public setView(view: UiView) {
const consents = JSON.stringify(this.cmpController.dps.getServicesConsents()); // data example
switch (view) {
case 'none':
// do not show the cmp, do not show a cmp button/trigger
this.cmpElement.innerHTML = '';
break;
case 'button':
// do not show the cmp, show a cmp button/trigger
this.cmpElement.innerHTML = 'custom button view';
break;
case 'first':
// the cmp needs to be shown
this.cmpElement.innerHTML = `custom first layer view: ${consents}`;
break;
case 'second':
// the optional custom secondary layer (never an initial view)
this.cmpElement.innerHTML = `custom second layer view ${consents}`;
break;
}
}
}
(async () => {
const gdprWebSdk = new GdprWebSdk();
const gdprCmpController = await gdprWebSdk.initBySetting('YOUR_GDPR_SETTINGS_ID');
const cmpView = new CmpView(gdprCmpController);
await cmpView.init();
})();
Same as GDPR but use UsWebSdk;
Same as GDPR but use TcfWebSdk;
FAQs
Please visit our official [https://usercentrics.com/docs/web/implementation/sdk/][docs] (alpha version, not to be used in production).
The npm package @usercentrics/cmp-web-sdk receives a total of 2 weekly downloads. As such, @usercentrics/cmp-web-sdk popularity was classified as not popular.
We found that @usercentrics/cmp-web-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.