Adding the google analytics scripts as outlined here https://nextjs.org/docs/messages/next-script-for-ga
And adding a .env file to store the GA ID as outlined here https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables