Skip to content

Commit 1ee55ea

Browse files
committed
Add google analytics
1 parent 4d64f33 commit 1ee55ea

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
lines changed

example.env

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
NEXT_PUBLIC_BACKEND_URL=https://backend.commitrocket.com
1+
NEXT_PUBLIC_BACKEND_URL=https://backend.commitrocket.com
2+
NEXT_PUBLIC_GOOGLE_ANALYTICS_TAG_ID= [[ SOME GOOGLE ANALYTICS TAG ID]]

package-lock.json

+21-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"class-variance-authority": "^0.4.0",
1818
"framer-motion": "^9.1.7",
1919
"next": "13.2.4",
20+
"nextjs-google-analytics": "^2.3.3",
2021
"react": "18.2.0",
2122
"react-dom": "18.2.0",
2223
"react-hook-form": "^7.43.5",
@@ -36,4 +37,4 @@
3637
"postcss": "^8.4.21",
3738
"tailwindcss": "^3.2.7"
3839
}
39-
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react";
2+
import { GoogleAnalytics as NextGoogleAnalytics } from "nextjs-google-analytics";
3+
4+
export type GoogleAnalyticsProps = Parameters<typeof NextGoogleAnalytics>[0];
5+
export const DEFAULT_CONFIG: GoogleAnalyticsProps = {
6+
gaMeasurementId: process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_TAG_ID,
7+
strategy: "lazyOnload",
8+
trackPageViews: {
9+
ignoreHashChange: true
10+
}
11+
};
12+
13+
const GoogleAnalytics = () => (
14+
<>
15+
{process.env.NODE_ENV !== "development" && <NextGoogleAnalytics {...DEFAULT_CONFIG} />}
16+
</>
17+
);
18+
19+
export default React.memo(GoogleAnalytics);

src/pages/_app.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Head from "next/head";
66

77
import Header from "@/components/navigation/Header";
88
import Footer from "@/components/navigation/Footer";
9+
import GoogleAnalytics from "@/components/analytics/GoogleAnalytics";
910

1011
import '@/styles/main.css';
1112

@@ -49,6 +50,7 @@ export default function App({ Component, pageProps, router }: AppProps) {
4950
<Head>
5051
<title>Commit Rocket</title>
5152
</Head>
53+
<GoogleAnalytics />
5254
<div className={"flex flex-col overflow-auto scroll-smooth scroll-p-4 " + openSans.variable}>
5355
<Header />
5456
<AnimatePresence mode="wait">

0 commit comments

Comments
 (0)