vercel / analytics

Privacy-friendly, real-time traffic insights
https://vercel.com/analytics
Mozilla Public License 2.0
429 stars 26 forks source link

How to use this module in a Nuxt 3 app? #5

Closed joulev closed 2 years ago

joulev commented 2 years ago

The docs told to use inject in a main.js, but Nuxt 3 doesn't have it. I tried putting inject() or onMounted(inject) to app.vue to no avail.

The common error message is that /va/script.js doesn't exist, which is true. But then, how do I get this file? When I use this package in a Next.js 13 app, the /va/script.js is (mysteriously but conveniently) created automatically for me, but I don't know how to create it for other frameworks such as Nuxt or SvelteKit.

How should I use inject() with Nuxt 3?

tobiaslins commented 2 years ago

Hey @joulev! Have you deployed your Nuxt 3 app to Vercel? We automatically inject the script.js to your deployment when you enabled Vercel Analytics for Audiences on your project.

zernonia commented 2 years ago

Yeah the docs is wrong on how to inject to Nuxt 3. But what @joulev you did is correct. Or you can inject using plugin.

@tobiaslins somehow the /va/script.js wasn't injected automatically.

Relevant issue https://github.com/vercel/analytics/issues/1

joulev commented 2 years ago

Hi, thanks for the responses!

Indeed it looks like the 404 page is also capturing the /va/script.js and other va routes. I think I will wait for the official docs on how to handle this matter then.

Since this issue is a duplicate of #1 now, I will close it.