-
Notifications
You must be signed in to change notification settings - Fork 67
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
🐛 The bug
Updated Nuxt and all modules to the latest and getting the error in the title. Worked without issues before.
Here is the error stack:
GAnalytics.ts:20 Error: useHead() was called without provide context, ensure you call it through the setup() function.
at injectHead (vue.BYLJNEcq.mjs?v=1c7113e8:26:9)
at useScript (vue.cHBs6zvy.mjs?v=1c7113e8:34:33)
at useScript (useScript.js?v=1c7113e8:30:20)
at useRegistryScript (utils.js?v=1c7113e8:48:10)
at useScriptGoogleAnalytics (google-analytics.js?v=1c7113e8:9:10)
at Object.trackEvent (GAnalytics.ts:4:25)
I use this composable for firing GA events:
export const useGAnalytics = () => {
const trackEvent = (eventName: string, params: any = null) => {
try {
const { proxy } = useScriptGoogleAnalytics();
proxy.gtag("event", eventName, params);
} catch (error) {
console.error(error);
}
};
return {
trackEvent,
};
};
I simply call trackEvent in various places, script tags, on event listeners on a button, etc. Worked fine before.
The bug can be seen in the reproduction. If you try to navigate between pages, the error occurs
🛠️ To reproduce
https://stackblitz.com/edit/github-cabjusrz?file=pages%2Fabout.vue,composables%2FGA.ts
🌈 Expected behavior
Expected events to fire without throwing an error.
ℹ️ Additional context
No response
ps-20x and konstantin-karlovich-unbiased-co-uk
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working