0

I want to add google analytics tracking to my app, and I want to connect user UID with activity. So I need to run script every time page is loaded to connect it. From what I know, best way to do this is by creating Nuxt plugin.

I don't have any experience with plugin, but whenever I write some code that requires my other code, mainly in /composables directory, it throws this error:

nuxt.mjs?v=c5fad482:159 Uncaught Error: nuxt instance unavailable
    at useNuxtApp (nuxt.mjs?v=c5fad482:159:13)
    at useRuntimeConfig (nuxt.mjs?v=c5fad482:166:10)
    at config.ts:32:1

My plugin code:

import { analytics } from "@/composables/api/analytics";

export default defineNuxtPlugin((nuxtApp) => {
  analytics.setUserID("dev");
});

analytics.setUserID is my own imported function from /composables

Eflyax
  • 5,307
  • 2
  • 19
  • 29

0 Answers0