Skip to content

feat(analytics): integrate Google Analytics (Closes #40)#98

Merged
priyankarpal merged 4 commits into
reactplay:mainfrom
mdnm18:feat/40-analytics-integration
Oct 25, 2025
Merged

feat(analytics): integrate Google Analytics (Closes #40)#98
priyankarpal merged 4 commits into
reactplay:mainfrom
mdnm18:feat/40-analytics-integration

Conversation

@mdnm18
Copy link
Copy Markdown
Contributor

@mdnm18 mdnm18 commented Oct 24, 2025

Resolves #40. Adds Google Analytics using @next/third-parties/google. Tracks page views automatically and adds custom event tracking for key CTA buttons.

Summary

This PR integrates Google Analytics 4 (GA4) into the application using the official @next/third-parties/google package. It fulfills Issue #40 by tracking page views, event clicks, and engagement without affecting performance.

Changes

  • Installed the @next/third-parties package.
  • Added NEXT_PUBLIC_GA_ID to .env.local (currently using a placeholder).
  • Added the <GoogleAnalytics /> component to src/app/[locale]/layout.tsx to enable automatic page view tracking.
  • Created a utility function trackGAEvent in src/utils/analytics.ts for sending custom events.
  • Added trackGAEvent calls (with "use client";) to track clicks on:
    • "Join the Community" buttons in the Navbar (navbar/index.tsx).
    • "Join the Community" and "See Upcoming Events" buttons in the Hero section (hero/index.tsx).
    • Social media icons in the Footer (footer/index.tsx).

Testing

I tested these changes locally by:

  1. Running the project using docker-compose up.
  2. Opening the browser's Network tab and filtering for google-analytics.com.
  3. Verified that gtag/js and collect requests were sent on page load and on client-side navigation (clicking navbar links).
  4. Verified that new collect requests were sent immediately upon clicking the tracked buttons (Join Community, See Events, Social Icons).

Screenshot 2025-10-25 at 12 58 36 AM

Related Issue

Resolves #40

Notes

  • The implementation uses the NEXT_PUBLIC_GA_ID environment variable. The actual Measurement ID needs to be provided and configured in the deployment environment for data to appear in the real GA dashboard.

Resolves reactplay#40. Adds Google Analytics using @next/third-parties/google. Tracks page views automatically and adds custom event tracking for key CTA buttons.
@netlify
Copy link
Copy Markdown

netlify Bot commented Oct 24, 2025

Deploy Preview for reactkolkata ready!

Name Link
🔨 Latest commit f7dad71
🔍 Latest deploy log https://app.netlify.com/projects/reactkolkata/deploys/68fcd3534a2b5a0008dd3cc0
😎 Deploy Preview https://deploy-preview-98--reactkolkata.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@mdnm18
Copy link
Copy Markdown
Contributor Author

mdnm18 commented Oct 25, 2025

@priyankarpal The build failure is fixed now. This PR should be ready to merge. Please let me know if you need the actual Google Analytics ID added before merging, or if it will be configured later in the deployment settings.

removed package-lock.json

Signed-off-by: Priyankar Pal  <88102392+priyankarpal@users.noreply.github.com>
Copy link
Copy Markdown
Member

@priyankarpal priyankarpal left a comment

Choose a reason for hiding this comment

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

looks good 🎉 adding env to the cloud provider

@priyankarpal priyankarpal merged commit 0c610c2 into reactplay:main Oct 25, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analytics Integration

2 participants