# next-script-for-ga

Rule `nextjs/next-script-for-ga`. Prefer `@next/third-parties/google` when using the inline script for Google Analytics and Tag Manager.

- Source: nextjs
- Technologies: Next.js, React
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 99.7M weekly downloads of presets that enable it
- Trend: +49.8% last quarter
- Rank: #160 by reach, #827 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `@next/next/next-script-for-ga` | yes | no | package `@next/eslint-plugin-next` | [docs](https://nextjs.org/docs/messages/next-script-for-ga) |
| Oxlint | `nextjs/next-script-for-ga` | no | no | plugin `nextjs`, category correctness | [docs](https://oxc.rs/docs/guide/usage/linter/rules/nextjs/next-script-for-ga.html) |
| Biome | `nursery/useNextScriptForGoogleAnalytics` | no | no | group nursery, since 2.6.6 | [docs](https://biomejs.dev/linter/rules/use-next-script-for-google-analytics/) |

## Code examples

### Correct: the rule accepts this

```tsx
import { GoogleAnalytics } from '@next/third-parties/google'

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>{children}</body>
      <GoogleAnalytics gaId="G-XYZ" />
    </html>
  )
}
```

```jsx
import { GoogleAnalytics } from '@next/third-parties/google'

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>{children}</body>
      <GoogleAnalytics gaId="G-XYZ" />
    </html>
  )
}
```

```jsx
import { GoogleAnalytics } from '@next/third-parties/google'

export default function Page() {
  return <GoogleAnalytics gaId="G-XYZ" />
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import next from "@next/eslint-plugin-next";

export default [
  {
    plugins: { "@next/next": next },
    rules: {
      "@next/next/next-script-for-ga": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "nextjs"
  ],
  "rules": {
    "nextjs/next-script-for-ga": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "useNextScriptForGoogleAnalytics": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Next.js recommended](https://lintradar.dev/presets/next-recommended.md) | ESLint | `@next/eslint-plugin-next` | 22 | 52.9M | +50.7% |
| [Next.js Core Web Vitals](https://lintradar.dev/presets/next-core-web-vitals.md) | ESLint | `eslint-config-next` | 62 | 46.8M | +48.8% |

## Related rules

- [nextjs/no-async-client-component](https://lintradar.dev/rules/nextjs/no-async-client-component.md): Prevent Client Components from being async functions.
- [nextjs/no-before-interactive-script-outside-document](https://lintradar.dev/rules/nextjs/no-before-interactive-script-outside-document.md): Prevent usage of `next/script`'s `beforeInteractive` strategy outside of `pages/_document.js`.
- [nextjs/no-sync-scripts](https://lintradar.dev/rules/nextjs/no-sync-scripts.md): Prevent synchronous scripts.
- [nextjs/no-assign-module-variable](https://lintradar.dev/rules/nextjs/no-assign-module-variable.md): Prevent assignment to the `module` variable.
- [nextjs/no-css-tags](https://lintradar.dev/rules/nextjs/no-css-tags.md): Prevent manual stylesheet tags.
- [nextjs/no-duplicate-head](https://lintradar.dev/rules/nextjs/no-duplicate-head.md): Prevent duplicate usage of `<Head>` in `pages/_document.js`.

---

Web page: https://lintradar.dev/rules/nextjs/next-script-for-ga. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
