I am having trouble getting Google Analytics to work on my deployed site, but it was working locally, when running the dev server in vscode and checking the real-time updates in GA.
The website is my personal portfolio https://kylewrightman.netlify.app/
I have tried going into my Site Settings > Build & Deploy > Post processing > Snippet Injection > and here I tried adding the HTML tags that Google Analytics provides, and tried inserting it before both the and tags, as those are the options it gives you, and that hasn’t worked either.
I did further troubleshooting in the middle of creating this post, and this is what I have found:
When i upload the .env file to GitHub, with the necessary GA info, the tracking with GA starts working. But obviously I do not want my .env file in the repo, so when I remove it and re-deploy my site, the GA tracking stops working. So I know the Google Analytics is working and the code I have used is correct - but when I am not including the .env file in the site’s repo, Google Analytics no longer works.
Is there any way to get this working and NOT have my .env file visible in the repo? The repo is private, but for future use-cases and with other projects, they may not have private repos and I would not want any sensitive information to be visible. Especially if the website is for a client.
Any help is much appreciated!