From 56384d4f23f0bf2fe5cd2a1308322c33331e429c Mon Sep 17 00:00:00 2001 From: Seth Silesky <5115498+silesky@users.noreply.github.com> Date: Tue, 27 Jun 2023 22:01:50 -0600 Subject: [PATCH] wip --- packages/consent/consent-tools/README.md | 34 +++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/consent/consent-tools/README.md b/packages/consent/consent-tools/README.md index e0bd129f9..daee0bbdd 100644 --- a/packages/consent/consent-tools/README.md +++ b/packages/consent/consent-tools/README.md @@ -1,18 +1,31 @@ # @segment/analytics-consent-tools -## Example -## Wrapper Usage -Please see our [ onetrust example.](../consent-wrapper-onetrust) + + + +## Quick Start ```ts // wrapper.js -import { createWrapper } from '@segment/analytics-consent-tools' +import { createWrapper, resolveWhen } from '@segment/analytics-consent-tools' export const withCMP = createWrapper({ - shouldLoad: () => Promise.resolve({ Advertising: false, Functional: true }), - getCategories: () => ({ Advertising: false, Functional: true }), + shouldLoad: (ctx) => { + await resolveWhen(() => + window.CMP !== undefined && !window.CMP.popUpVisible() + 500) + + if (noConsentNeeded) { + return ctx.abort({ loadSegmentNormally: true }) + } + }, + getCategories: () => { + // e.g. { Advertising: true, Functional: false } + return normalizeCategories(window.CMP.consentedCategories()) + } }) ``` -## Wrapper Consumer Usage + +## Wrapper Usage API ## `npm` ```js import { withCMP } from './wrapper' @@ -44,10 +57,11 @@ withCmp(window.analytics) window.analytics.load('