Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt3 with "bootstrap: false" : Cannot read properties of undefined (reading 'pageview') #534

Open
kaboume opened this issue Apr 2, 2023 · 2 comments

Comments

@kaboume
Copy link

kaboume commented Apr 2, 2023

Please fill in at least the mandatory (*) questions below, or I will immediately close this issue without reading. Thanks

Environment *

Run this command in the project folder and fill in their results:

npm ls vue-gtag:
└── [email protected]

npm ls vue:
├─┬ @pinia/[email protected]
│ └─┬ [email protected]
│ └── [email protected] deduped
├─┬ @vue-leaflet/[email protected]
│ └─┬ [email protected]
│ └─┬ @vue/[email protected]
│ └── [email protected] deduped
├─┬ @vuepic/[email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ ├─┬ @nuxt/[email protected]
│ │ ├─┬ @vitejs/[email protected]
│ │ │ └── [email protected] deduped
│ │ ├─┬ @vitejs/[email protected]
│ │ │ └── [email protected] deduped
│ │ └── [email protected] deduped
│ ├─┬ @unhead/[email protected]
│ │ └── [email protected] deduped
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ └── [email protected] deduped
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
└─┬ [email protected]
└── [email protected] deduped

Description *

My App is under vue3 & Nuxt3.
I would like to send the event "pageview" only if the user consented to the rgpd banner.

So, I created in the "plugins" folder of my Nuxt3 application a file named : analytics.client.js with this content :

import VueGtag from 'vue-gtag'
export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(VueGtag, {
    bootstrap: false,
    config: {
      id: 'G-XXXXXXXXXXXX',
    },
  }, nuxtApp.$router)
})

And in my Nuxt Page, I added :

<script setup>
import { bootstrap } from 'vue-gtag'
....

onMounted(() => {
  bootstrap().then((gtag) => {
    console.log('gtag', gtag)
    gtag.pageview(route.fullPath)
  })
})
</script>

Then when I load the page, I have this messages :

gtag undefined
my-page.vue:55 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'pageview')

@peterbabinec
Copy link

I am experiencing the same, using "vue-gtag": "^1.16.1" and "vue": "^2.7.13":

configuration:

  vue.use(VueGtag, {
    disableScriptLoad: false,
    bootstrap: false,
    config: { id: "G-XXXXXXXXXXXX" },
  });

and then doing this produces Uncaught (in promise) TypeError: gtag is undefined:

import { bootstrap } from "vue-gtag";
...
    async register() {
      bootstrap().then((gtag) => {
        gtag.event("register", { method: "Test" });
      });
      ...
    },

However when I call it with this.$gtag inside then block it works fine. Not sure if that's intended behaviour or not.

@ionut-tatu
Copy link

Any solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants