xavier collantes

User Metrics With Amplitude And NextJS

By Xavier Collantes

8/11/2025


Amplitude logo NextJS logo

Why Are User Analytics Important?

At Google and a couple of the startups I was at, it was extremely important to understand user metrics because you have to be user focused on every step of things you build.
To be user focused, you have to ask questions like: what does the user do? What works with the user? What does not work with the user?
Without user metrics, we are blind. Without it, we leave the fate of our world to chance.

Common Questions To Ask

As part of user focus, these are the common questions to start to ask:
  • How many users are using the product?
  • How long are users using the product?
  • What features are users using? Which do they not use?
  • Where are users coming from?
  • Which platforms do users use? iOS, Android, Web, MacOS, Windows, etc.
Once the answers are obtained from these questions, it will be clear on next steps to increase user engagement or product usage.

What is Amplitude?

Amplitude is a platform for collecting, analyzing, and acting on user behavior data.
Amplitude logo
I chose Amplitude because of its simplicity over Google Analytics and its free features over other competitors like Umami and PostHog.
I found the documentation lacking for NextJS, so I had to dig through the code to determine how to track events.

Cool Features

Autocapture: Automatically capture user interactions and page views with a few lines of code.
Unlimited feature flags: Create and manage feature flags for your application on Free plan.
Data retention for 1 year: Retain data for 1 year on Free plan. Compared to Umami's 6 months on Free tier.
Heatmaps: Visualize user interactions and page views with a heatmap. Available with the Pro plan.
Heatmap

How to Get Started with Amplitude with NextJS

Create an account on Amplitude.
Create a new project.
Add the Amplitude script to your website.
For most frameworks, you can use the Amplitude script to track events. There is a great guide by ianduhamel on how to implement Amplitude in NextJS but I found an easier way with Amplitude's new Autocapture feature.
Here's all you need to do to get started:
In the _app.tsx file, add the following code:

Specify this in the .env.local file.

ts
1const AMPLITUDE_API_KEY = process.env.NEXT_PUBLIC_AMPLITUDE_API_KEY
2
3useEffect(() => {
4  init(AMPLITUDE_API_KEY, undefined, {
5    autocapture: true,
6  })
7}, [])
8
Specify this in the .env.local file. hosted withby Xavier
You should now be able to see the events in the Amplitude dashboard.

Further Reading

Related Articles

Related by topics:

webdev
bi
Streamlit Data Visualization Cheat Sheet

For Streamlit data platform.

By Xavier Collantes1/26/2024
frontend
webdev
bi
+2

HomeFeedback