vercel / analytics

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

Getting 404 for `script.js` #1

Closed bogy0 closed 2 years ago

bogy0 commented 2 years ago

First of all, great work with the updates. Watching the conference was really inspiring. Of course, my first thing to do was to update one of my Next.js projects and try the new goodies.

At one point I decided to try out this new Analytics feature called Audiences, but after adding it to the project I am getting these errors in the console. Screenshot 2022-10-25 at 23 46 55

After some quick search in the vercel org I came across this repository where I found a reference for this va/script.js file. Screenshot 2022-10-25 at 23 50 22

Overall, the audiences feature is working, I am getting visitor data in the newly enabled dashboard page; the issue only is that the browser logging this error.

If you need further details, example codes, let me know, but what i did was basically follow your guide:

import { Analytics } from '@vercel/analytics/react';

import '../styles/globals.css'

const MyApp = ({Component, pageProps }) => {
  return (
      <>
        <Component {...pageProps} />
        <Analytics />
      </>
  );
}

export default MyApp
frontsideair commented 2 years ago

I'm also having a similar problem. I don't get any analytics data on my dashboard though.

I added this to my Gatsby project by adding inject to gatsby-browser.js, which does its job and adds the script to the <head>. But the va/script.js gives a 404, which makes sense because there's no such file anywhere. Is Vercel supposed to intercept and serve this file?

I also have rewrites defined in my project so maybe this is overriding the hypothesized intercept. This may be an edge case.

NuroDev commented 2 years ago

But the va/script.js gives a 404, which makes sense because there's no such file anywhere. Is Vercel supposed to intercept and serve this file?

Yeah same here. Have another site that has this package working & manually added the /va/script.js to my public/ directory but then got another error from failing to post to /va/view.

Does seem like it's usually expected that Vercel will add / intercept any requests to /va/... endpoint(s) but it isn't for some reason?

alex-grover commented 2 years ago

Seeing a 404 as well with an Astro project, using both the plain HTML approach as well as using inject().

max commented 2 years ago

Possibly not the reason y'all are seeing the error but I was also getting a 404 for the injected script when deploying @vercel/analytics. Turns out you first have to enable the feature in the dashboard and then deploy the library (a re-deploy fixed it for me).

bogy0 commented 2 years ago

Unfortunately, re-deploying my project is not solved the error log in my case.

chriswdmr commented 2 years ago

As @max correctly pointed out, the mentioned path /va/script.js will become available on your next deployment after you enabled the feature.

If you added the package before you enabled the feature, you can trigger a redeployment which has the same effect.

@bogy0 It seems like the error you're seeing is related to your browser as you already get data. Have you tried disabling all extensions/ad-blockers?

tomegger commented 2 years ago

Same problem here. Iยดve already tried all steps (re-deploying, enabling/disabling, etc.) but still have the same error as @bogy0.

chriswdmr commented 2 years ago

Would you mind creating a minimal reproduction?

Ideally a small repo that gets deployed to Vercel so we can have a closer look!

bogy0 commented 2 years ago

will do later today

tomegger commented 2 years ago

Iยดve also a simple app if you want to take a look

frontsideair commented 2 years ago

I also tried redeploying but didn't work in my case. It's not minimal but my blog, for which I want to use the analytics, is open-source.

chriswdmr commented 2 years ago

I also tried redeploying but didn't work in my case. It's not minimal but my blog, for which I want to use the analytics, is open-source.

Thanks for providing an example!

It seems like that your custom 404 page is catching all routes โ€“ including the /va/script.js URL. You have to instrument Gatsby in a way that it ignores this URL.

frontsideair commented 2 years ago

Thanks, I added the redirect manually to bypass Gatsby with the this config, which is transformed with gatsby-plugin-zeit-now plugin. This fixed the 404 issue and requests are actually sent and response is received, but my dashboard doesn't load any data.

chriswdmr commented 2 years ago

@frontsideair the script is available behind your own domain and not via vercel.com. Please change vercel.com to your own domain.

frontsideair commented 2 years ago

I understand and removed the redirect to vercel.com, I haven't found a good workaround so I'm giving up on this for now. Waiting for an official solution.

mehulmpt commented 2 years ago

Same for us. With rewrites enabled the @vercel/analytics script throws 404.

GizmoRay commented 2 years ago

+1 - facing the same issue. Some guidance on how best to handle both a 404 page + allowing the analytics package to come through would be great.

pyronaur commented 2 years ago

I created a static blank /va/script.js on my Astro site in hopes that would get replaced, but looks like that didn't do anything either.

vojto commented 2 years ago

Same issue with SvelteKit.

schnubor commented 2 years ago

