DEV Community

Mahdi Hosseini
Mahdi Hosseini

Posted on

Monitoring Frontend Applications in Next.js, From Errors to Insights 🚀

Image description
Hey there! 👋 
I'm Mahdi, a frontend developer with a few years of experience working with React and particularly Next.js. In this article, I want to share my real-world experience with monitoring in frontend projects - something I underestimated until a few serious bugs hit our production environment and taught me otherwise. 😅

Why Monitoring Matters in Frontend 🤔

The thing about frontend is that our code runs on the user's browser, not our own machine. Everything might seem perfect in development, but do we really know: 
🔹 Are users experiencing errors? 
🔹 Is the page loading fast? 
🔹 Does Safari behave differently? 
🔹 Are key interactions breaking?
To answer these questions, proper monitoring is essential. 💡

What Should We Monitor? 📊

Before diving into tools, let's define what we actually want to keep an eye on: 
🔹 JavaScript runtime errors 
🔹 Failed API requests 
🔹 Core Web Vitals (LCP, FID, CLS, etc.) 
🔹 UI freezes or crashes 
🔹 User behavior (rage clicks, drop-offs, session flows)

Tools I've Used and Recommend 🛠️

Sentry - My First Line of Defense 🛡️

Sentry is always the first thing I set up in my Next.js projects. It gives detailed error tracking, browser context, and user insights. It helps me catch unexpected bugs early and fix them with confidence. 🚀

LogRocket - Replay User Sessions 🎥

If Sentry tells you what went wrong, LogRocket shows you how it happened. It records user sessions, including mouse movements, clicks, and DOM changes. It has saved me so much time debugging issues that only occur under specific circumstances. 🕵️‍♂️

Vercel Analytics - Lightweight Performance Monitoring 📈

If you're using Vercel, their built-in analytics tool is a great way to track performance metrics like page load times and layout shifts. It's simple, privacy-friendly, and requires zero setup. 😎

Google Analytics (GA4) - Track User Behavior 📊

GA4 gives high-level insights into how users move through your app, where they drop off, and what events they trigger. It helps connect technical metrics with business goals. 💼

Custom Logging - Tailored to Your Product 🛠️

Sometimes generic tools aren't enough. I also implement custom logging for specific user actions or edge cases that matter to my product team. It's lightweight, flexible, and surprisingly powerful. ⚡

Monitoring Is a Culture, Not Just a Tool 🌟

In one of the teams I worked with, we had a simple pre-release checklist that made all the difference: 
🔹 Is Sentry enabled for this module? 
🔹 Are critical errors being alerted via email or Slack? 
🔹 Are we tracking important user actions? 
🔹 Are performance metrics being recorded?
Monitoring isn't something you "add later." It should be part of the delivery process from day one. ✅

A Real-World Story 📖

One day, a user reported that the app "just doesn't load" - but only in Safari. Everything worked fine on Chrome and Firefox. 
Thanks to monitoring, I discovered that an optional chaining operator caused a crash in Safari 13, which didn't support it. I shipped a quick patch, and the issue disappeared. 🛠️ 
Without monitoring, I would have had no idea this bug existed. 😱

Final Thoughts 💬

Monitoring in a frontend Next.js app isn't a luxury - it's a requirement. Start with Sentry for error reporting, add LogRocket for session replays, and use GA4 or Vercel Analytics for behavior and performance tracking. 
Monitor. Understand. Improve. 🌈
If you've had similar experiences or want to share tools that worked for you, I'd love to hear about them. 😊

  • Mahdi

Top comments (1)

Collapse
 
lovit_js profile image
Lovit

Thanks for sharing