Handling Cookie Consent

Chapter 3:

To ensure GDPR compliance, you’ll need to ask users for cookie consent before tracking. The CookieConsent component handles this.

import { CookieConsent } from '@pro/analytics/CookieConsent'

function MyApp() {
  return (
    <>
      <CookieConsent>
        🍪 We use cookies to improve your experience. By using our site, you accept cookies.
      </CookieConsent>
      {/* Rest of your app */}
    </>
  )
}
  • When a user accepts cookies, it automatically enables tracking.

  • The cookie consent value is stored, ensuring that analytics only run after consent is granted.

Last updated