rsnext/errors/deprecated-analyticsid.mdx
Damien Simonin Feugas 821849261d
Deprecation warning for config.analyticsId (#60677)
###  🧐 What's in there?

`config.analyticsId` is a rarely-used mechanism, initially intended to
Next.js users hosting their application themselves and willing to report
Core Web Vitals to Vercel Speed Insights.

This platform specific mechanism can be replaced with the built-in
[`useReportWebVitals`](https://nextjs.org/docs/app/api-reference/functions/use-report-web-vitals).

### 🧪 How to test?

1. make a new Next.js app
1. define env variable `VERCEL_ANALYTICS_ID` to a dummy value
1. start your application in dev mode:
   ```shell
⚠ config.analyticsId is deprecated and will be removed in next major
version. Read more:
https://nextjs.org/docs/messages/deprecated-analyticsid
   
      ▲ Next.js 14.0.5-canary.58
      - Local:        http://localhost:3000
    ✓ Ready in 917ms
   ```
1. build your application:
   ```shell
      ▲ Next.js 14.0.5-canary.58
   
      Creating an optimized production build ...
    ✓ Compiled successfully
      Linting and checking validity of types  .
⚠ The Next.js plugin was not detected in your ESLint configuration. See
https://nextjs.org/docs/basic-features/eslint#migrating-existing-config
    ✓ Linting and checking validity of types
    ✓ Collecting page data
    ✓ Generating static pages (4/4)
⚠ `config.analyticsId` is deprecated and will be removed in next major
version. Read more:
https://nextjs.org/docs/messages/deprecated-analyticsid
    ```
1. remove the env variable, add a `next.config.js` file with a dummy
`analyticsId` variable:
   ```js
   module.exports = { analyticsId: "UA-12345678-9" };
   ```
1. start your application in dev mode: it'll issue the same warning.
1. build your application: it'll issue the same warning.

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2024-01-19 14:45:05 +01:00

20 lines
893 B
Text

---
title: config.analytics is deprecated
---
## Why This Error Occurred
The Core Web Vitals of your Next.js application could be tracked and sent to any backend of your choice.
Earlier version of Next.js enable tracking by specifying `analyticsId` into your `next.config.js` file.
This configuration mechanism will be removed in nextjs@15, as it could be elegantly replaced with `useReportWebVitals` built-in hook.
## Possible Ways to Fix It
To remove this warning, you must remove `analyticsId` from your `next.config.js` file.
To keep tracking your Core Web Vitals, you could:
- use `useReportWebVitals` hook as explained [here](https://nextjs.org/docs/app/api-reference/functions/use-report-web-vitals) and send the metrics to any backend of your choice.
- [install and use](https://vercel.com/docs/speed-insights/quickstart) `@vercel/speed-insights` package into your application