solo-cmp
This library is a wrapper of the IAB's Transparency and Consent Framework (TCF) library with the intention of simplifying and adding more ways of customization of the whole flow that starts from the view of the CMP banner at the release of the user's consent. This library is completely framework agnostic, so feel free to implement your CMP with any framework such as Vue, React and others.
So what you have to do is only the graphical implementation and if necessary add plugins to execute logic based on the event flows mapped by the library.
Installation
npm
npm install @pubtech-ai/solo-cmp --save
Using
This example demonstrates the basic use case of a CMP UI using our library.
import cmpstub from '@iabtcf/stub';
cmpstub();
import {
SoloCmp,
UIConstructor,
OpenCmpUIEvent,
EventDispatcher,
TCStringService,
ACStringService
} from "@pubtech-ai/solo-cmp";
import DependencyInjectionManager from "@pubtech-ai/solo-cmp/lib/DependencyInjection/DependencyInjectionManager";
const uiConstructor = new UIConstructor(document, 'your-cmp-html-element-id-container', (rootElement, soloCmpDataBundle) => {
}, (rootElement) => {
const eventDispatcher = DependencyInjectionManager.getService(EventDispatcher.getClassName());
const tcStringService = DependencyInjectionManager.getService(TCStringService.getClassName());
const acStringService = DependencyInjectionManager.getService(ACStringService.getClassName());
eventDispatcher.dispatch(new OpenCmpUIEvent(
tcStringService.retrieveTCString(),
acStringService.retrieveACString()
));
});
const cmpVersion = 1;
const cmpVendorListVersion = 79;
const cmpId = 100000;
const soloCmp = new SoloCmp(
{
uiConstructor: uiConstructor,
isDebugEnabled: true,
cmpConfig: {
isAmp: true,
onConsentAds: () => {
},
debug: true
},
supportedLanguages: ['it', 'en'],
cmpVersion: cmpVersion,
cmpVendorListVersion: cmpVendorListVersion,
tcStringCookieName: 'euconsent-v2',
acStringLocalStorageName: 'ac_euconsent-v2',
cmpId: cmpId,
isServiceSpecific: true,
baseUrlVendorList: "https://url-to/vendorList",
initialHeightAmpCmpUi: '30vh',
enableBorderAmpCmpUi: false,
}
);
soloCmp.init();
After this first initialization what needs to be done is to render all the choices available within the
UIChoicesBridgeDto object exposed by the SoloCmpDataBundle which is injected by the first callback provided during the creation of the UIConstructor.
const uiChoicesBridgeDto = soloCmpDataBundle.uiChoicesBridgeDto;
const uiPurposes = uiChoicesBridgeDto.UIPurposeChoices;
const uiSpecialFeatures = uiChoicesBridgeDto.UISpecialFeatureChoices;
const uiVendors = uiChoicesBridgeDto.UIVendorChoices;
const uiLegIntPurposes = uiChoicesBridgeDto.UILegitimateInterestsPurposeChoices;
const uiLegIntVendors = uiChoicesBridgeDto.UILegitimateInterestsVendorChoices;
const uiGoogleVendors = uiChoicesBridgeDto.UIGoogleVendorOptions;
import {
AcceptAllEvent,
ApplyConsentEvent,
EventDispatcher,
MoreChoicesEvent,
} from "@pubtech-ai/solo-cmp";
EventDispatcher.getInstance().dispatch(new MoreChoicesEvent());
EventDispatcher
.getInstance()
.dispatch(
new ApplyConsentEvent(
soloCmpDataBundle.uiChoicesBridgeDto,
soloCmpDataBundle
)
);
EventDispatcher
.getInstance()
.dispatch(
new AcceptAllEvent(
soloCmpDataBundle
)
);
That's all, create your CMP, show consents and give the user the ability to choose which things to enable and disable and dispatch the above events.
Note: Closing the CMP UI is your responsibility, so once the user has done something to dispatch ApplyConsentEvent or AcceptAllEvent, don't show the CMP, or destroy it.
Contribution
In order to contribute to the improvement of the project, below you will find the project development flow.
Before being able to open a PR with changes to be applied or bug fixes to be solved, it is necessary to open an issue
and explain the reason and a possible solution. You can open each PR by forking the project and creating the PR directly from
your project to the project of our library.
Main rules:
- Open issue
- Create PR from forked project
- Link your PR to the issue
Development Flow
All development work occurs on the develop
branch.
The main
branch is used to create new releases by merging current head of the develop
branch.
You should create a feature-branch, branching from develop
, whenever you need to add some changes to the main
branch.
If those changes are accepted they will be merged by the repository maintainer.
Dependencies
This application is based on:
- Node.js: 14.15.4
- IAB TCF Modules
- BottleJs
Development environment
To ease local development you have to install these tools:
Install dependencies
To install dependencies, execute these commands:
npm install
When the process is complete, a Browser tab is automatically opened.
Compile and minify for production
To create a production version, execute this command:
npm run build
Test project
To run tests, execute this command:
npm run test
Lint project
To lint the project files, execute this command:
npm run lint
Disclaimer
This SOFTWARE PRODUCT is provided by THE PROVIDER "as is" and "with all faults." THE PROVIDER makes no representations
or warranties of any kind concerning the safety, suitability, lack of viruses, inaccuracies, typographical errors, or
other harmful components of this SOFTWARE PRODUCT. There are inherent dangers in the use of any software, and you are
solely responsible for determining whether this SOFTWARE PRODUCT is compatible with your equipment, gdpr compliance and
other software installed on your equipment. You are also solely responsible for the protection of your equipment and
backup of your data, and THE PROVIDER will not be liable for any damages you may suffer in connection with using,
modifying, or distributing this SOFTWARE PRODUCT.