Web-Dev-Path / web-dev-path

The Web Dev Path platform. Progressive Web App (PWA). Next.js rules!
https://webdevpath.co
GNU General Public License v3.0
33 stars 11 forks source link

Google Analytics 4 Integration #177

Closed mariana-caldas closed 1 year ago

mariana-caldas commented 1 year ago

What do we need to build or fix?

We need to integrate Google Analytics 4 (GA4) with our Next.js application to track and analyze user interactions within our web app. Currently, we lack an efficient way to monitor user activity and get useful insights about user behavior on our platform.

Technical details

The integration may require the use of a library, such as next-ga (https://snyk.io/advisor/npm-package/next-ga), a lightweight and straightforward Google Analytics wrapper for Next.js. We will also be storing the Google Analytics Measurement ID in an environment variable to avoid hardcoding this sensitive information into our application.

Approach suggestions

  1. In your local repository copy, run git pull from main and create a new branch feature/ga-4-integration to get started
  2. After getting the GA4 Measurement ID with @mariana-caldas , store it in our .env file with the variable name NEXT_PUBLIC_GA_MEASUREMENT_ID
  3. Install the next-ga package. Remember we use yarn as our package manager, so it would be yarn add next-ga
  4. Use the withGA function in the _app.js file to initialize GA on page load and track page views.

Deadline

Please keep in mind that once you assign this task to yourself, you'll need to complete it in 10 days.

Acceptance criteria