Skip to content

Commit

Permalink
fix: update env name
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Dec 28, 2023
1 parent 14f45e6 commit 84c7a88
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions components/GoogleAnalytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const GoogleAnalytics = () => {
<>
<Script
strategy="afterInteractive"
src={`https://www.googletagmanager.com/gtag/js?id=${gtag.GA_TRACKING_ID}`}
src={`https://www.googletagmanager.com/gtag/js?id=${gtag.NEXT_PUBLIC_GA_TRACKING_ID}`}
/>
<Script
id="gtag-init"
Expand All @@ -18,7 +18,7 @@ const GoogleAnalytics = () => {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gtag.GA_TRACKING_ID}', {
gtag('config', '${gtag.NEXT_PUBLIC_GA_TRACKING_ID}', {
page_path: window.location.pathname,
});
`,
Expand Down
5 changes: 3 additions & 2 deletions lib/gtag.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// https://stackoverflow.com/questions/77063977/implementing-google-analytics-in-nextjs-13-app-directory

export const GA_TRACKING_ID: string | undefined = process.env.GA_TRACKING_ID;
export const NEXT_PUBLIC_GA_TRACKING_ID: string | undefined =
process.env.NEXT_PUBLIC_GA_TRACKING_ID;

export const pageview = (url: string) => {
(window as any).gtag("config", GA_TRACKING_ID, {
(window as any).gtag("config", NEXT_PUBLIC_GA_TRACKING_ID, {
page_path: url,
});
};
Expand Down

0 comments on commit 84c7a88

Please sign in to comment.