Skip to content

Commit

Permalink
feat: integrate google analytics and remove getInitialProps in _app.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
gloriateodoro committed Dec 15, 2023
1 parent 4de1bc4 commit 3231daf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@rjsf/core": "^2.4.1",
"@stripe/react-stripe-js": "^1.2.2",
"@stripe/stripe-js": "^1.11.0",
"@types/react-ga": "^2.3.0",
"apollo-boost": "^0.4.9",
"apollo-link-ws": "^1.0.20",
"formik": "^2.2.6",
Expand Down
9 changes: 3 additions & 6 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import { createApolloClient } from "../lib";
// add global css
import "../styles/globals.css";
import { useRouter } from "next/router";
import { initializeGA, logPageView } from "../utils/analytics";

ReactGA.initialize("G-7R11G6KBCH");
initializeGA("G-7R11G6KBCH");

const theme = extendTheme(nossas);

Expand All @@ -22,7 +23,7 @@ function App({ Component, pageProps }) {
const router = useRouter();

useEffect(() => {
ReactGA.pageview(router.pathname);
logPageView(router.pathname);
}, [router.pathname]);

return (
Expand All @@ -34,8 +35,4 @@ function App({ Component, pageProps }) {
);
}

App.getInitialProps = async (appContext) => ({
...(await NextApp.getInitialProps(appContext)),
});

export default appWithTranslation(App);
10 changes: 10 additions & 0 deletions utils/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ReactGA from "react-ga";

export const initializeGA = (trackingID: string) => {
ReactGA.initialize(trackingID);
};

export const logPageView = (pathname: string) => {
ReactGA.set({ page: pathname });
ReactGA.pageview(pathname);
};

1 comment on commit 3231daf

@vercel
Copy link

@vercel vercel bot commented on 3231daf Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nossas-org – ./

nossas-org.vercel.app
nossas-org-nossas.vercel.app
nossas-org-git-main-nossas.vercel.app

Please sign in to comment.