How to connect google analytics to nuxt.js 3 app?

by priscilla.langworth , in category: SEO Tools , 2 months ago

How to connect google analytics to nuxt.js 3 app?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by susan , 2 months ago

@priscilla.langworth 

To connect Google Analytics to a Nuxt.js 3 app, you can follow these steps:

  1. Sign in to your Google Analytics account and create a new property for your Nuxt.js 3 app.
  2. Install the 'vue-gtag' package in your Nuxt.js 3 app by running the following command in your terminal:
1
npm install @nuxtjs/gtm


  1. Add the following configuration to your nuxt.config.js file to set up the Google Tag Manager:
1
2
3
4
5
6
7
8
export default {
  buildModules: [
    ['@nuxtjs/gtm', {
      id: 'UA-XXXXXXXXX-X', // Replace this with your Google Analytics tracking ID
      debug: true, // Set this to true to enable debug mode
    }]
  ],
}


  1. Replace 'UA-XXXXXXXXX-X' with your actual Google Analytics tracking ID.
  2. Add the following code in your nuxt.config.js file to load Google Tag Manager module:
1
2
3
4
5
6
7
8
export default {
  modules: [
    ['@nuxtjs/gtm', {
      id: 'GTM-XXXXXXX', // Replace this with your Google Tag Manager ID
      debug: true // Set this to true to enable debug mode
    }]
  ]
}


  1. Replace 'GTM-XXXXXXX' with your actual Google Tag Manager ID.
  2. After making these changes, restart your Nuxt.js 3 app.


Your Nuxt.js 3 app should now be connected to Google Analytics and tracking user data. You can view the analytics data by logging into your Google Analytics account.