-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change the condition to check google analytics Id #451
Comments
Hello! The reason is mainly historical, as the library initially only provided the option to get the As there were already users of the library relying on the env, we added the prop kind of as a fallback option. Also, having the env take precedence over the prop let user modify the value by changing the env and redeploying without having to commit any changes, which can be also convenient in many cases. All that being said, I'm not really sure I get what you mean by:
Do you have an example for this? |
Is this accurate? According to NextJS this is a a build time variable.
I have a staging build and a production build and would like to deploy and use the same code. I can have different env vars but because NEXT_PUBLIC_GA_MEASUREMENT_ID is injected at "build time" I cannot actually change it by setting a different env var at the run time. |
After changing your env you'll need to re-deploy |
Ok, not too familiar with vercel but i guess re-deploy means it'll re-do build as part of it, which makes sense. |
Hey @MauricioRobayo Here is an example - https://github.com/EddieHubCommunity/LinkFree In the above project, there can be different pages for each user. Thanks |
I was able to do this via _app.js from https://www.makeuseof.com/nextjs-google-analytics/ |
Yes @bugzpodder this is an alternate way. |
This is how I landed here. I want to set two tracking IDs, one for Google Ads, another for GA4. There should not be two separate tracking snippets on a page. react-ga4 supports this but doesn't seem as well tied into Next.js. |
nextjs-google-analytics/src/components/GoogleAnalytics.tsx
Line 33 in 86b434f
Here in above referenced code
_gaMeasurementId is formed using -
const _gaMeasurementId = process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID ?? gaMeasurementId;
What if a user wants to use multiple google analytics IDs for different purposes in any use case?
Why we didn't go with -
const _gaMeasurementId = gaMeasurementId ?? process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID;
The text was updated successfully, but these errors were encountered: