Integrate via CDN script tag
Add the script tag to your index.html <head>, before any GTM or analytics scripts. This order ensures consent defaults are set before other tags can fire.
<head> <!-- 1. truConsent cookie banner — must be first --> <script src="https://cdn.truconsent.io/cmp.min.js" data-banner-type="cookie-consent" data-api-url="%VITE_TRU_CONSENT_API_URL%" data-api-key="%VITE_TRU_CONSENT_API_KEY%" data-org-id="%VITE_TRU_CONSENT_ORGANIZATION_ID%" data-asset-id="%VITE_TRU_CONSENT_ASSET_ID%"> </script>
<!-- 2. GTM or other analytics — loaded after consent defaults --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script></head>Vite replaces %VITE_*% placeholders at build time from your .env file.
Script tag attributes
Section titled “Script tag attributes”| Attribute | Description |
|---|---|
data-banner-type | ”cookie-consent” (default). Omit or set explicitly. |
data-api-url * | Base URL of the truConsent API |
data-api-key * | Consent-scope API key |
data-org-id * | Your organisation ID |
data-asset-id * | Your asset UUID |
”Cookie Settings” link
Section titled “”Cookie Settings” link”Add this anywhere in your footer so users can reopen the preferences panel:
<a href="#" onclick="truTagManager.openSettings(); return false;">Cookie Settings</a>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.