Next.js Discord

Discord Forum

GoogleAnalytics in App directory

Unanswered
Cuvier’s Dwarf Caiman posted this in #help-forum
Open in Discord
Cuvier’s Dwarf CaimanOP
Hello everyone. I am trying implement GoogleAnalytics in my nextjs application (NextJS14 + App directory) using @next/third-parties which is activated when the user accepts the consent cookies of the website.
The documentation says to add the GoogleAnalytics component in the layout, which in my case is server side and this works. But since it is server side, I do not have access to browser cookies to check whether the user has accepted the cookies.
I have tried creating a client component which returns the GoogleAnalytics component, and then importing this component into my layout, but then the analytics tracking doesn't seem to work. I really don't want to check cookies in the layout, which would lead to my layout becoming client-side and defeating the whole purpose of RSC. Any help would be appreciated on this.
I've created an issue on the NextJs github repo here : https://github.com/vercel/next.js/issues/64328
It was closed automatically since I can't really provide a reproducible demo, so any ideas on how to provide a demo without sharing our analytics id or access to our analytics console would be much appreciated too.
Thanks in advance !

0 Replies