Integrate via npm (React)
Install the package:
npm install @truconsent/consent-noticeyarn add @truconsent/consent-noticepnpm add @truconsent/consent-noticebun add @truconsent/consent-noticeMount TruCookieConsent in your root App component, outside <Routes>, so it persists across navigation and only runs the consent check once.
import { TruCookieConsent } from "@truconsent/consent-notice";import "@truconsent/consent-notice/banner-styles.css";import "@truconsent/consent-notice/variables.css";import "@truconsent/consent-notice/tailwind.css";
const App = () => ( <QueryClientProvider client={queryClient}> <BrowserRouter> <TruCookieConsent apiUrl={import.meta.env.VITE_TRU_CONSENT_API_URL} apiKey={import.meta.env.VITE_TRU_CONSENT_API_KEY} orgId={import.meta.env.VITE_TRU_CONSENT_ORGANIZATION_ID} assetId={import.meta.env.VITE_TRU_CONSENT_ASSET_ID} /> <Routes> <Route path="/" element={<Index />} /> {/* ... */} </Routes> </BrowserRouter> </QueryClientProvider>);| Prop | Type | Description |
|---|---|---|
apiUrl * | string | Base URL of the truConsent API |
apiKey * | string | Consent-scope API key |
orgId * | string | Your organisation ID |
assetId * | string | Your asset UUID |
theme | string | ”light” (default) or “dark” |
onClose | function | Called after the user makes a choice |
”Cookie Settings” link
Section titled “”Cookie Settings” link”The component registers window.truCookieConsent on mount:
<button onClick={() => window.truCookieConsent?.openSettings()}> Cookie Settings</button>window.truCookieConsent API
Section titled “window.truCookieConsent API”| Method | Description |
|---|---|
openSettings() | Opens the preferences panel |
acceptAll() | Programmatically accepts all categories |
rejectAll() | Programmatically rejects all optional categories |
hasConsented() | Returns true if the user has already made a choice |
reset() | Clears stored consent and re-shows the banner |
getCategories() | Returns the current { [slug]: boolean } consent state |
Verification
Section titled “Verification”- Open your site — the banner should appear on first visit.
- After accepting, check DevTools → Application → Local Storage —
tru_consentshould be set. - To test again:
localStorage.removeItem('tru_consent')then reload.
Banner does not appear
- Confirm the cookie notice status in the platform is Active (admin approval required).
- Check that your domain is in Allowed Domains under Settings → API Settings.
- Verify all four env vars are set and non-empty.
403 Forbidden in the network tab
- Your domain is not allowlisted. Add it under Settings → Allowed Domains.