Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@guardian/consent-management-platform
Advanced tools
Library of useful utilities for managing consent state across *.theguardian.com
Welcome to the Consent Management Platform, a library of useful utilities for managing consent state across *.theguardian.com.
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
.
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
});
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, ... }
});
The cmpUi exports useful utilities for users who want to load the CMP UI on their site via an iframe
.
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
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);
The file cmpConfig
exposes some useful config variables related to the CMP.
import { cmpConfig } from '@guardian/consent-management-platform';
If you're looking to develop on the consent-management-platform
please read our development instructions document.
FAQs
Consent management for *.theguardian.com.
The npm package @guardian/consent-management-platform receives a total of 23 weekly downloads. As such, @guardian/consent-management-platform popularity was classified as not popular.
We found that @guardian/consent-management-platform demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 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
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.