Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vercel analytics file missing #6230

Closed
1 task
fschroiff opened this issue Feb 13, 2023 · 6 comments
Closed
1 task

Vercel analytics file missing #6230

fschroiff opened this issue Feb 13, 2023 · 6 comments

Comments

@fschroiff
Copy link

fschroiff commented Feb 13, 2023

What version of astro are you using?

2.0.10

Are you using an SSR adapter? If so, which one?

Vercel

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

On my site https://www.fsch.ro I get a 404 on the file /_vercel/insights/script.js.
also when building locally I don’t see the script.js file.

This is my config:

import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
import tailwind from "@astrojs/tailwind";
import prefetch from "@astrojs/prefetch";
import vercel from "@astrojs/vercel/static";

export default defineConfig({
  site: 'https://fsch.ro',
  integrations: [sitemap(), tailwind(), prefetch()],
  adapter: vercel({
    analytics: true
  })
});

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-4s4gze?file=package.json

Participation

  • I am willing to submit a pull request for this issue.
@mfrachet
Copy link
Contributor

mfrachet commented Feb 13, 2023

(I may be wrong) I'm feeling that this issue is about this specific loc from @vercel/analytics: https://github.com/vercel/analytics/blob/main/packages/web/src/generic.ts#L20

From my understanding, Vercel should add this script (see the "else" part of the ternary above) but for some reasons, it does not 🤔

Have you tried enabling analytics and the re-building (without cache)?

@fschroiff
Copy link
Author

I had to also enable "Audiences" in the Vercel Analytics settings and redeploy. Now the script.js gets added.
Maybe some additional check is needed. Or it could be noted in the docs that you need to activate both options (web vitals and audiences) in Vercel Analytics.

@fschroiff
Copy link
Author

Could it be that for Web Vitals you don't need to add anything to your Astro setup? That the analytics package is only needed for the audiences feature?

@delucis
Copy link
Member

delucis commented Feb 15, 2023

@fschroiff I see the script loading successfully on your site:
image

It could be that you have a browser extension that blocks tracking scripts? I also see a 404 when enabling Ghostery as Ghostery recognises Vercel’s analytics scripts and blocks it.

Locally this script is not available though as it is injected by Vercel (and you probably don’t want to collect analytics from local development). Maybe we should avoid injecting the analytics script during development?

@fschroiff
Copy link
Author

fschroiff commented Feb 16, 2023

@delucis After enabling "Audiences" analytics in the Vercel dashboard and redeploying without cache everything worked as expected.

Theres two types of analytics in Vercel: "Web Vitals" and "Audiences". For the "Web Vitals" you don't need to install this analytics package at all. For "Audiences" you need this package.

I thought the analytics package was needed for "Web Vitals" as well. This is not the case.

So what happened was: I installed the analytics package and activated "Web Vitals". The package adds the link to script.js, but as I have not activated "Audiences" Vercel has not added the script.js file. Hence the error.

Could you make the analytics package add the script.js file only when "Audiences" is active? I guess it would be better/ easier to tweak the docs a bit.

@delucis
Copy link
Member

delucis commented Feb 16, 2023

I don’t think we can know if a deployment has “Audiences” enabled or not but can definitely document that you need to manually enable it. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants