Framework · Install guide
Cookie consent for React
Updated
For a React single-page app, add Kiescy to index.html so it loads before your bundle. It holds back trackers until visitors agree and works across client-side route changes.
- Setup time
- About 10 minutes
- Coding
- One line in your layout
- Laws covered
- GDPR, UK GDPR, CCPA, DPDP
- Google Consent Mode v2
- Built in, basic or advanced
Set up cookie consent on React in 3 steps
- Create a free accountAdd your website. Kiescy scans it and finds the trackers that need consent.
- Paste one script into ReactYour banner appears and starts holding back trackers until visitors choose.
- Check it worksOpen your site in a private window and run the free check to confirm nothing loads early.
Why React sites need cookie consent
React single-page apps usually initialize analytics in the entry file, which runs before any banner component can mount. Consent has to come from a script that loads first.
Your options on React
| Approach | Good for | Watch out for |
|---|---|---|
| A React cookie component | UI-only needs | Can't stop SDKs initialized at startup |
| Kiescy in index.html | Any React app | Move SDK initialization into onChange |
Add your privacy policy
Render a policy inside a component by including the embed element and loading the policy script once:
<div data-kiescy-doc="privacy"></div>
<script src="https://script.kiescy.com/embed/policy/YOUR_SITE_KEY.js" async></script>Check that it works
Open your site in a private window: the banner should appear for a first-time visitor. Then run the free privacy check, which opens your site as a new EU visitor and lists anything that still loads before consent.
Kiescy's monitoring repeats that check on a schedule and emails you if a new script starts tracking before consent.
What your React visitors see
Kiescy detects where each visitor is and shows the version their law requires, so you don't have to choose between the strictest banner for everyone and no banner at all.
Trackers React sites usually load
These are the tools that most often need consent on React sites, and how Kiescy treats them. Run a cookie scan to see exactly what yours loads.
| Tool | Category | What happens |
|---|---|---|
| react-ga4, gtag.js | Analytics | Initialize only after analytics consent |
| PostHog, Mixpanel, Segment | Analytics | Gate initialization on consent |
| Meta Pixel (react-facebook-pixel) | Advertising | Gate on advertising consent |
| Sentry, LogRocket | Performance / analytics | Session replay tools record behavior; treat as analytics |
Google Consent Mode v2 on React
Kiescy loads from index.html before your bundle, so Consent Mode v2 defaults are set before react-ga4 or gtag.js load. Initialize those libraries in a window.pira.onChange callback once analytics is allowed.
New to Consent Mode? Read basic vs advanced Consent Mode v2.
Troubleshooting
Analytics starts before the visitor chooses
If you call ReactGA.initialize() at startup, it loads Google's script immediately. Move it into the pira.onChange callback.
The banner covers my fixed bottom navigation
Choose a top or center layout for the banner in Kiescy, or add bottom padding while the banner is open by listening for the pira:consent event.
Compliance checklist for React
- A consent banner that blocks non-essential trackers until the visitor agrees (opt-in for the EU, UK and India).
- A "Do Not Sell or Share" option for California visitors, and Global Privacy Control honored.
- A privacy policy that names the tools above, linked from every page.
- A cookie policy listing the cookies your scan finds.
- A way for people to request, correct or delete their data.
- Records of each consent choice, kept as proof.
- Add a "Cookie settings" control that calls window.pira.open().
Guides for React site owners
Questions
Does the banner re-appear on every route change?
No. It runs once per page load and remembers the visitor's choice, so client-side navigation doesn't affect it.
Is there an npm package?
You don't need one. A script tag loads before your bundle, which is what lets it hold back other scripts.
Does it work with React Router and client-side navigation?
Yes. The banner runs once per page load; route changes don't re-trigger it, and the visitor's choice persists.
Official React documentation
Menus move. If a step above doesn't match what you see, React's own docs show the current way to add code.
Get compliant this afternoon, not this quarter.
Set up your policies, banner and request form in one place. Free while Kiescy is in early access.