Member-only story
How to Add Google Analytics to a Next.js Application
The simplest way to add analytics to your website

Data is today the world’s most valuable commodity. So understanding how your users are using your platform is crucial for taking your business to the next level.
And in the world of analytics, Google is the leader. And the great news is it’s completely free to use! :D
Today we will see how to integrate Google analytics into a Next.js application. If you are interested in pure React, another article is for you.
If you prefer the video format of this article you can check this out.
Let’s get started!
Step 1 — Get the key
Create a new account on https://analytics.google.com/
. When you register for the first time, you will be asked to add a new property.

But if you already have a google analytics account, you can create a new property by going into the admin section of your account. Then you have to create a data stream. As we are doing this for the web, we will select web.

Then you will have to provide some details about your website. Put some dummy data for now and create the stream.

Now you will have to grab the Measurement ID
which is the most important thing in the whole process.