@corvesta/cookie-consent-lib
v1.0.1
Published
Framework-agnostic cookie consent library for OneTrust integration
Readme
Cookie Consent Library
A lightweight, framework-agnostic cookie consent library for OneTrust and Google Tag Manager integration.
Installation
npm install @corvesta/cookie-consent-libUsage
Basic OneTrust Only
import { loadCookieConsent } from '@corvesta/cookie-consent-lib';
loadCookieConsent('your-onetrust-id');OneTrust + Google Tag Manager
import { loadCookieConsentAndGTM } from '@corvesta/cookie-consent-lib';
loadCookieConsentAndGTM({
oneTrustId: 'your-onetrust-id',
gtmId: 'GTM-XXXXXXX'
});GTM Only (No Cookie Consent)
import { loadCookieConsentAndGTM } from '@corvesta/cookie-consent-lib';
loadCookieConsentAndGTM({
gtmId: 'GTM-XXXXXXX',
enableCookieConsent: false
});Framework Integration
React
import { useEffect } from 'react';
import { loadCookieConsentAndGTM } from '@corvesta/cookie-consent-lib';
function App() {
useEffect(() => {
loadCookieConsentAndGTM({
oneTrustId: 'your-onetrust-id',
gtmId: 'GTM-XXXXXXX'
});
}, []);
return <div>Your app content</div>;
}API
loadCookieConsent(id: string)
Loads OneTrust cookie consent scripts.
loadCookieConsentAndGTM(options: LoadOptions)
Loads OneTrust and/or GTM with configuration options.
Options:
oneTrustId?: string- OneTrust domain script IDgtmId?: string- Google Tag Manager container IDenableCookieConsent?: boolean- Enable OneTrust (default: true)enableGTM?: boolean- Enable GTM (default: true)
initializeGTM(gtmId: string)
Directly initializes Google Tag Manager.
License
MIT
