MauricioRobayo/nextjs-google-analytics

NEXT_PUBLIC environment variables don't seem to work

phillipsm opened this issue · 2 comments

I can't get nextjs-google-analytics to work when I place my measurement ID in a NEXT_PUBLIC variable. No events get reported.

It seems to be something with the next public vars. If I make my own NEXT_PUBLIC var, no events are reported either.

      <GoogleAnalytics
        trackPageViews
        gaMeasurementId={process.env.NEXT_PUBLIC_GA_ID}
      />

But, things work great if I pass my Google Analytics ID as string like this,

<GoogleAnalytics trackPageViews gaMeasurementId="MY GA ID HERE" />

I'm using Next 12.2.5 and Nextjs Google Analytics
2.2.2
.

If you enter your GA4 code in your .env you won't need to include it like you code example.
The package will do this for you.
More information about that can be found here in the readme.

@phillipsm did you solve it? Is it ok to close this issue?