@didomi/vega-sdk
v0.0.2
Published
Didomi SDK for Vega TV platform
Readme
Didomi Vega SDK
A Vega SDK for integrating Didomi's Consent Management Platform (CMP) with Amazon's Vega platform. This SDK enables applications to manage user consent for data collection and processing in compliance with privacy regulations.
Features
- Display consent notices and preference dialogs
- Collect and manage user consent choices
- Synchronize consent data with Didomi servers
- Support for various privacy regulations (GDPR, CCPA, etc.)
- Comprehensive event handling for user interactions
Installation
npm install @didomi/vega-sdkPeer Dependencies
This SDK has the following peer dependencies:
- React (>=18.0.0 <=18.2.0)
- React DOM (>=18.0.0 <=18.2.0)
- React Native (^0.72.0)
- @amazon-devices/react-native-vega (^2.0.0)
- @amazon-devices/webview
For WebView: Update your app's manifest.toml file to include required services
Usage
Basic Integration
import { DidomiSDK, DidomiSDKAPI } from '@didomi/vega-sdk';
import React, { useRef } from 'react';
const MyApp = () => {
const didomiRef = useRef<DidomiSDKAPI>(null);
return (
<DidomiSDK
noticeId="YOUR_NOTICE_ID"
didomiPublicApiKey="YOUR_PUBLIC_API_KEY"
ref={didomiRef}
onReady={() => console.log('Didomi SDK is ready')}
onConsentChanged={(consent) => console.log('Consent changed:', consent)}
>
{/* Your application content */}
<YourApp />
</DidomiSDK>
);
};Programmatically Interacting with the SDK
After integrating the SDK, you can programmatically access its functionality through the ref:
// All SDK methods are accessible through the ref
const didomiSDK = didomiRef.current;
// Display UI elements
didomiSDK?.notice.show(); // Show consent notice
didomiSDK?.preferences.show('purposes'); // Show preferences UI
// Query SDK state
const isConsentRequired = await didomiSDK?.isConsentRequired();
// Manage user consent
const userStatus = await didomiSDK?.getCurrentUserStatus();
await didomiSDK?.setUserAgreeToAll();
await didomiSDK?.setCurrentUserStatus({
purposes: {
/* purpose status */
},
vendors: {
/* vendor status */
},
});API Reference
Component Props
The DidomiSDK accepts the following required props:
| Prop | Type | Description |
| -------------------- | -------- | -------------------------------------------------------------------------------- |
| noticeId | string | ID of the consent notice to display |
| didomiPublicApiKey | string | Your Didomi public API key |
| sdkPath | string | (Optional) Path to the Didomi SDK, defaults to 'https://sdk.privacy-center.org/' |
Methods
The SDK exposes methods through a ref:
Consent Management
| Method | Description | Parameters | Returns |
| ------------------------ | ------------------------------- | ----------------------------------------------- | ------------------ |
| notice.show() | Shows the consent notice | None | void |
| notice.isVisible() | Checks if the notice is visible | None | Promise<boolean> |
| preferences.show(type) | Shows the preferences UI | type: 'information' | 'purposes' | 'vendor' | void |
| reset() | Resets the consent data | None | void |
User Status
| Method | Description | Parameters | Returns |
| ------------------------ | --------------------------------- | ---------- | ---------------------------- |
| getCurrentUserStatus() | Gets detailed user consent status | None | Promise<CurrentUserStatus> |
| getUserStatus() | Gets user consent status | None | Promise<any> |
| getPurposes() | Gets available purposes | None | Promise<any> |
| getVendors() | Gets available vendors | None | Promise<any> |
User Configuration
| Method | Description | Parameters | Returns |
| ------------------------------ | ------------------------------------- | ------------------------------- | ------------------------- |
| setUser(config) | Sets user information | config: UserConfiguration | Promise<void> |
| clearUser() | Clears user data | None | Promise<void> |
| setUserAgreeToAll() | Sets consent to agree to all | None | Promise<void> |
| setUserDisagreeToAll() | Sets consent to disagree to all | None | Promise<void> |
| setCurrentUserStatus(params) | Updates user consent status | params: SetUserStatusParams | Promise<boolean> |
| syncUser() | Synchronizes user consent with server | None | Promise<SyncReadyEvent> |
Consent Checking
| Method | Description | Parameters | Returns |
| ------------------------------ | ------------------------------------- | ---------------- | ------------------- |
| isConsentRequired() | Checks if consent is required | None | Promise<boolean> |
| isUserConsentStatusPartial() | Checks if user consent is partial | None | Promise<boolean> |
| shouldConsentBeCollected() | Checks if consent should be collected | None | Promise<boolean> |
| isRegulationApplied(name) | Checks if a regulation applies | name: string | Promise<boolean> |
| getRequiredPurposeIds() | Gets required purpose IDs | None | Promise<string[]> |
| getRequiredVendorIds() | Gets required vendor IDs | None | Promise<string[]> |
Events
The SDK provides callbacks for various events:
Ready Events
| Event | Description | Callback Parameter |
| --------- | ---------------------------- | ------------------ |
| onReady | Called when the SDK is ready | None |
Consent Events
| Event | Description | Callback Parameter |
| ------------------ | -------------------------------- | ---------------------------- |
| onConsentChanged | Called when user consent changes | consent: User consent data |
UI Events
| Event | Description | Callback Parameter |
| --------------------- | ------------------------------------ | ------------------ |
| onNoticeShown | Called when notice is shown | None |
| onNoticeHidden | Called when notice is hidden | None |
| onPreferencesShown | Called when preferences UI is shown | None |
| onPreferencesHidden | Called when preferences UI is hidden | None |
User Interaction Events
| Event | Description | Callback Parameter |
| --------------------------------- | ------------------------------------------- | ------------------ |
| onNoticeBackdropclick | Called when notice backdrop is clicked | None |
| onNoticeClickAgree | Called when user clicks agree on notice | None |
| onNoticeClickMoreInfo | Called when user clicks more info on notice | None |
| onPreferencesClickAgreeToAll | Called when user clicks agree to all | None |
| onPreferencesClickDisagreeToAll | Called when user clicks disagree to all | None |
| onPreferencesClickSaveChoices | Called when user saves choices | None |
Implementation Example
Below is a simplified example showing how to implement the SDK and access its functionality:
import { DidomiSDK, DidomiSDKAPI } from '@didomi/vega-sdk';
import React, { useRef, useState } from 'react';
import { View } from 'react-native';
function App() {
// Create ref to access SDK methods
const didomiRef = useRef<DidomiSDKAPI>(null);
// Example of event handling
const handleReady = () => {
// SDK is ready, you can now call methods
console.log('SDK is ready');
};
// Example of handling consent changes
const handleConsentChanged = (consent) => {
console.log('Consent changed', consent);
// Update application state or perform actions based on consent
};
return (
<DidomiSDK
noticeId="YOUR_NOTICE_ID"
didomiPublicApiKey="YOUR_PUBLIC_API_KEY"
ref={didomiRef}
onReady={handleReady}
onConsentChanged={handleConsentChanged}
>
<View>{/* Your application UI */}</View>
</DidomiSDK>
);
}
export default App;License
Copyright © Didomi. All rights reserved.
