I have a NextJS site which is statically generated at build (SSG).
There are two things I need to implement next
- Google Analytics
- GDPR compliant opt-in cookie options
The first one is easy enough to do, however i'm struggling with making this GDPR compliant. The issue is I don't have access to cookies at server side when my site is statically generated. This means that without knowing whether the user has consented to cookies at the server, I can't serve (or not serve) the analytics script along with the rest of the page.
Possible solutions:
Handle everything at client side - ask for consent, then dynamically add the GA tag to the
<head>
. However i'm worried this will negatively effect the analytics, or break it altogether. Does anyone know?Change my site to be server-side rendered (SSR). I'd love to avoid this if possible. I'm really happy with how fast the site is running with SSG. It's essentially just a basic blog so would be a shame to have to convert for the sake of analytics.
Any other ideas?...
If anyone has experience with this, whether they used Next or Nuxt, etc, your input would be greatly appreciated!
Thanks in advance