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

@guardian/consent-management-platform

Package Overview
Dependencies
Maintainers
22
Versions
206
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@guardian/consent-management-platform

Library of useful utilities for managing consent state across *.theguardian.com

  • 1.1.0-beta.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23
decreased by-81.3%
Maintainers
22
Weekly downloads
 
Created
Source

Welcome to the Consent Management Platform, a library of useful utilities for managing consent state across *.theguardian.com.

What useful utilities does this offer?

cmp

If you need to conditionally run some code based on a user's consent state you can use the cmp module.

This module exposes two functions onGuConsentNotification and onIabConsentNotification.

onGuConsentNotification

This function takes 2 arguments, the first is the purpose name (a string) that is relevant to the code you're running eg. "functional" OR "performance", and the second is a callback (a function).

When onGuConsentNotification is called it will execute the callback immediately, passing it a single argument (a boolean or null) which indicates the user's consent state at that time for the given purpose name.

The cmp module also listens for subsequent changes to the user's consent state (eg. if a user saves an update to their consent via the CMP modal), if this happens it will re-execute the callback, passing it a single argument (a boolean or null) which inidicates the user's updated consent state for the given purpose name.

Example:

import { onGuConsentNotification } from '@guardian/consent-management-platform';

onGuConsentNotification('functional', functionalConsentState => {
    console.log(functionalConsentState); // true || false || null
});
onIabConsentNotification

This function takes 1 argument, a callback (a function).

When onIabConsentNotification is called it will execute the callback immediately, passing it a single argument, an object which reflects the consent granted to the IAB purposes. The signature for this object will be:

{
    [key: number]: boolean | null;
}

The keys in this object will match the IAB purpose IDs from the IAB vendor list.

The cmp module will also listens for subsequent changes to the user's consent state (eg. if a user saves an update to their consent via the CMP modal), if this happens it will re-execute the callback, passing it a single argument, an object which reflects the latest consent granted to the IAB purposes.

Example:

import { onIabConsentNotification } from '@guardian/consent-management-platform';

onIabConsentNotification(iabConsentState => {
    console.log(iabConsentState); // { 0: true || false || null, 1: true || false || null, ... }
});

cmpUi

The cmpUi exports useful utilities for users who want to load the CMP UI on their site via an iframe.

cmpUi.canShow

The cmpUi.canShow function returns a boolean to indicate whether the user has already saved their consent state. Users should use this when deciding whether or not to present the CMP UI.

Example:

import { cmpUi } from '@guardian/consent-management-platform';

console.log(cmpUi.canShow()); // true | false
cmpUi.setupMessageHandlers

Users loading the CMP UI on their site via an iframe can pass 2 callback functions to cmpUi.setupMessageHandlers that will be executed when messages are emitted from the CMP UI iframe. The 1st argument (onReadyCmp) will be executed when the CMP UI emits a ready message to indicate it has loaded and is ready to be shown. And the 2nd argumememnt (onCloseCmp) will be executed when the CMP UI emits a close message to indicate the user has saved their consent or clicked the close button.

Example:

import { cmpUi, cmpConfig } from '@guardian/consent-management-platform';

const iframe = document.createElement('iframe');
iframe.src = cmpConfig.CMP_URL;
iframe.style.display = 'none';

const onReadyCmp = () => {
    iframe.style.display = 'block';
};

const onCloseCmp = () => {
    iframe.remove();
};

cmpUi.setupMessageHandlers(onReadyCmp, onCloseCmp);

// IMPORTANT: Always add iframe to page after calling setupMessageHandlers
document.body.appendChild(iframe);

cmpConfig

The file cmpConfig exposes some useful config variables related to the CMP.

example:
import { cmpConfig } from '@guardian/consent-management-platform';

Developer instructions

If you're looking to develop on the consent-management-platform please read our development instructions document.

FAQs

Package last updated on 01 Nov 2019

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