@contentful/experience-consent-manager

A package for handling User Consent Management via Osano.

Usage no npm install needed!

<script type="module">
  import contentfulExperienceConsentManager from 'https://cdn.skypack.dev/@contentful/experience-consent-manager';
</script>

README

@contentful/experience-consent-manager

A package for handling User Consent Management via Osano.

What does it do?

  • Handles loading of Osano script
  • Provides Custom CSS to match Forma36 (v3) styles.
  • Provides useful helpers e.g. isAnalyticsEnabled
  • Provides useful callbacks e.g. onConsentChanged and onError

Installation

yarn add @contentful/experience-consent-manager

Usage

// Import this unless you want to provide your own CSS
import '@contentful/experience-consent-manager/dist/style.css';

import { createConsentManager, ConsentCategory } from '@contentful/experience-consent-manager';

const manager = createConsentManager({
  appKey: 'myApp', // e.g. compose, userInterface, launch ..etc
  osano: {
    // Required
    configId: 'xxxxxxxx',
    // Optional (but Recommended)
    allowedCategories: [ConsentCategory.ESSENTIAL, ConsentCategory.ANALYTICS],
  },
});

// Later on in your app (but as EARLY AS POSSIBLE)
manager.initialize({
  // Required
  getUserConsentData: () => {
    return user.cookieConsentData;
  },
  // Optional (but Recommended)
  onConsentChanged: (consent) => {
    // You probably want to save this to /users/me under appKey namespace.
  },
  onError: (error) => {
    // Log this somewhere, e.g. Sentry?
  },
  // ...
  // ...
  // For the full list of options see src/ConsentManager.ts
});