Having the same problem (script 404) on a Next 13 app (still using /pages) with a custom 404 page. disabled & enabled the feature in the vercel UI again and redeployed, still 404ing. Also not seeing any data in the Audience dashboard which I think is just a side effect. It says "Vercel Analytics is set up, but detected a non-production environment." on my local though, so it's at least trying to do something.

diffTed commented 2 years ago

Same here (Next 13)

tobiaslins commented 2 years ago

We're actively working on a solution for this issue. We'll keep you posted!

sgarcia22 commented 2 years ago

Same problem, I get a Uncaught SyntaxError: Unexpected token '<' (at script.js:1:1) and cannot access any analytics.

I'm using Vue v2, and tried injecting it with the inject() call in both the app.js mounted() callback, and in main.js when creating the Vue app.

Also tried using it in the HTML <script async src="/va/script.js"></script>.

In my routes I have this however, not sure if that is causing a problem like the comments above or how I would go about fixing that.

  {
    path: "/:catchAll(.*)",
    name: "NotFound",
    redirect: "/",
    meta: {title: "๐Ÿ˜” - 404"},
  },
remisture commented 2 years ago

We're actively working on a solution for this issue. We'll keep you posted!

Any updates?

aprendendofelipe commented 2 years ago

There seems to be an incompatibility with the i18n configuration in next.config.js.

JoshLittlewood commented 2 years ago

Removing i18n from my next.config.js did resolve the issue for me.

paulmwatson commented 2 years ago

Happening on our NextJS site hosted on Vercel too. i18n worth more than analytics at the moment so will wait for official fix.

tobiaslins commented 2 years ago

Hey everyone! We just rolled out the fix for this issue. You will have to redeploy your apps to make it work.

Let us know how it goes ๐Ÿ™Œ

paulmwatson commented 2 years ago

Thanks @tobiaslins but I'm getting the same error. Re-enabled the analytics, updated the code, re-deployed, but same https://www.somersetstrikers.co.za/va/script.js 404 error.

alex-grover commented 2 years ago

I got the analytics to work using the plain HTML approach in my project (didn't even need to install the NPM package). Thank you!

joulev commented 2 years ago

@tobiaslins Can confirm that it is working now for my Nuxt app (#5). I got another app (SvelteKit) working with a similar method too.

dglsparsons commented 2 years ago

Thanks @tobiaslins but I'm getting the same error. Re-enabled the analytics, updated the code, re-deployed, but same https://www.somersetstrikers.co.za/va/script.js 404 error.

Hi @paulmwatson, it looks like you enabled Analytics after deploying the project. It needs to be enabled before making the deployment. Could you re-deploy again and check? :)

frontsideair commented 2 years ago

Works for me as well, thanks! As a docs suggestion, I added the inject script to gatsby-node.js for Gatsby, as it seemed like the correct place for it.

paulmwatson commented 2 years ago

Thanks @dglsparsons, just did a re-deploy there (leaving analytics enabled) and same error.

darasus commented 2 years ago

Same, redeployed multiple times while analytics enabled and still seeing 404

dglsparsons commented 2 years ago

Okay, it seems like we still have some issues relating to i18n interfering with analytics. We're working on a fix for sites using i18n now. I believe sites without i18n should work fine though.

vacodoceo commented 2 years ago

@tobiaslins still having the same error with SvelteKit

tobiaslins commented 2 years ago

@vacodoceo can you please share the last deployment url with us to take a closer look?

Robin-w151 commented 2 years ago

I can confirm that it is now working for my SvelteKit app after I did a redeployment and leaving audiences enabled.

dglsparsons commented 2 years ago

Hi, further update here: we've shipped a change that should resolve any issues with i18n interference. You'll need to redeploy (again) to see the changes, but ๐Ÿคž this resolves any remaining issues! Let me know if it doesn't work :)

vacodoceo commented 2 years ago

@tobiaslins I just checked again and it's working. I enabled audiences, redeployed, and it started working. It's strange because I redeployed a couple of times an hour ago and it didn't work, and I don't think enabling audiences was what fixed it.

Anyway, thanks for the support!

tobiaslins commented 2 years ago

@vacodoceo we just rolled out a fix for i18n, it takes a while until it's available for everyone! thanks for confirming ๐Ÿค—

tjkohli commented 2 years ago

It works with SvelteKit after redeploying! Thank you so much. ๐Ÿ™๐Ÿผ

tomegger commented 2 years ago

It works now! ๐Ÿ™Œ

paulmwatson commented 2 years ago

Excellent, it works now, thanks for the work

mehulmpt commented 2 years ago

Works for us too ๐Ÿ™Œ

schnubor commented 2 years ago

Works, thanks! :)

aprendendofelipe commented 2 years ago

Now it's working with i18n. Thanks!

Dogtiti commented 1 year ago

same issue

tobiaslins commented 1 year ago

@FlatMapIO @Dogtiti can you please send me a deployment URL so I can take a look for you? Happy to dig deep!