Skip to content

feat: migrated from react-ga4 to next/third-parties for analytics#73

Merged
Alessandro100 merged 1 commit intomainfrom
fix/70-google-analytics-tags
Mar 11, 2026
Merged

feat: migrated from react-ga4 to next/third-parties for analytics#73
Alessandro100 merged 1 commit intomainfrom
fix/70-google-analytics-tags

Conversation

@Alessandro100
Copy link
Contributor

closes #70

Summary:

Updated the google analytics library from react-ga4 to next/third-parties as it is the recommended approach from nextjs. Also properly initialized the analytics and included the GA ID in Vercel

Expected behavior:

We should start to collect GA events again

Testing tips:

Once this goes to production, verify if the tags are properly collecting data in google analytics

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Run the unit tests with yarn test to make sure you didn't break anything
  • Add or update any needed documentation to the repo
  • Format the title like "feat: [new feature short description]". Title must follow the Conventional Commit Specification(https://www.conventionalcommits.org/en/v1.0.0/).
  • Linked all relevant issues
  • Include screenshot(s) showing how this pull request works and fixes the issue(s)

@Alessandro100 Alessandro100 self-assigned this Mar 11, 2026
@vercel
Copy link

vercel bot commented Mar 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mobilitydatabase-web Ready Ready Preview, Comment Mar 11, 2026 1:00pm

Request Review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Migrates Google Analytics event tracking from react-ga4 to Next.js’ @next/third-parties integration so analytics can be initialized via the App Router layout and events can be sent via sendGAEvent. custom

Changes:

  • Add @next/third-parties and remove react-ga4.
  • Replace ReactGA.event(...) calls with sendGAEvent(...) in Feed UI components.
  • Add <GoogleAnalytics gaId=... /> initialization in src/app/[locale]/layout.tsx gated on NEXT_PUBLIC_GOOGLE_ANALYTICS_ID.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
package.json Adds @next/third-parties, removes react-ga4.
yarn.lock Locks @next/third-parties (and its dependency), removes react-ga4.
src/app/[locale]/layout.tsx Initializes Google Analytics in the App Router layout using env-configured GA ID.
src/app/screens/Feed/components/FeedSummary.tsx Sends GA event on “View on map” click via sendGAEvent.
src/app/components/CoveredAreaMap.tsx Sends GA event on “Open detailed map” click via sendGAEvent.
src/app/screens/Feed/components/ClientDownloadButton.tsx Sends GA event on download click via sendGAEvent (no more lazy import).
src/app/screens/Feed/components/ClientQualityReportButton.tsx Sends GA event on quality report click via sendGAEvent (no more lazy import).

Comment on lines 129 to +134
</body>
{getEnvConfig('NEXT_PUBLIC_GOOGLE_ANALYTICS_ID') !== '' && (
<GoogleAnalytics
gaId={getEnvConfig('NEXT_PUBLIC_GOOGLE_ANALYTICS_ID')}
/>
)}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

<GoogleAnalytics /> is being rendered as a direct child of <html> (after </body>). That results in invalid document structure (only <head> and <body> should be children of <html>) and may cause Next/React to relocate or drop the injected script tags. Move the conditional <GoogleAnalytics> render inside <body> (typically near the end) and consider assigning const gaId = getEnvConfig('NEXT_PUBLIC_GOOGLE_ANALYTICS_ID') to avoid reading env twice.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the documentation, it's placed under the body: https://nextjs.org/docs/app/guides/third-party-libraries#google-analytics

@github-actions
Copy link

*Lighthouse ran on https://mobilitydatabase-2dleodl6l-mobility-data.vercel.app/ * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🟢 94 🟢 96 🟢 100 🟢 100

*Lighthouse ran on https://mobilitydatabase-2dleodl6l-mobility-data.vercel.app/feeds * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🟠 86 🟠 87 🟢 96 🟢 100

*Lighthouse ran on https://mobilitydatabase-2dleodl6l-mobility-data.vercel.app/feeds/gtfs/mdb-2126 * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🔴 37 🟢 94 🟢 96 🟢 100

*Lighthouse ran on https://mobilitydatabase-2dleodl6l-mobility-data.vercel.app/feeds/gtfs_rt/mdb-2585 * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🟢 98 🟠 83 🟢 100 🟢 100

*Lighthouse ran on https://mobilitydatabase-2dleodl6l-mobility-data.vercel.app/feeds/gbfs/gbfs-flamingo_porirua * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🟢 91 🟢 94 🟢 96 🟢 100

Copy link
Member

@davidgamez davidgamez left a comment

Choose a reason for hiding this comment

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

LGTM

@Alessandro100 Alessandro100 merged commit bd43630 into main Mar 11, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Initialize Google Analytics

3 participants