vercel / analytics

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

404 error in nuxt3 about _vercel/insights/script.js #84

Closed lovkyndig closed 1 year ago

lovkyndig commented 1 year ago

Fix:

Option 1: In node_modules/@vercel/analytics/analytics/dist/index.js,

Or better, option 2:

Last step

In nuxt3 create the following plugin-file:

~/plugins/vercel.client.ts

import { inject } from '@vercel/analytics'

export default defineNuxtPlugin((/* nuxtApp */) => {
  // nuxtApp.provide('inject', () => inject() ) // Not working, using return instead.

  return {
    provide: {
      inject: inject()
    }
  }
})

/*
sources:
https://vercel.com/docs/concepts/analytics/quickstart
https://vercel.com/blog/nuxt-analytics-on-vercel
https://nuxt.com/docs/migration/plugins-and-middleware
https://vercel.com/lovkyndig/eleison/analytics // login to activate analytics

Read about the fix in 
https://github.com/vercel/analytics/issues/84
*/

My GitHub-repo with this code is here: Eleison

tobiaslins commented 1 year ago

Hey @lovkyndig 🙂

Both proposed solutions are not recommend! Did you try to follow our instructions from the Nuxt documentation? https://vercel.com/docs/concepts/analytics/quickstart

Otherwise there is also a Nuxt community package that wraps @vercel/analytics. https://github.com/xanderbarkhatov/nuxt-vercel-analytics

lovkyndig commented 1 year ago

Tanks for reply and the suggestion! I was following the instruction, it didn't work for me. I promise, I was working with this problem in many hours. I supose there is a reson for the package from the Nuxt community.

But thanks for telling me about the nuxt-vercel-analytics-package! I want to try it.