question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for nuxt 3

See original GitHub issue

Adding the google analytics module to nuxt 3 generates the following errors:

  • ERROR Error compiling template
  • ERROR Cannot start nuxt: serialize is not defined

Here my nuxt config

import { defineNuxtConfig } from 'nuxt3'

// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({
    css: ["~/assets/css/styles.css"],
    build: {
        postcss: {
            postcssOptions: require("./postcss.config.js"),
        },
    },
    modules: [
        ['@nuxtjs/google-analytics', { ua: 'X1234567' }],
    ]
})

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:12

github_iconTop GitHub Comments

3reactions
cayekplecommented, Mar 8, 2022

@afiorenza Yes, I changed the package to yarn add vue-gtag-next, then I created vue-gtag.client.js in the plugins folder at the project root.

vue-gtag.client.js

import { defineNuxtPlugin } from '#app'
import VueGtag from 'vue-gtag-next'

export default defineNuxtPlugin((nuxtApp) => {
  const getGDPR = localStorage.getItem('GDPR:accepted');
  nuxtApp.vueApp.use(VueGtag, {
    property: {
      id: 'G-XXXXXXXXX
    },
    appName: 'APP NAME',
    enabled: getGDPR === 'true',
    pageTrackerScreenviewEnabled: true
  }, nuxtApp.vueApp.router);
});
2reactions
adarshmadrechacommented, Oct 19, 2022

For nuxt 3 RC 11, the below code works fine.

Create ga.js file in plugins folder. No need to import or change anything in nuxt.config.js. You can name anything actually. I have named it ga.js.

import VueGtag from 'vue-gtag'

export default defineNuxtPlugin((nuxtApp) => {
    nuxtApp.vueApp.use(VueGtag, {
        config: {
            id: 'GA_MEASUREMENT_ID',
        },
    }, nuxtApp.$router)
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

feat!: Add support for Nuxt 3 by dankerow · Pull Request #12
This PR enables this module to work for Nuxt 3. Notable changes Uses @nuxt/module-builder to build module. Refactor structure (lib -> src, ...
Read more >
Nuxt 3 first steps. - ITNEXT
OK, first things first. What's nuxi ? It's the new Nuxt CLI (Command Line Interface) that will help you install and manage all...
Read more >
Modules - Migrate to Nuxt 3
Plugins or components using the Composition API need exclusive Vue 2 or Vue 3 support. By using vue-demi they should be compatible with...
Read more >
Configuration - Nuxt
This default configuration can be overwritten with the nuxt.config.js file. ... In nuxt.config.js , add the CSS resources: nuxt.config.js
Read more >
Nuxt 3 integration - Vue I18n - Intlify
In the following sections, we will work on Nuxt 3 applications that support English, French, and Japanese. Add language switching #. We will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found