Once your Nuxt JS app is ready, you will want to monitor user behavior and optimize the user experience. Google Analytics can help with that and is easily integrated with Nuxt.js. Here is how to add GA, step by step.
Let's dive in!
Before we dig in you need to know that Google Analytics is complex and a bit clunky. There are other options that give you the same insights in a slick and straightforward dashboard.
Simple Analytics is one of them. A privacy-friendly and simple analytics tool - just the insights you need in a straightforward dashboard. (And its also free yes).

All right, now let's get into answering your question!
Integrating Google Analytics
Set up Google Analytics
- Log into your GA profile (or create one, if you haven't already).
- Create a GA property for your app.
- Inspect the property and note down your Measurement ID. You will need it later.
Install the Analytics Module
Nuxt.js has a specific module for Google Analytics which simplifies the integration process. Install the @nuxtjs/google-analytics module using npm or yarn:
npm install --save @nuxtjs/google-analytics
Configure the Module in nuxt.config.js
In your nuxt.config.js file, include the Google Analytics module and configure it with your Measurement ID:
export default {
// Other configurations...
modules: [
// Other modules...
'@nuxtjs/google-analytics'
],
googleAnalytics: {
id: 'YOUR_MEASUREMENT_ID' // Replace with your Google Analytics Measurement ID
}
}
Implement Event Tracking (Optional)
If you want to track specific events like button clicks or form submissions, you can do so using the GA API in your components:
export default {
methods: {
trackEvent() {
this.$ga.event('category', 'action', 'label', value)
}
}
}
Replace 'category', 'action', 'label', and value with your specific event details.
Test and Verify
Once your application is deployed, test to ensure that page views and events are being tracked correctly. You can use tools like the Google Analytics Debugger for Chrome to help with this.
(Optional) Create New Properties
To track multiple apps, create more GA properties and use the corresponding Measurement IDs. This prevents GA from conflating the data.
Final Thoughts
Adding Google Analytics to your app can give you great insights. However, ask yourself: is Google Analytics the right tool for you?
GA is an overpowered solution for straightforward analytics. If you're looking for a simple and intuitive dashboard with the insights you need, there are better alternatives.
If this resonates with you, feel free to give Simple Analytics a spin. You just need to add the script to your app and off you go. This takes about one minute- and there is a free version as well!
Enjoy!
