Didomi React


Didomi React is a React component which creates a layer on top of our SDK.
Using the component
- Install the library using npm.
$ npm install --save didomi-react
- Import the module in your app.
import { DidomiSDK } from 'didomi-react';
Please note that the sooner you instanciate the component, the faster the banner will be displayed or the faster the consents will be shared with your partners and the ads displayed.
- Instanciate the component in your app
const didomiConfig = {
website: {
vendors: {
iab: {
all: true
}
}
}
}
...
<DidomiSDK
config={didomiConfig}
onReady={didomi => console.log('Didomi SDK is loaded and ready', didomi)}
onConsentChanged={cwtToken => console.log('A consent has been given/withdrawn', cwtToken)}
onNoticeShown={() => console.log('Didomi Notice Shown')}
onNoticeHidden={() => console.log('Didomi Notice Hidden')}
/>
Column Props
Name | Type | Default | Description |
---|
config | object | {} | Configuration of the SDK, please go below to see the configuration object structure |
onReady | function | | Called when the SDK is loaded. Pass the Didomi object as parameter. Please see the https://developers.didomi.io/cmp/web-sdk/reference for more information about what you can do with the Didomi object |
onConsentChanged | function | | Called when a consent is given or withdrawn by the user. Pass the CWT Token as parameter. |
onNoticeShown | function | | Called when the notice is shown |
onNoticeHidden | function | | Called when the notice is hidden |
Configuration object
This is the structure of the configuration object. For more information, please visit our SDK documentation
{
website: {
ignoreCountry: true,
privacyPolicyURL: 'http://example.com',
name: 'Example',
apiKey: '<Your API key>',
logoUrl: 'http://logo.png',
vendors: {
iab: {
all: true,
exclude: [1],
include: [3],
},
didomi: ['google'],
custom: [
{
id: 'custom-vendor',
name: 'Custom Vendor',
purposeIds: ['cookies'],
policyUrl: 'http://www.vendor.com/privacy-policy'
}
]
},
customPurposes: [
{
id: 'my_custom_purpose',
name: {
en: 'My custom purpose',
},
description: {
en: 'Description',
}
}
]
},
languages: {
enabled: ['en', 'fr', 'es', 'nl', 'ca', 'it', 'de', 'pt'],
default: 'fr',
},
notice: {
position: 'popup',
closeOnClick: true,
content: {
popup: {
en: 'Text',
},
notice: {
en: 'Text',
},
dismiss: {
en: 'Text',
},
learnMore: {
en: 'Text',
}
}
},
preferences: {
defaultChoice: true,
content: {
text: {
en: 'Text',
},
title: {
en: 'Text',
},
disagreeToAll: {
en: 'Text',
},
agreeToAll: {
en: 'Text',
},
save: {
en: 'Text',
},
textVendors: {
en: 'Text'
},
subTextVendors: {
en: 'Text'
}
},
information: {
enable: true,
content: {
text: {
en: 'Text',
},
learnMore: {
en: 'Text',
},
agreeAndClose: {
en: 'Text',
}
}
}
},
theme: {
color: '#3F51B5',
font: 'Arial',
buttons: {
regularButtons: {
backgroundColor: '#eeeeee',
textColor: '#999999',
borderColor: 'rgba(34, 34, 34, 0.2)',
borderWidth: '1px',
borderRadius: '0px',
},
highlightButtons: {
backgroundColor: 'rgb(194, 39, 45)',
textColor: '#ffffff',
borderColor: 'rgba(194, 39, 45, 0.3)',
borderWidth: '1px',
borderRadius: '0px',
}
}
},
tagManager: {
provider: 'gtm'
},
integrations: {
vendors: {
google: {
enable: true,
eprivacy: true
}
},
refreshOnConsent: true
}
Example of implementation
import React, { Component } from 'react'
import { DidomiSDK } from 'didomi-react'
const didomiConfig = {
website: {
name: 'Didomi',
apiKey: 'API_KEY',
vendors: {
iab: {
all: true
}
}
},
notice: {
position: 'bottom'
},
languages: {
enabled: ['fr', 'en', 'es'],
default: 'fr'
}
}
class DidomiDemo extends Component {
constructor(props) {
super(props);
this.didomiObject = {};
}
onDidomiReady(didomi) {
this.didomiObject = didomi;
console.log('Didomi Ready - Is the consent required ? : ', this.didomiObject.isConsentRequired());
console.log('Didomi Ready - Do we have the consent for the vendor IAB 1 : ', this.didomiObject.getUserConsentStatusForVendor(1));
console.log('Didomi Ready - Do we have the consent for the vendor IAB 1 and the purpose cookies : ', this.didomiObject.getUserConsentStatus('cookies', 1));
}
consentHasChanged(cwtToken) {
console.log('Didomi Consent Changed - cwtToken : ', cwtToken);
console.log('Didomi Consent Changed - Is the consent required ? : ', this.didomiObject.isConsentRequired());
console.log('Didomi Consent Changed - Do we have the consent for the vendor IAB 1 : ', this.didomiObject.getUserConsentStatusForVendor(1));
console.log('Didomi Consent Changed - Do we have the consent for the vendor IAB 1 and the purpose cookies : ', this.didomiObject.getUserConsentStatus('cookies', 1));
}
render() {
return <div>
<h1>Didomi React Demo</h1>
<DidomiSDK
config={didomiConfig}
onReady={this.onDidomiReady.bind(this)}
onConsentChanged={this.consentHasChanged.bind(this)}
/>
<button onClick={() => this.didomiObject.setUserAgreeToAll()}>Set Agree to All</button>
</div>
}
}
Didomi SDK Documentation
See Documentation
License
MIT