New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@usercentrics/cmp-browser-sdk

Package Overview
Dependencies
Maintainers
6
Versions
212
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@usercentrics/cmp-browser-sdk

Usercentrics CMP Browser SDK

  • 0.4.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
decreased by-42.78%
Maintainers
6
Weekly downloads
 
Created
Source

Usercentrics CMP Browser SDK

With the Usercentrics CMP Browser SDK our aim is to provide a lightweight library which enables you to build your own fully customized Consent Solution while still leveraging the Usercentrics service database and tools.

We also offer collaboration possibilities with Usercentrics Partners who are able to support you in building your own customized solution. Contact our sales team for more information.

Installing the dependency

npm install @usercentrics/cmp-browser-sdk --save

Initialization

import Usercentrics, { INITIAL_VIEW } from '@usercentrics/cmp-browser-sdk';

const UC = new Usercentrics('YOUR_USERCENTRICS_SETTINGS_ID');

UC.init().then((initialView) => {
    // getCategories() returns all categories' and data processing services' information
    const categories = UC.getCategories();
    // getSettings() returns all Usercentrics settings you need for your custom solution
    const settings = UC.getSettings();

    switch (initialView) {
        case INITIAL_VIEW.FIRST_LAYER:
            // Show first layer (i.e. privacy banner)
            return;
        case INITIAL_VIEW.PRIVACY_BUTTON:
            // Show privacy button
            return;
        case INITIAL_VIEW.NONE:
        default:
            // Show nothing
            return;
    }
});

The constructor also supports an optional Options parameter.

Changing the language

import Usercentrics, { INITIAL_VIEW } from '@usercentrics/cmp-browser-sdk';

const UC = new Usercentrics('YOUR_USERCENTRICS_SETTINGS_ID');

UC.init().then((initialView) => {
    /**
     * ...
     */

    UC.changeLanguage('NEW_LANGUAGE').then(() => {
        // Remember to fetch new categories and settings
        const categories = UC.getCategories();
        const settings = UC.getSettings();
    });
});

NOTE: If the given controllerId returns no history from the Usercentrics backend, that controllerId will not be updated for the end user.

controllerId is known before init

import Usercentrics from '@usercentrics/cmp-browser-sdk';

const UC = new Usercentrics('YOUR_USERCENTRICS_SETTINGS_ID', { controllerId: 'CONTROLLER_ID_FOR_END_USER' });

UC.init().then((initialView) => {
    /**
     * ...
     */
});

controllerId is known after init

import Usercentrics from '@usercentrics/cmp-browser-sdk';

const UC = new Usercentrics('YOUR_USERCENTRICS_SETTINGS_ID');

UC.init().then((initialView) => {
    /**
     * ...
     */

    UC.restoreUserSession('CONTROLLER_ID_FOR_END_USER').then(() => {
        /**
         * ...
         */
    });
});

IE11 compatibility

If your Consent Solution should work with IE11 (or other legacy browsers), then there's a few extra steps you need to do:

Also you'll have to have Babel (with core-js) (or similar) in your build setup to make sure, that Symbol etc. get polyfilled.

Script tag support

You can also use the SDK as a script tag on your site:

<script type="application/javascript" src="https://app.usercentrics.eu/browser-sdk/0.4.5/bundle.js"></script>

You can now access all methods/constants by using them from within the UC_SDK namespace:

const UC = new UC_SDK.Usercentrics('YOUR_USERCENTRICS_SETTINGS_ID');

UC.init().then((initialView) => {
    const categories = UC.getCategories();
    const settings = UC.getSettings();

    switch (initialView) {
        case UC_SDK.INITIAL_VIEW.FIRST_LAYER:
            // Show first layer (i.e. privacy banner)
            return;
        case UC_SDK.INITIAL_VIEW.PRIVACY_BUTTON:
            // Show privacy button
            return;
        case UC_SDK.INITIAL_VIEW.NONE:
        default:
            // Show nothing
            return;
    }
});

NOTE: If you need Internet Explorer 11 support, you can point the src attribute to https://app.usercentrics.eu/browser-sdk/0.4.5/bundle_legacy.js.

Documentation

Documentation can be found on our documentation website.

FAQs

Package last updated on 04 Jun 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc