vybekiit 0.7.34 → 0.7.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +520 -9
- package/dist/global-skills/eas-app-stores/SKILL.md +2 -2
- package/dist/global-skills/eas-hosting/SKILL.md +2 -2
- package/dist/global-skills/eas-observe/SKILL.md +7 -15
- package/dist/global-skills/eas-observe/references/queries.md +51 -10
- package/dist/global-skills/eas-observe/references/setup.md +60 -7
- package/dist/global-skills/eas-simulator/SKILL.md +2 -2
- package/dist/global-skills/eas-simulator/references/run-your-app.md +2 -0
- package/dist/global-skills/eas-update/SKILL.md +2 -2
- package/dist/global-skills/eas-update-insights/SKILL.md +2 -2
- package/dist/global-skills/eas-workflows/SKILL.md +2 -2
- package/dist/global-skills/expo-animation/SKILL.md +2 -2
- package/dist/global-skills/expo-app-clip/SKILL.md +2 -2
- package/dist/global-skills/expo-brownfield/SKILL.md +2 -2
- package/dist/global-skills/expo-data-fetching/SKILL.md +2 -2
- package/dist/global-skills/expo-design-system/SKILL.md +2 -2
- package/dist/global-skills/expo-dev-client/SKILL.md +4 -2
- package/dist/global-skills/expo-dom/SKILL.md +2 -2
- package/dist/global-skills/expo-examples/SKILL.md +2 -2
- package/dist/global-skills/expo-migrate-module/SKILL.md +2 -2
- package/dist/global-skills/expo-module/SKILL.md +2 -2
- package/dist/global-skills/expo-native-ui/SKILL.md +2 -2
- package/dist/global-skills/expo-overview/SKILL.md +9 -4
- package/dist/global-skills/expo-overview/references/launch-without-dev-menu.md +24 -0
- package/dist/global-skills/expo-project-structure/SKILL.md +2 -2
- package/dist/global-skills/expo-router/SKILL.md +2 -2
- package/dist/global-skills/expo-ui/SKILL.md +2 -2
- package/dist/global-skills/expo-upgrade/SKILL.md +2 -2
- package/dist/global-skills/expo-web-to-native/SKILL.md +2 -2
- package/dist/global-skills/expo-web-to-native/references/verify-on-device.md +1 -1
- package/dist/global-skills/firebase-app-hosting-basics/SKILL.md +16 -3
- package/dist/global-skills/firebase-app-hosting-basics/references/cli_commands.md +10 -12
- package/dist/global-skills/firebase-app-hosting-basics/references/configuration.md +2 -1
- package/dist/global-skills/firebase-basics/SKILL.md +6 -4
- package/dist/global-skills/firebase-basics/references/web_setup.md +3 -3
- package/dist/global-skills/instrument-feature-flags/references/adding-feature-flag-code.md +81 -333
- package/dist/global-skills/instrument-feature-flags/references/android.md +19 -13
- package/dist/global-skills/instrument-feature-flags/references/api.md +17 -13
- package/dist/global-skills/instrument-feature-flags/references/best-practices.md +35 -35
- package/dist/global-skills/instrument-feature-flags/references/django.md +120 -72
- package/dist/global-skills/instrument-feature-flags/references/dotnet.md +48 -102
- package/dist/global-skills/instrument-feature-flags/references/elixir.md +4 -10
- package/dist/global-skills/instrument-feature-flags/references/flask.md +55 -39
- package/dist/global-skills/instrument-feature-flags/references/flutter.md +19 -13
- package/dist/global-skills/instrument-feature-flags/references/go.md +21 -13
- package/dist/global-skills/instrument-feature-flags/references/ios.md +19 -13
- package/dist/global-skills/instrument-feature-flags/references/java.md +4 -12
- package/dist/global-skills/instrument-feature-flags/references/laravel.md +18 -16
- package/dist/global-skills/instrument-feature-flags/references/next-js.md +44 -54
- package/dist/global-skills/instrument-feature-flags/references/nodejs.md +21 -13
- package/dist/global-skills/instrument-feature-flags/references/php.md +21 -13
- package/dist/global-skills/instrument-feature-flags/references/python.md +22 -14
- package/dist/global-skills/instrument-feature-flags/references/react-native.md +18 -13
- package/dist/global-skills/instrument-feature-flags/references/react.md +21 -14
- package/dist/global-skills/instrument-feature-flags/references/ruby-on-rails.md +31 -68
- package/dist/global-skills/instrument-feature-flags/references/ruby.md +21 -13
- package/dist/global-skills/instrument-feature-flags/references/rust.md +10 -34
- package/dist/global-skills/instrument-feature-flags/references/usage.md +94 -114
- package/dist/global-skills/instrument-feature-flags/references/web.md +21 -13
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-android.md +7 -7
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-expo.md +2 -2
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-fastapi.md +1 -1
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-flask.md +1 -1
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-laravel.md +2 -2
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-php.md +1 -1
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-python.md +1 -1
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-ruby.md +1 -1
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-swift.md +4 -4
- package/dist/global-skills/instrument-product-analytics/references/android.md +64 -109
- package/dist/global-skills/instrument-product-analytics/references/angular.md +32 -28
- package/dist/global-skills/instrument-product-analytics/references/astro.md +29 -34
- package/dist/global-skills/instrument-product-analytics/references/configuration.md +27 -42
- package/dist/global-skills/instrument-product-analytics/references/django.md +120 -72
- package/dist/global-skills/instrument-product-analytics/references/dotnet.md +48 -102
- package/dist/global-skills/instrument-product-analytics/references/elixir.md +25 -50
- package/dist/global-skills/instrument-product-analytics/references/flask.md +55 -39
- package/dist/global-skills/instrument-product-analytics/references/flutter.md +94 -96
- package/dist/global-skills/instrument-product-analytics/references/go.md +39 -77
- package/dist/global-skills/instrument-product-analytics/references/identify-users.md +24 -26
- package/dist/global-skills/instrument-product-analytics/references/ios.md +22 -22
- package/dist/global-skills/instrument-product-analytics/references/laravel.md +18 -16
- package/dist/global-skills/instrument-product-analytics/references/next-js.md +44 -54
- package/dist/global-skills/instrument-product-analytics/references/nuxt-js-3-6.md +32 -34
- package/dist/global-skills/instrument-product-analytics/references/nuxt-js.md +36 -36
- package/dist/global-skills/instrument-product-analytics/references/php.md +42 -87
- package/dist/global-skills/instrument-product-analytics/references/posthog-python.md +15 -12
- package/dist/global-skills/instrument-product-analytics/references/python.md +106 -154
- package/dist/global-skills/instrument-product-analytics/references/react-native.md +97 -176
- package/dist/global-skills/instrument-product-analytics/references/react-router-v6.md +29 -40
- package/dist/global-skills/instrument-product-analytics/references/react-router-v7-data-mode.md +29 -38
- package/dist/global-skills/instrument-product-analytics/references/react-router-v7-declarative-mode.md +29 -40
- package/dist/global-skills/instrument-product-analytics/references/react-router-v7-framework-mode.md +32 -37
- package/dist/global-skills/instrument-product-analytics/references/ruby-on-rails.md +31 -68
- package/dist/global-skills/instrument-product-analytics/references/ruby.md +40 -96
- package/dist/global-skills/instrument-product-analytics/references/svelte.md +34 -34
- package/dist/global-skills/instrument-product-analytics/references/tanstack-start.md +19 -19
- package/dist/global-skills/instrument-product-analytics/references/usage.md +94 -114
- package/dist/global-skills/instrument-product-analytics/references/vue-js.md +33 -45
- package/dist/global-skills/mongodb-search-and-ai/SKILL.md +40 -22
- package/dist/global-skills/mongodb-search-and-ai/references/automated-embedding.md +8 -2
- package/dist/global-skills/mongodb-search-and-ai/references/quick-start.md +725 -0
- package/dist/global-skills/mongodb-search-and-ai/scripts/quickstart_complete.py +386 -0
- package/dist/global-skills/neon/references/claimable-neon.md +2 -0
- package/dist/global-skills/neon-realtime/references/queries.md +2 -2
- package/dist/global-skills/resend/SKILL.md +1 -1
- package/dist/global-skills/resend/references/inboxes.md +49 -21
- package/dist/global-skills/resend/references/webhooks.md +1 -1
- package/dist/global-skills/stripe-best-practices/SKILL.md +1 -1
- package/dist/global-skills/stripe-best-practices/references/connect.md +1 -1
- package/dist/global-skills/stripe-best-practices/references/security.md +9 -9
- package/dist/global-skills/vybekiitReferences/backend/AGENTS.md +1 -1
- package/dist/global-skills/vybekiitReferences/backend/agent/goal-routes.json +303 -18
- package/dist/global-skills/vybekiitReferences/extension/AGENTS.md +1 -1
- package/dist/global-skills/vybekiitReferences/extension/agent/goal-routes.json +352 -18
- package/dist/global-skills/vybekiitReferences/mobile/AGENTS.md +1 -1
- package/dist/global-skills/vybekiitReferences/mobile/agent/goal-routes.json +413 -22
- package/dist/global-skills/vybekiitReferences/spa/AGENTS.md +1 -1
- package/dist/global-skills/vybekiitReferences/spa/agent/goal-routes.json +391 -21
- package/dist/global-skills/vybekiitReferences/web/AGENTS.md +14 -2
- package/dist/global-skills/vybekiitReferences/web/agent/goal-routes.json +490 -32
- package/package.json +8 -8
|
@@ -2,31 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
# Next.js
|
|
4
4
|
|
|
5
|
+
Canonical URL: https://posthog.com/docs/libraries/next-js
|
|
6
|
+
|
|
7
|
+
> **Cloud region:** This page uses US Cloud hosts. For an EU Cloud project, use `https://eu.i.posthog.com` instead of `https://us.i.posthog.com` (ingestion host), and use `https://eu.posthog.com` instead of `https://app.posthog.com` (app host for links).
|
|
8
|
+
|
|
9
|
+
## On this page
|
|
10
|
+
|
|
11
|
+
- [Prerequisites](#prerequisites)
|
|
12
|
+
- [Beta: integration via LLM](#beta-integration-via-llm)
|
|
13
|
+
- [Client-side setup](#client-side-setup)
|
|
14
|
+
- [Integration](#integration)
|
|
15
|
+
- [Identifying users](#identifying-users)
|
|
16
|
+
- [Accessing PostHog](#accessing-posthog)
|
|
17
|
+
- [Server-side analytics](#server-side-analytics)
|
|
18
|
+
- [Configuring a reverse proxy to PostHog](#configuring-a-reverse-proxy-to-posthog)
|
|
19
|
+
- [Further reading](#further-reading)
|
|
20
|
+
|
|
5
21
|
PostHog makes it easy to get data about traffic and usage of your [Next.js](https://nextjs.org/) app. Integrating PostHog into your site enables analytics about user behavior, custom events capture, session recordings, feature flags, and more.
|
|
6
22
|
|
|
7
|
-
This guide walks you through integrating PostHog into your Next.js app using the [React](/docs/libraries/react.md) and the [Node.js](/docs/libraries/node.md) SDKs.
|
|
23
|
+
This guide walks you through integrating PostHog into your Next.js app using the [React](https://posthog.com/docs/libraries/react.md) and the [Node.js](https://posthog.com/docs/libraries/node.md) SDKs.
|
|
8
24
|
|
|
9
25
|
> You can see a working example of this integration in our [Next.js demo app](https://github.com/PostHog/posthog-js/tree/main/playground/nextjs).
|
|
10
26
|
|
|
11
27
|
Next.js has both client and server-side rendering, as well as pages and app routers. We'll cover all of these options in this guide.
|
|
12
28
|
|
|
13
|
-
> **Try `@posthog/next` (pre-release):** A simplified Next.js integration with synchronized client/server identity, server-side flag bootstrapping, and a built-in API proxy. [Read the setup guide →](/docs/libraries/next-js/posthog-next.md)
|
|
29
|
+
> **Try `@posthog/next` (pre-release):** A simplified Next.js integration with synchronized client/server identity, server-side flag bootstrapping, and a built-in API proxy. [Read the setup guide →](https://posthog.com/docs/libraries/next-js/posthog-next.md)
|
|
14
30
|
|
|
15
31
|
## Prerequisites
|
|
16
32
|
|
|
17
33
|
To follow this guide along, you need:
|
|
18
34
|
|
|
19
|
-
1. A PostHog instance (either [Cloud](https://app.posthog.com/signup) or [self-hosted](/docs/self-host.md))
|
|
35
|
+
1. A PostHog instance (either [Cloud](https://app.posthog.com/signup) or [self-hosted](https://posthog.com/docs/self-host.md))
|
|
20
36
|
2. A Next.js application
|
|
21
37
|
|
|
22
38
|
## Beta: integration via LLM
|
|
23
39
|
|
|
24
|
-
Install PostHog for Next.js in seconds with our wizard by running this prompt with [LLM coding agents](/blog/envoy-wizard-llm-agent.md) like Cursor and Bolt, or by running it in your terminal.
|
|
40
|
+
Install PostHog for Next.js in seconds with our wizard by running this prompt with [LLM coding agents](https://posthog.com/blog/envoy-wizard-llm-agent.md) like Cursor and Bolt, or by running it in your terminal.
|
|
25
41
|
|
|
26
42
|
`npx @posthog/wizard`
|
|
27
43
|
|
|
28
|
-
[Learn more](/wizard.md)
|
|
29
|
-
|
|
30
44
|
Or, to integrate manually, continue with the rest of this guide.
|
|
31
45
|
|
|
32
46
|
## Client-side setup
|
|
@@ -65,7 +79,7 @@ bun add posthog-js
|
|
|
65
79
|
> worker-src 'self' blob: data:;
|
|
66
80
|
> ```
|
|
67
81
|
>
|
|
68
|
-
> `script-src` covers the snippet and the lazy-loaded bundles, `connect-src` covers event ingestion and feature flags, and `worker-src` covers session replay. The [toolbar needs a few more](/docs/advanced/content-security-policy.md), or use a [reverse proxy](/docs/advanced/proxy.md) so everything is first-party. Failing to do so causes silent failures where `capture` and `identify` calls never send, so the integration looks complete while zero events arrive. Remember `connect-src` falls back to `default-src`, so `default-src 'self'` blocks event delivery even when the script itself is bundled.
|
|
82
|
+
> `script-src` covers the snippet and the lazy-loaded bundles, `connect-src` covers event ingestion and feature flags, and `worker-src` covers session replay. The [toolbar needs a few more](https://posthog.com/docs/advanced/content-security-policy.md), or use a [reverse proxy](https://posthog.com/docs/advanced/proxy.md) so everything is first-party. Failing to do so causes silent failures where `capture` and `identify` calls never send, so the integration looks complete while zero events arrive. Remember `connect-src` falls back to `default-src`, so `default-src 'self'` blocks event delivery even when the script itself is bundled.
|
|
69
83
|
|
|
70
84
|
Add your environment variables to your `.env.local` file and to your hosting provider (e.g. Vercel, Netlify, AWS). You can find your project token in your [project settings](https://app.posthog.com/project/settings).
|
|
71
85
|
|
|
@@ -104,7 +118,7 @@ posthog.init(process.env.NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN!, {
|
|
|
104
118
|
});
|
|
105
119
|
```
|
|
106
120
|
|
|
107
|
-
Bootstrapping with
|
|
121
|
+
**Bootstrapping with instrumentation-client**
|
|
108
122
|
|
|
109
123
|
When using `instrumentation-client`, the values you pass to `posthog.init` remain fixed for the entire session. This means bootstrapping only works if you evaluate flags **before your app renders** (for example, on the server).
|
|
110
124
|
|
|
@@ -115,17 +129,17 @@ If you need flag values after the app has rendered, you’ll want to:
|
|
|
115
129
|
|
|
116
130
|
Both approaches avoid flicker and give you the same outcome as bootstrapping, as long as you use the same `distinct_id` across client and server.
|
|
117
131
|
|
|
118
|
-
See the [bootstrapping guide](/docs/feature-flags/bootstrapping.md) for more information.
|
|
132
|
+
See the [bootstrapping guide](https://posthog.com/docs/feature-flags/bootstrapping.md) for more information.
|
|
119
133
|
|
|
120
134
|
## Identifying users
|
|
121
135
|
|
|
122
|
-
> **Identifying users is required.** Call `posthog.identify('your-user-id')` after login to link events to a known user. This is what connects frontend event captures, [session replays](/docs/session-replay.md), [LLM traces](/docs/ai-engineering.md), and [error tracking](/docs/error-tracking.md) to the same person — and lets backend events link back too.
|
|
136
|
+
> **Identifying users is required.** Call `posthog.identify('your-user-id')` after login to link events to a known user. This is what connects frontend event captures, [session replays](https://posthog.com/docs/session-replay.md), [LLM traces](https://posthog.com/docs/ai-engineering.md), and [error tracking](https://posthog.com/docs/error-tracking.md) to the same person — and lets backend events link back too.
|
|
123
137
|
>
|
|
124
138
|
> Use a stable ID from your auth system when possible, not an email or display name. Send those as person properties instead. If your app has no other stable key, email works as a fallback if they are unique. Never a shared literal like `"anonymous"` or `"user"`, which pools many people onto one person and corrupts their data. When no ID is available at all, skip the identify and retain the anonymous distinct ID that's automatically assigned.
|
|
125
139
|
>
|
|
126
140
|
> Call `posthog.reset()` on logout, so the next person to use the browser doesn't inherit the last one's identity.
|
|
127
141
|
>
|
|
128
|
-
> See our guide on [identifying users](/docs/getting-started/identify-users.md) for how to set this up.
|
|
142
|
+
> See our guide on [identifying users](https://posthog.com/docs/getting-started/identify-users.md) for how to set this up.
|
|
129
143
|
|
|
130
144
|
### Linking client and server events
|
|
131
145
|
|
|
@@ -133,8 +147,6 @@ Next.js apps usually capture on both sides. To keep them on the same person, use
|
|
|
133
147
|
|
|
134
148
|
If your app calls your own backend, `tracing_headers` adds `X-POSTHOG-DISTINCT-ID` and `X-POSTHOG-SESSION-ID` to matching `fetch` and `XMLHttpRequest` requests. This lets server-side SDKs link backend events, errors, and LLM traces back to frontend sessions and replays. Use hostnames only, without protocols or paths.
|
|
135
149
|
|
|
136
|
-
JavaScript
|
|
137
|
-
|
|
138
150
|
```javascript
|
|
139
151
|
posthog.init('<ph_project_token>', {
|
|
140
152
|
api_host: 'https://us.i.posthog.com',
|
|
@@ -147,23 +159,23 @@ This works in local development too, but match on the hostname alone: use `'loca
|
|
|
147
159
|
|
|
148
160
|
Tracing headers help you attribute events across front and backend consistently. When this isn't available, use your server-side stable IDs to deduce the matching `distinctId`, and pass it in when capturing the event.
|
|
149
161
|
|
|
150
|
-
Set up a reverse proxy (recommended)
|
|
162
|
+
**Set up a reverse proxy (recommended)**
|
|
151
163
|
|
|
152
|
-
We recommend [setting up a reverse proxy](/docs/advanced/proxy.md), so that events are less likely to be intercepted by tracking blockers.
|
|
164
|
+
We recommend [setting up a reverse proxy](https://posthog.com/docs/advanced/proxy.md), so that events are less likely to be intercepted by tracking blockers.
|
|
153
165
|
|
|
154
|
-
We have our [own managed reverse proxy service](/docs/advanced/proxy/managed-reverse-proxy.md), which is free for all PostHog Cloud users, routes through our infrastructure, and makes setting up your proxy easy.
|
|
166
|
+
We have our [own managed reverse proxy service](https://posthog.com/docs/advanced/proxy/managed-reverse-proxy.md), which is free for all PostHog Cloud users, routes through our infrastructure, and makes setting up your proxy easy.
|
|
155
167
|
|
|
156
|
-
If you don't want to use our managed service then there are several other options for creating a reverse proxy, including using [Cloudflare](/docs/advanced/proxy/cloudflare.md), [AWS Cloudfront](/docs/advanced/proxy/cloudfront.md), and [Vercel](/docs/advanced/proxy/vercel.md).
|
|
168
|
+
If you don't want to use our managed service then there are several other options for creating a reverse proxy, including using [Cloudflare](https://posthog.com/docs/advanced/proxy/cloudflare.md), [AWS Cloudfront](https://posthog.com/docs/advanced/proxy/cloudfront.md), and [Vercel](https://posthog.com/docs/advanced/proxy/vercel.md).
|
|
157
169
|
|
|
158
|
-
Grouping products in one project (recommended)
|
|
170
|
+
**Grouping products in one project (recommended)**
|
|
159
171
|
|
|
160
|
-
If you have multiple customer-facing products (e.g. a marketing website + mobile app + web app), it's best to install PostHog on them all and [group them in one project](/docs/settings/projects.md).
|
|
172
|
+
If you have multiple customer-facing products (e.g. a marketing website + mobile app + web app), it's best to install PostHog on them all and [group them in one project](https://posthog.com/docs/settings/projects.md).
|
|
161
173
|
|
|
162
174
|
This makes it possible to track users across their entire journey (e.g. from visiting your marketing website to signing up for your product), or how they use your product across multiple platforms.
|
|
163
175
|
|
|
164
|
-
Add IPs to Firewall/WAF allowlists (recommended)
|
|
176
|
+
**Add IPs to Firewall/WAF allowlists (recommended)**
|
|
165
177
|
|
|
166
|
-
For certain features like [heatmaps](/docs/toolbar/heatmaps.md), your Web Application Firewall (WAF) may be blocking PostHog's requests to your site. Add these IP addresses to your WAF allowlist or rules to let PostHog access your site.
|
|
178
|
+
For certain features like [heatmaps](https://posthog.com/docs/toolbar/heatmaps.md), your Web Application Firewall (WAF) may be blocking PostHog's requests to your site. Add these IP addresses to your WAF allowlist or rules to let PostHog access your site.
|
|
167
179
|
|
|
168
180
|
**EU**: `3.75.65.221`, `18.197.246.42`, `3.120.223.253`
|
|
169
181
|
|
|
@@ -173,14 +185,12 @@ These are public, stable IPs used by PostHog services.
|
|
|
173
185
|
|
|
174
186
|
PostHog captures heatmap screenshots using [Browserless](https://www.browserless.io), which has its own IP addresses. Browserless [publishes the current list here](https://docs.browserless.io/baas/troubleshooting/whitelisting-ips).
|
|
175
187
|
|
|
176
|
-
An allowlist does not help when your app has a private address. For apps on an internal network, see [internal and intranet applications](/docs/session-replay/troubleshooting.md#internal-and-intranet-applications).
|
|
188
|
+
An allowlist does not help when your app has a private address. For apps on an internal network, see [internal and intranet applications](https://posthog.com/docs/session-replay/troubleshooting.md#internal-and-intranet-applications).
|
|
177
189
|
|
|
178
190
|
## Accessing PostHog
|
|
179
191
|
|
|
180
192
|
Once initialized in `instrumentation-client.js|ts`, import `posthog` from `posthog-js` anywhere and call the methods you need on the `posthog` object.
|
|
181
193
|
|
|
182
|
-
JavaScript
|
|
183
|
-
|
|
184
194
|
```javascript
|
|
185
195
|
"use client";
|
|
186
196
|
import posthog from "posthog-js";
|
|
@@ -196,9 +206,7 @@ export default function Home() {
|
|
|
196
206
|
|
|
197
207
|
### Using React hooks
|
|
198
208
|
|
|
199
|
-
The [React feature flag hooks](/docs/libraries/react.md#feature-flags) work automatically when PostHog is initialized via `instrumentation-client.ts`. The hooks use the initialized posthog-js singleton:
|
|
200
|
-
|
|
201
|
-
JavaScript
|
|
209
|
+
The [React feature flag hooks](https://posthog.com/docs/libraries/react.md#feature-flags) work automatically when PostHog is initialized via `instrumentation-client.ts`. The hooks use the initialized posthog-js singleton:
|
|
202
210
|
|
|
203
211
|
```javascript
|
|
204
212
|
"use client";
|
|
@@ -213,16 +221,16 @@ export default function FeatureComponent() {
|
|
|
213
221
|
|
|
214
222
|
### Usage
|
|
215
223
|
|
|
216
|
-
See the [React SDK docs](/docs/libraries/react.md) for examples of how to use:
|
|
224
|
+
See the [React SDK docs](https://posthog.com/docs/libraries/react.md) for examples of how to use:
|
|
217
225
|
|
|
218
|
-
- [`posthog-js` functions like custom event capture, user identification, and more.](/docs/libraries/react.md#using-posthog-js-functions)
|
|
219
|
-
- [Feature flags including variants and payloads.](/docs/libraries/react.md#feature-flags)
|
|
226
|
+
- [`posthog-js` functions like custom event capture, user identification, and more.](https://posthog.com/docs/libraries/react.md#using-posthog-js-functions)
|
|
227
|
+
- [Feature flags including variants and payloads.](https://posthog.com/docs/libraries/react.md#feature-flags)
|
|
220
228
|
|
|
221
|
-
You can also read [the full `posthog-js` documentation](/docs/libraries/js/usage.md) for all the usable functions.
|
|
229
|
+
You can also read [the full `posthog-js` documentation](https://posthog.com/docs/libraries/js/usage.md) for all the usable functions.
|
|
222
230
|
|
|
223
231
|
## Server-side analytics
|
|
224
232
|
|
|
225
|
-
Next.js enables you to both server-side render pages and add server-side functionality. To integrate PostHog into your Next.js app on the server-side, you can use the [Node SDK](/docs/libraries/node.md).
|
|
233
|
+
Next.js enables you to both server-side render pages and add server-side functionality. To integrate PostHog into your Next.js app on the server-side, you can use the [Node SDK](https://posthog.com/docs/libraries/node.md).
|
|
226
234
|
|
|
227
235
|
First, install the `posthog-node` library:
|
|
228
236
|
|
|
@@ -258,8 +266,6 @@ For the app router, we can initialize the `posthog-node` SDK once with a `PostHo
|
|
|
258
266
|
|
|
259
267
|
This enables us to send events and fetch data from PostHog on the server – without making client-side requests.
|
|
260
268
|
|
|
261
|
-
JavaScript
|
|
262
|
-
|
|
263
269
|
```javascript
|
|
264
270
|
// app/posthog.js
|
|
265
271
|
import { PostHog } from 'posthog-node'
|
|
@@ -281,8 +287,6 @@ export default function PostHogClient() {
|
|
|
281
287
|
|
|
282
288
|
To use this client, we import it into our pages and call it with the `PostHogClient` function:
|
|
283
289
|
|
|
284
|
-
JavaScript
|
|
285
|
-
|
|
286
290
|
```javascript
|
|
287
291
|
import Link from 'next/link'
|
|
288
292
|
import PostHogClient from '../posthog'
|
|
@@ -313,8 +317,6 @@ For the pages router, we can use the `getServerSideProps` function to access Pos
|
|
|
313
317
|
|
|
314
318
|
This looks like this:
|
|
315
319
|
|
|
316
|
-
JavaScript
|
|
317
|
-
|
|
318
320
|
```javascript
|
|
319
321
|
// pages/posts/[id].js
|
|
320
322
|
import { useContext, useEffect, useState } from 'react'
|
|
@@ -386,8 +388,6 @@ export async function getServerSideProps(ctx) {
|
|
|
386
388
|
|
|
387
389
|
> **Note**: next-auth doesn't put a user ID on the session by default. Its session is `{ name, email, image }`, so `session.user.id` is `undefined` until you add it yourself with a session callback in your `authOptions`:
|
|
388
390
|
>
|
|
389
|
-
> JavaScript
|
|
390
|
-
>
|
|
391
391
|
> ```javascript
|
|
392
392
|
> // lib/auth.js
|
|
393
393
|
> export const authOptions = {
|
|
@@ -412,8 +412,6 @@ Next.js overrides the default `fetch` behavior on the server to introduce their
|
|
|
412
412
|
|
|
413
413
|
You can override that configuration when initializing PostHog, but make sure you understand the pros/cons of using Next.js's cache and that you might get cached results rather than the actual result our server would return. This is important for feature flags, for example.
|
|
414
414
|
|
|
415
|
-
TSX
|
|
416
|
-
|
|
417
415
|
```jsx
|
|
418
416
|
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN, {
|
|
419
417
|
// ... your configuration
|
|
@@ -429,18 +427,10 @@ posthog.init(process.env.NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN, {
|
|
|
429
427
|
|
|
430
428
|
## Configuring a reverse proxy to PostHog
|
|
431
429
|
|
|
432
|
-
To improve the reliability of client-side tracking and make requests less likely to be intercepted by tracking blockers, you can setup a reverse proxy in Next.js. Read more about deploying a reverse proxy using [Next.js rewrites](/docs/advanced/proxy/nextjs.md), [Next.js middleware](/docs/advanced/proxy/nextjs-middleware.md), and [Vercel rewrites](/docs/advanced/proxy/vercel.md).
|
|
430
|
+
To improve the reliability of client-side tracking and make requests less likely to be intercepted by tracking blockers, you can setup a reverse proxy in Next.js. Read more about deploying a reverse proxy using [Next.js rewrites](https://posthog.com/docs/advanced/proxy/nextjs.md), [Next.js middleware](https://posthog.com/docs/advanced/proxy/nextjs-middleware.md), and [Vercel rewrites](https://posthog.com/docs/advanced/proxy/vercel.md).
|
|
433
431
|
|
|
434
432
|
## Further reading
|
|
435
433
|
|
|
436
|
-
- [How to set up Next.js analytics, feature flags, and more](/tutorials/nextjs-analytics.md)
|
|
437
|
-
- [How to set up Next.js pages router analytics, feature flags, and more](/tutorials/nextjs-pages-analytics.md)
|
|
438
|
-
- [How to set up Next.js A/B tests](/tutorials/nextjs-ab-tests.md)
|
|
439
|
-
|
|
440
|
-
### Still have questions?
|
|
441
|
-
|
|
442
|
-
Ask PostHog AI
|
|
443
|
-
|
|
444
|
-
### Was this page useful?
|
|
445
|
-
|
|
446
|
-
HelpfulCould be better
|
|
434
|
+
- [How to set up Next.js analytics, feature flags, and more](https://posthog.com/tutorials/nextjs-analytics.md)
|
|
435
|
+
- [How to set up Next.js pages router analytics, feature flags, and more](https://posthog.com/tutorials/nextjs-pages-analytics.md)
|
|
436
|
+
- [How to set up Next.js A/B tests](https://posthog.com/tutorials/nextjs-ab-tests.md)
|
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
# Nuxt.js (v3.0 to v3.6)
|
|
4
4
|
|
|
5
|
+
Canonical URL: https://posthog.com/docs/libraries/nuxt-js-3-6
|
|
6
|
+
|
|
7
|
+
> **Cloud region:** This page uses US Cloud hosts. For an EU Cloud project, use `https://eu.i.posthog.com` instead of `https://us.i.posthog.com` (ingestion host), and use `https://eu.posthog.com` instead of `https://us.posthog.com` (app host for links).
|
|
8
|
+
|
|
9
|
+
## On this page
|
|
10
|
+
|
|
11
|
+
- [Setting up PostHog on the client side](#setting-up-posthog-on-the-client-side)
|
|
12
|
+
- [Setting up PostHog on the server side](#setting-up-posthog-on-the-server-side)
|
|
13
|
+
- [Next steps](#next-steps)
|
|
14
|
+
|
|
5
15
|
PostHog makes it easy to get data about usage of your [Nuxt.js](https://nuxt.com/) app. Integrating PostHog into your app enables analytics about user behavior, custom events capture, session replays, feature flags, and more.
|
|
6
16
|
|
|
7
17
|
These docs are for Nuxt v3.0 to v3.6. You can see a working example of the Nuxt v3.0 integration in our [Nuxt.js demo app](https://github.com/PostHog/posthog-js/tree/master/playground/nuxtjs)
|
|
@@ -42,7 +52,7 @@ bun add posthog-js
|
|
|
42
52
|
> worker-src 'self' blob: data:;
|
|
43
53
|
> ```
|
|
44
54
|
>
|
|
45
|
-
> `script-src` covers the snippet and the lazy-loaded bundles, `connect-src` covers event ingestion and feature flags, and `worker-src` covers session replay. The [toolbar needs a few more](/docs/advanced/content-security-policy.md), or use a [reverse proxy](/docs/advanced/proxy.md) so everything is first-party. Failing to do so causes silent failures where `capture` and `identify` calls never send, so the integration looks complete while zero events arrive. Remember `connect-src` falls back to `default-src`, so `default-src 'self'` blocks event delivery even when the script itself is bundled.
|
|
55
|
+
> `script-src` covers the snippet and the lazy-loaded bundles, `connect-src` covers event ingestion and feature flags, and `worker-src` covers session replay. The [toolbar needs a few more](https://posthog.com/docs/advanced/content-security-policy.md), or use a [reverse proxy](https://posthog.com/docs/advanced/proxy.md) so everything is first-party. Failing to do so causes silent failures where `capture` and `identify` calls never send, so the integration looks complete while zero events arrive. Remember `connect-src` falls back to `default-src`, so `default-src 'self'` blocks event delivery even when the script itself is bundled.
|
|
46
56
|
|
|
47
57
|
2. Store your PostHog key and host in environment variables rather than hard-coding them. Add them to a `.env` file (and to your hosting provider). You can find these in [your project settings](https://us.posthog.com/settings/project).
|
|
48
58
|
|
|
@@ -73,7 +83,7 @@ export default defineNuxtConfig({
|
|
|
73
83
|
|
|
74
84
|
Anything shipped to the browser – the token you pass to `posthog.init()`, anything under Nuxt's `runtimeConfig.public`, or the `@posthog/nuxt` module's `posthogConfig` – ends up in your client-side JavaScript and is visible to anyone who visits your site. This is fine for your **project token** (`<ph_project_token>`), which is designed to be public.
|
|
75
85
|
|
|
76
|
-
Your **[personal API key](/docs/api.md#authentication)** is different. It can grant full access to your PostHog account, so it must never reach the browser. If you need it – for example, for [source map uploads](/docs/error-tracking/upload-source-maps/nuxt.md) or [server-side local evaluation](/docs/feature-flags/local-evaluation.md) – read it from a server-only environment variable (or top-level `runtimeConfig`, never `runtimeConfig.public`) and only use it in server code.
|
|
86
|
+
Your **[personal API key](https://posthog.com/docs/api.md#authentication)** is different. It can grant full access to your PostHog account, so it must never reach the browser. If you need it – for example, for [source map uploads](https://posthog.com/docs/error-tracking/upload-source-maps/nuxt.md) or [server-side local evaluation](https://posthog.com/docs/feature-flags/local-evaluation.md) – read it from a server-only environment variable (or top-level `runtimeConfig`, never `runtimeConfig.public`) and only use it in server code.
|
|
77
87
|
|
|
78
88
|
Either way, prefer reading keys from environment variables rather than hard-coding them in `nuxt.config`, so you can keep them out of source control and use different values per environment.
|
|
79
89
|
|
|
@@ -106,8 +116,6 @@ export default defineNuxtPlugin(() => {
|
|
|
106
116
|
|
|
107
117
|
PostHog can then be accessed throughout your Nuxt.js using the provider accessor, for example:
|
|
108
118
|
|
|
109
|
-
Vue
|
|
110
|
-
|
|
111
119
|
```html
|
|
112
120
|
<script setup>
|
|
113
121
|
const { $posthog } = useNuxtApp()
|
|
@@ -118,15 +126,13 @@ Vue
|
|
|
118
126
|
</script>
|
|
119
127
|
```
|
|
120
128
|
|
|
121
|
-
See the [JavaScript SDK docs](/docs/libraries/js/usage.md) for all usable functions, such as:
|
|
129
|
+
See the [JavaScript SDK docs](https://posthog.com/docs/libraries/js/usage.md) for all usable functions, such as:
|
|
122
130
|
|
|
123
|
-
- [Capture custom event capture, identify users, and more.](/docs/libraries/js/usage.md#capturing-events)
|
|
124
|
-
- [Feature flags including variants and payloads.](/docs/libraries/js/usage.md#feature-flags)
|
|
131
|
+
- [Capture custom event capture, identify users, and more.](https://posthog.com/docs/libraries/js/usage.md#capturing-events)
|
|
132
|
+
- [Feature flags including variants and payloads.](https://posthog.com/docs/libraries/js/usage.md#feature-flags)
|
|
125
133
|
|
|
126
134
|
If your app calls your own backend, `tracing_headers` adds `X-POSTHOG-DISTINCT-ID` and `X-POSTHOG-SESSION-ID` to matching `fetch` and `XMLHttpRequest` requests. This lets server-side SDKs link backend events, errors, and LLM traces back to frontend sessions and replays. Use hostnames only, without protocols or paths.
|
|
127
135
|
|
|
128
|
-
JavaScript
|
|
129
|
-
|
|
130
136
|
```javascript
|
|
131
137
|
posthog.init('<ph_project_token>', {
|
|
132
138
|
api_host: 'https://us.i.posthog.com',
|
|
@@ -139,23 +145,23 @@ This works in local development too, but match on the hostname alone: use `'loca
|
|
|
139
145
|
|
|
140
146
|
Tracing headers help you attribute events across front and backend consistently. When this isn't available, use your server-side stable IDs to deduce the matching `distinctId`, and pass it in when capturing the event.
|
|
141
147
|
|
|
142
|
-
Set up a reverse proxy (recommended)
|
|
148
|
+
**Set up a reverse proxy (recommended)**
|
|
143
149
|
|
|
144
|
-
We recommend [setting up a reverse proxy](/docs/advanced/proxy.md), so that events are less likely to be intercepted by tracking blockers.
|
|
150
|
+
We recommend [setting up a reverse proxy](https://posthog.com/docs/advanced/proxy.md), so that events are less likely to be intercepted by tracking blockers.
|
|
145
151
|
|
|
146
|
-
We have our [own managed reverse proxy service](/docs/advanced/proxy/managed-reverse-proxy.md), which is free for all PostHog Cloud users, routes through our infrastructure, and makes setting up your proxy easy.
|
|
152
|
+
We have our [own managed reverse proxy service](https://posthog.com/docs/advanced/proxy/managed-reverse-proxy.md), which is free for all PostHog Cloud users, routes through our infrastructure, and makes setting up your proxy easy.
|
|
147
153
|
|
|
148
|
-
If you don't want to use our managed service then there are several other options for creating a reverse proxy, including using [Cloudflare](/docs/advanced/proxy/cloudflare.md), [AWS Cloudfront](/docs/advanced/proxy/cloudfront.md), and [Vercel](/docs/advanced/proxy/vercel.md).
|
|
154
|
+
If you don't want to use our managed service then there are several other options for creating a reverse proxy, including using [Cloudflare](https://posthog.com/docs/advanced/proxy/cloudflare.md), [AWS Cloudfront](https://posthog.com/docs/advanced/proxy/cloudfront.md), and [Vercel](https://posthog.com/docs/advanced/proxy/vercel.md).
|
|
149
155
|
|
|
150
|
-
Grouping products in one project (recommended)
|
|
156
|
+
**Grouping products in one project (recommended)**
|
|
151
157
|
|
|
152
|
-
If you have multiple customer-facing products (e.g. a marketing website + mobile app + web app), it's best to install PostHog on them all and [group them in one project](/docs/settings/projects.md).
|
|
158
|
+
If you have multiple customer-facing products (e.g. a marketing website + mobile app + web app), it's best to install PostHog on them all and [group them in one project](https://posthog.com/docs/settings/projects.md).
|
|
153
159
|
|
|
154
160
|
This makes it possible to track users across their entire journey (e.g. from visiting your marketing website to signing up for your product), or how they use your product across multiple platforms.
|
|
155
161
|
|
|
156
|
-
Add IPs to Firewall/WAF allowlists (recommended)
|
|
162
|
+
**Add IPs to Firewall/WAF allowlists (recommended)**
|
|
157
163
|
|
|
158
|
-
For certain features like [heatmaps](/docs/toolbar/heatmaps.md), your Web Application Firewall (WAF) may be blocking PostHog's requests to your site. Add these IP addresses to your WAF allowlist or rules to let PostHog access your site.
|
|
164
|
+
For certain features like [heatmaps](https://posthog.com/docs/toolbar/heatmaps.md), your Web Application Firewall (WAF) may be blocking PostHog's requests to your site. Add these IP addresses to your WAF allowlist or rules to let PostHog access your site.
|
|
159
165
|
|
|
160
166
|
**EU**: `3.75.65.221`, `18.197.246.42`, `3.120.223.253`
|
|
161
167
|
|
|
@@ -165,7 +171,7 @@ These are public, stable IPs used by PostHog services.
|
|
|
165
171
|
|
|
166
172
|
PostHog captures heatmap screenshots using [Browserless](https://www.browserless.io), which has its own IP addresses. Browserless [publishes the current list here](https://docs.browserless.io/baas/troubleshooting/whitelisting-ips).
|
|
167
173
|
|
|
168
|
-
An allowlist does not help when your app has a private address. For apps on an internal network, see [internal and intranet applications](/docs/session-replay/troubleshooting.md#internal-and-intranet-applications).
|
|
174
|
+
An allowlist does not help when your app has a private address. For apps on an internal network, see [internal and intranet applications](https://posthog.com/docs/session-replay/troubleshooting.md#internal-and-intranet-applications).
|
|
169
175
|
|
|
170
176
|
## Setting up PostHog on the server side
|
|
171
177
|
|
|
@@ -241,26 +247,18 @@ server/api/example.js
|
|
|
241
247
|
|
|
242
248
|
> **Note**: Make sure to *always* call `posthog.shutdown()` after capturing events from the server-side. PostHog queues events into larger batches, and this call forces all batched events to be flushed immediately.
|
|
243
249
|
|
|
244
|
-
See the [Node SDK docs](/docs/libraries/node.md) for all usable functions, such as:
|
|
250
|
+
See the [Node SDK docs](https://posthog.com/docs/libraries/node.md) for all usable functions, such as:
|
|
245
251
|
|
|
246
|
-
- [Capture custom event capture, identify users, and more.](/docs/libraries/node.md#capturing-events)
|
|
247
|
-
- [Feature flags including variants and payloads.](/docs/libraries/node.md#feature-flags)
|
|
252
|
+
- [Capture custom event capture, identify users, and more.](https://posthog.com/docs/libraries/node.md#capturing-events)
|
|
253
|
+
- [Feature flags including variants and payloads.](https://posthog.com/docs/libraries/node.md#feature-flags)
|
|
248
254
|
|
|
249
255
|
## Next steps
|
|
250
256
|
|
|
251
|
-
For any technical questions for how to integrate specific PostHog features into Nuxt (such as analytics, feature flags, A/B testing, surveys, etc.), have a look at our [JavaScript Web](/docs/libraries/js.md) and [Node](/docs/libraries/node.md) SDK docs.
|
|
257
|
+
For any technical questions for how to integrate specific PostHog features into Nuxt (such as analytics, feature flags, A/B testing, surveys, etc.), have a look at our [JavaScript Web](https://posthog.com/docs/libraries/js.md) and [Node](https://posthog.com/docs/libraries/node.md) SDK docs.
|
|
252
258
|
|
|
253
259
|
Alternatively, the following tutorials can help you get started:
|
|
254
260
|
|
|
255
|
-
- [How to set up analytics in Nuxt](/tutorials/nuxt-analytics.md)
|
|
256
|
-
- [How to set up feature flags in Nuxt](/tutorials/nuxt-feature-flags.md)
|
|
257
|
-
- [How to set up A/B tests in Nuxt](/tutorials/nuxtjs-ab-tests.md)
|
|
258
|
-
- [How to set up surveys in Nuxt](/tutorials/nuxt-surveys.md)
|
|
259
|
-
|
|
260
|
-
### Still have questions?
|
|
261
|
-
|
|
262
|
-
Ask PostHog AI
|
|
263
|
-
|
|
264
|
-
### Was this page useful?
|
|
265
|
-
|
|
266
|
-
HelpfulCould be better
|
|
261
|
+
- [How to set up analytics in Nuxt](https://posthog.com/tutorials/nuxt-analytics.md)
|
|
262
|
+
- [How to set up feature flags in Nuxt](https://posthog.com/tutorials/nuxt-feature-flags.md)
|
|
263
|
+
- [How to set up A/B tests in Nuxt](https://posthog.com/tutorials/nuxtjs-ab-tests.md)
|
|
264
|
+
- [How to set up surveys in Nuxt](https://posthog.com/tutorials/nuxt-surveys.md)
|
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
# Nuxt.js
|
|
4
4
|
|
|
5
|
+
Canonical URL: https://posthog.com/docs/libraries/nuxt-js
|
|
6
|
+
|
|
7
|
+
> **Cloud region:** This page uses US Cloud hosts. For an EU Cloud project, use `https://eu.posthog.com` instead of `https://us.posthog.com` or `https://app.posthog.com` (app host for links).
|
|
8
|
+
|
|
9
|
+
## On this page
|
|
10
|
+
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Identifying users](#identifying-users)
|
|
13
|
+
- [Configuration](#configuration)
|
|
14
|
+
- [Usage on the client side](#usage-on-the-client-side)
|
|
15
|
+
- [Usage on the server side](#usage-on-the-server-side)
|
|
16
|
+
- [Feature flags](#feature-flags)
|
|
17
|
+
- [Error Tracking](#error-tracking)
|
|
18
|
+
- [Troubleshooting](#troubleshooting)
|
|
19
|
+
- [Next steps](#next-steps)
|
|
20
|
+
|
|
5
21
|
PostHog makes it easy to get data about usage of your [Nuxt.js](https://nuxt.com/) app. Integrating PostHog into your app enables analytics about user behavior, custom events capture, session replays, feature flags, and more.
|
|
6
22
|
|
|
7
23
|
This guide covers Nuxt v4.x and v3.7+. For these versions, we recommend using `@posthog/nuxt` module for client-side capture.
|
|
@@ -15,7 +31,7 @@ The `@posthog/nuxt` module provides:
|
|
|
15
31
|
|
|
16
32
|
For server-side event capture beyond error tracking, use the `posthog-node` SDK directly.
|
|
17
33
|
|
|
18
|
-
> **Using an older version?** See our docs for [Nuxt 3.0-3.6](/docs/libraries/nuxt-js-3-6.md) or [Nuxt 2.x](/docs/libraries/nuxt-js-2.md).
|
|
34
|
+
> **Using an older version?** See our docs for [Nuxt 3.0-3.6](https://posthog.com/docs/libraries/nuxt-js-3-6.md) or [Nuxt 2.x](https://posthog.com/docs/libraries/nuxt-js-2.md).
|
|
19
35
|
|
|
20
36
|
## Installation
|
|
21
37
|
|
|
@@ -53,22 +69,20 @@ bun add @posthog/nuxt
|
|
|
53
69
|
> worker-src 'self' blob: data:;
|
|
54
70
|
> ```
|
|
55
71
|
>
|
|
56
|
-
> `script-src` covers the snippet and the lazy-loaded bundles, `connect-src` covers event ingestion and feature flags, and `worker-src` covers session replay. The [toolbar needs a few more](/docs/advanced/content-security-policy.md), or use a [reverse proxy](/docs/advanced/proxy.md) so everything is first-party. Failing to do so causes silent failures where `capture` and `identify` calls never send, so the integration looks complete while zero events arrive. Remember `connect-src` falls back to `default-src`, so `default-src 'self'` blocks event delivery even when the script itself is bundled.
|
|
72
|
+
> `script-src` covers the snippet and the lazy-loaded bundles, `connect-src` covers event ingestion and feature flags, and `worker-src` covers session replay. The [toolbar needs a few more](https://posthog.com/docs/advanced/content-security-policy.md), or use a [reverse proxy](https://posthog.com/docs/advanced/proxy.md) so everything is first-party. Failing to do so causes silent failures where `capture` and `identify` calls never send, so the integration looks complete while zero events arrive. Remember `connect-src` falls back to `default-src`, so `default-src 'self'` blocks event delivery even when the script itself is bundled.
|
|
57
73
|
|
|
58
74
|
## Identifying users
|
|
59
75
|
|
|
60
|
-
> **Identifying users is required.** Call `posthog.identify('your-user-id')` after login to link events to a known user. This is what connects frontend event captures, [session replays](/docs/session-replay.md), [LLM traces](/docs/ai-engineering.md), and [error tracking](/docs/error-tracking.md) to the same person — and lets backend events link back too.
|
|
76
|
+
> **Identifying users is required.** Call `posthog.identify('your-user-id')` after login to link events to a known user. This is what connects frontend event captures, [session replays](https://posthog.com/docs/session-replay.md), [LLM traces](https://posthog.com/docs/ai-engineering.md), and [error tracking](https://posthog.com/docs/error-tracking.md) to the same person — and lets backend events link back too.
|
|
61
77
|
>
|
|
62
78
|
> Use a stable ID from your auth system when possible, not an email or display name. Send those as person properties instead. If your app has no other stable key, email works as a fallback if they are unique. Never a shared literal like `"anonymous"` or `"user"`, which pools many people onto one person and corrupts their data. When no ID is available at all, skip the identify and retain the anonymous distinct ID that's automatically assigned.
|
|
63
79
|
>
|
|
64
80
|
> Call `posthog.reset()` on logout, so the next person to use the browser doesn't inherit the last one's identity.
|
|
65
81
|
>
|
|
66
|
-
> See our guide on [identifying users](/docs/getting-started/identify-users.md) for how to set this up.
|
|
82
|
+
> See our guide on [identifying users](https://posthog.com/docs/getting-started/identify-users.md) for how to set this up.
|
|
67
83
|
|
|
68
84
|
If your app calls your own backend, `tracing_headers` adds `X-POSTHOG-DISTINCT-ID` and `X-POSTHOG-SESSION-ID` to matching `fetch` and `XMLHttpRequest` requests. This lets server-side SDKs link backend events, errors, and LLM traces back to frontend sessions and replays. Use hostnames only, without protocols or paths.
|
|
69
85
|
|
|
70
|
-
JavaScript
|
|
71
|
-
|
|
72
86
|
```javascript
|
|
73
87
|
posthog.init('<ph_project_token>', {
|
|
74
88
|
api_host: 'https://us.i.posthog.com',
|
|
@@ -113,7 +127,7 @@ export default defineNuxtConfig({
|
|
|
113
127
|
|
|
114
128
|
Anything shipped to the browser – the token you pass to `posthog.init()`, anything under Nuxt's `runtimeConfig.public`, or the `@posthog/nuxt` module's `posthogConfig` – ends up in your client-side JavaScript and is visible to anyone who visits your site. This is fine for your **project token** (`<ph_project_token>`), which is designed to be public.
|
|
115
129
|
|
|
116
|
-
Your **[personal API key](/docs/api.md#authentication)** is different. It can grant full access to your PostHog account, so it must never reach the browser. If you need it – for example, for [source map uploads](/docs/error-tracking/upload-source-maps/nuxt.md) or [server-side local evaluation](/docs/feature-flags/local-evaluation.md) – read it from a server-only environment variable (or top-level `runtimeConfig`, never `runtimeConfig.public`) and only use it in server code.
|
|
130
|
+
Your **[personal API key](https://posthog.com/docs/api.md#authentication)** is different. It can grant full access to your PostHog account, so it must never reach the browser. If you need it – for example, for [source map uploads](https://posthog.com/docs/error-tracking/upload-source-maps/nuxt.md) or [server-side local evaluation](https://posthog.com/docs/feature-flags/local-evaluation.md) – read it from a server-only environment variable (or top-level `runtimeConfig`, never `runtimeConfig.public`) and only use it in server code.
|
|
117
131
|
|
|
118
132
|
Either way, prefer reading keys from environment variables rather than hard-coding them in `nuxt.config`, so you can keep them out of source control and use different values per environment.
|
|
119
133
|
|
|
@@ -177,23 +191,23 @@ export default defineEventHandler((event) => {
|
|
|
177
191
|
})
|
|
178
192
|
```
|
|
179
193
|
|
|
180
|
-
Set up a reverse proxy (recommended)
|
|
194
|
+
**Set up a reverse proxy (recommended)**
|
|
181
195
|
|
|
182
|
-
We recommend [setting up a reverse proxy](/docs/advanced/proxy.md), so that events are less likely to be intercepted by tracking blockers.
|
|
196
|
+
We recommend [setting up a reverse proxy](https://posthog.com/docs/advanced/proxy.md), so that events are less likely to be intercepted by tracking blockers.
|
|
183
197
|
|
|
184
|
-
We have our [own managed reverse proxy service](/docs/advanced/proxy/managed-reverse-proxy.md), which is free for all PostHog Cloud users, routes through our infrastructure, and makes setting up your proxy easy.
|
|
198
|
+
We have our [own managed reverse proxy service](https://posthog.com/docs/advanced/proxy/managed-reverse-proxy.md), which is free for all PostHog Cloud users, routes through our infrastructure, and makes setting up your proxy easy.
|
|
185
199
|
|
|
186
|
-
If you don't want to use our managed service then there are several other options for creating a reverse proxy, including using [Cloudflare](/docs/advanced/proxy/cloudflare.md), [AWS Cloudfront](/docs/advanced/proxy/cloudfront.md), and [Vercel](/docs/advanced/proxy/vercel.md).
|
|
200
|
+
If you don't want to use our managed service then there are several other options for creating a reverse proxy, including using [Cloudflare](https://posthog.com/docs/advanced/proxy/cloudflare.md), [AWS Cloudfront](https://posthog.com/docs/advanced/proxy/cloudfront.md), and [Vercel](https://posthog.com/docs/advanced/proxy/vercel.md).
|
|
187
201
|
|
|
188
|
-
Grouping products in one project (recommended)
|
|
202
|
+
**Grouping products in one project (recommended)**
|
|
189
203
|
|
|
190
|
-
If you have multiple customer-facing products (e.g. a marketing website + mobile app + web app), it's best to install PostHog on them all and [group them in one project](/docs/settings/projects.md).
|
|
204
|
+
If you have multiple customer-facing products (e.g. a marketing website + mobile app + web app), it's best to install PostHog on them all and [group them in one project](https://posthog.com/docs/settings/projects.md).
|
|
191
205
|
|
|
192
206
|
This makes it possible to track users across their entire journey (e.g. from visiting your marketing website to signing up for your product), or how they use your product across multiple platforms.
|
|
193
207
|
|
|
194
|
-
Add IPs to Firewall/WAF allowlists (recommended)
|
|
208
|
+
**Add IPs to Firewall/WAF allowlists (recommended)**
|
|
195
209
|
|
|
196
|
-
For certain features like [heatmaps](/docs/toolbar/heatmaps.md), your Web Application Firewall (WAF) may be blocking PostHog's requests to your site. Add these IP addresses to your WAF allowlist or rules to let PostHog access your site.
|
|
210
|
+
For certain features like [heatmaps](https://posthog.com/docs/toolbar/heatmaps.md), your Web Application Firewall (WAF) may be blocking PostHog's requests to your site. Add these IP addresses to your WAF allowlist or rules to let PostHog access your site.
|
|
197
211
|
|
|
198
212
|
**EU**: `3.75.65.221`, `18.197.246.42`, `3.120.223.253`
|
|
199
213
|
|
|
@@ -203,14 +217,12 @@ These are public, stable IPs used by PostHog services.
|
|
|
203
217
|
|
|
204
218
|
PostHog captures heatmap screenshots using [Browserless](https://www.browserless.io), which has its own IP addresses. Browserless [publishes the current list here](https://docs.browserless.io/baas/troubleshooting/whitelisting-ips).
|
|
205
219
|
|
|
206
|
-
An allowlist does not help when your app has a private address. For apps on an internal network, see [internal and intranet applications](/docs/session-replay/troubleshooting.md#internal-and-intranet-applications).
|
|
220
|
+
An allowlist does not help when your app has a private address. For apps on an internal network, see [internal and intranet applications](https://posthog.com/docs/session-replay/troubleshooting.md#internal-and-intranet-applications).
|
|
207
221
|
|
|
208
222
|
## Feature flags
|
|
209
223
|
|
|
210
224
|
The module provides auto-imported composables for feature flags. All composables return reactive refs that automatically update when flags are loaded or changed.
|
|
211
225
|
|
|
212
|
-
Vue
|
|
213
|
-
|
|
214
226
|
```html
|
|
215
227
|
<script setup>
|
|
216
228
|
const isEnabled = useFeatureFlagEnabled('new-feature')
|
|
@@ -222,8 +234,6 @@ const isEnabled = useFeatureFlagEnabled('new-feature')
|
|
|
222
234
|
</template>
|
|
223
235
|
```
|
|
224
236
|
|
|
225
|
-
Vue
|
|
226
|
-
|
|
227
237
|
```html
|
|
228
238
|
<script setup>
|
|
229
239
|
const variant = useFeatureFlagVariantKey('experiment')
|
|
@@ -236,8 +246,6 @@ const variant = useFeatureFlagVariantKey('experiment')
|
|
|
236
246
|
</template>
|
|
237
247
|
```
|
|
238
248
|
|
|
239
|
-
Vue
|
|
240
|
-
|
|
241
249
|
```html
|
|
242
250
|
<script setup>
|
|
243
251
|
const payload = useFeatureFlagPayload('config-flag')
|
|
@@ -251,7 +259,7 @@ const payload = useFeatureFlagPayload('config-flag')
|
|
|
251
259
|
|
|
252
260
|
## Error Tracking
|
|
253
261
|
|
|
254
|
-
For a detailed error tracking installation guide, including automatic exception capture and source map configuration, see the [Nuxt error tracking installation docs](/docs/error-tracking/installation/nuxt-3-7.md).
|
|
262
|
+
For a detailed error tracking installation guide, including automatic exception capture and source map configuration, see the [Nuxt error tracking installation docs](https://posthog.com/docs/error-tracking/installation/nuxt-3-7.md).
|
|
255
263
|
|
|
256
264
|
## Troubleshooting
|
|
257
265
|
|
|
@@ -261,19 +269,11 @@ For a detailed error tracking installation guide, including automatic exception
|
|
|
261
269
|
|
|
262
270
|
## Next steps
|
|
263
271
|
|
|
264
|
-
For any technical questions for how to integrate specific PostHog features into Nuxt (such as analytics, feature flags, A/B testing, surveys, etc.), have a look at our [JavaScript Web](/docs/libraries/js.md) and [Node](/docs/libraries/node.md) SDK docs.
|
|
272
|
+
For any technical questions for how to integrate specific PostHog features into Nuxt (such as analytics, feature flags, A/B testing, surveys, etc.), have a look at our [JavaScript Web](https://posthog.com/docs/libraries/js.md) and [Node](https://posthog.com/docs/libraries/node.md) SDK docs.
|
|
265
273
|
|
|
266
274
|
Alternatively, the following tutorials can help you get started:
|
|
267
275
|
|
|
268
|
-
- [How to set up analytics in Nuxt](/tutorials/nuxt-analytics.md)
|
|
269
|
-
- [How to set up feature flags in Nuxt](/tutorials/nuxt-feature-flags.md)
|
|
270
|
-
- [How to set up A/B tests in Nuxt](/tutorials/nuxtjs-ab-tests.md)
|
|
271
|
-
- [How to set up surveys in Nuxt](/tutorials/nuxt-surveys.md)
|
|
272
|
-
|
|
273
|
-
### Still have questions?
|
|
274
|
-
|
|
275
|
-
Ask PostHog AI
|
|
276
|
-
|
|
277
|
-
### Was this page useful?
|
|
278
|
-
|
|
279
|
-
HelpfulCould be better
|
|
276
|
+
- [How to set up analytics in Nuxt](https://posthog.com/tutorials/nuxt-analytics.md)
|
|
277
|
+
- [How to set up feature flags in Nuxt](https://posthog.com/tutorials/nuxt-feature-flags.md)
|
|
278
|
+
- [How to set up A/B tests in Nuxt](https://posthog.com/tutorials/nuxtjs-ab-tests.md)
|
|
279
|
+
- [How to set up surveys in Nuxt](https://posthog.com/tutorials/nuxt-surveys.md)
|