Next.js Discord

Discord Forum

How do you add google analytics in the Nextjs app directory

Unanswered
Gharial posted this in #help-forum
Open in Discord
GharialOP
All the video tutorials and documention I have been able to find on integrating google analytics in nextjs refers to the _app.js but since I am using the app directory, I am getting an error trying to place the script in the head tag. NextJs wants you to place it outside the head tag but then how can you have GA in all pages? Thanks to anyone who can help me with this. Thanks.
o answer my own question:
Found a great vid explaining this - https://www.youtube.com/watch?v=DJMTWuz2ksk&t=111s

1 Reply

Polar bear
It would be a Script component in your root layout at /app/layout