Skip to content

Commit c78bd3c

Browse files
committed
add doc for instrumentation client hook
1 parent 03ce7f5 commit c78bd3c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: clientInstrumentationHook
3+
description: Enable client-side instrumentation.
4+
version: experimental
5+
---
6+
7+
## Usage
8+
9+
When enabled, Next.js searches for an `instrumentation-client.ts` file at the project root and executes it synchronously before hydration. This file is bundled into the initial JavaScript chunk, allowing you to run analytics or monitoring before any other code executes. The code in this file runs exclusively on the client side and is not executed during server-side rendering (SSR).
10+
11+
> **Good to know:**
12+
>
13+
> - Client instrumentation increases bundle size and execution time, so keep it minimal to avoid delaying interactivity.
14+
15+
```ts filename="next.config.ts" switcher
16+
import type { NextConfig } from 'next'
17+
18+
const nextConfig: NextConfig = {
19+
experimental: {
20+
clientInstrumentationHook: true,
21+
},
22+
}
23+
24+
export default nextConfig
25+
```
26+
27+
```js filename="next.config.js" switcher
28+
/** @type {import('next').NextConfig} */
29+
const nextConfig = {
30+
experimental: {
31+
clientInstrumentationHook: true,
32+
},
33+
}
34+
35+
module.exports = nextConfig
36+
```

0 commit comments

Comments
 (0)