vybekiit 0.7.33 → 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 +818 -92
- 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/manifest.json +2 -1
- 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/SKILL.md +15 -10
- package/dist/global-skills/neon/references/claimable-neon.md +2 -0
- package/dist/global-skills/neon-functions/SKILL.md +12 -11
- package/dist/global-skills/neon-functions/references/sse.md +2 -2
- package/dist/global-skills/neon-object-storage/SKILL.md +5 -4
- package/dist/global-skills/neon-postgres/SKILL.md +4 -1
- package/dist/global-skills/neon-realtime/SKILL.md +207 -0
- package/dist/global-skills/neon-realtime/references/mutations.md +743 -0
- package/dist/global-skills/neon-realtime/references/queries.md +509 -0
- package/dist/global-skills/neon-realtime/references/reactivity.md +407 -0
- package/dist/global-skills/neon-realtime/references/ssr.md +695 -0
- package/dist/global-skills/neon-realtime/references/subscribing.md +485 -0
- package/dist/global-skills/resend/SKILL.md +4 -2
- package/dist/global-skills/resend/references/inboxes.md +377 -0
- package/dist/global-skills/resend/references/webhooks.md +9 -0
- 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,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
# React Native
|
|
4
4
|
|
|
5
|
+
Canonical URL: https://posthog.com/docs/libraries/react-native
|
|
6
|
+
|
|
7
|
+
## On this page
|
|
8
|
+
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [Capturing events](#capturing-events)
|
|
11
|
+
- [Autocapture](#autocapture)
|
|
12
|
+
- [Common before_send patterns](#common-before_send-patterns)
|
|
13
|
+
- [Identifying users](#identifying-users)
|
|
14
|
+
- [Get the current user's distinct ID](#get-the-current-users-distinct-id)
|
|
15
|
+
- [Alias](#alias)
|
|
16
|
+
- [Setting person properties](#setting-person-properties)
|
|
17
|
+
- [Super properties](#super-properties)
|
|
18
|
+
- [Opt out of data capture](#opt-out-of-data-capture)
|
|
19
|
+
- [Flush](#flush)
|
|
20
|
+
- [Reset after logout](#reset-after-logout)
|
|
21
|
+
- [Offline behavior](#offline-behavior)
|
|
22
|
+
- [Opt in/out](#opt-inout)
|
|
23
|
+
- [Feature Flags](#feature-flags)
|
|
24
|
+
- [Experiments (A/B tests)](#experiments-ab-tests)
|
|
25
|
+
- [Group analytics](#group-analytics)
|
|
26
|
+
- [Error tracking](#error-tracking)
|
|
27
|
+
- [Logs](#logs)
|
|
28
|
+
- [Session replay](#session-replay)
|
|
29
|
+
- [Surveys](#surveys)
|
|
30
|
+
- [Push notifications](#push-notifications)
|
|
31
|
+
- [Debug mode](#debug-mode)
|
|
32
|
+
- [Disabling for local development](#disabling-for-local-development)
|
|
33
|
+
- [Upgrading from V1, V2 to V3 or V3 to V4](#upgrading-from-v1-v2-to-v3-or-v3-to-v4)
|
|
34
|
+
|
|
5
35
|
## Installation
|
|
6
36
|
|
|
7
37
|
Our React Native enables you to integrate PostHog with your React Native project. For React Native projects built with Expo, there are no mobile native dependencies outside of supported Expo packages.
|
|
@@ -10,16 +40,12 @@ To install, add the `posthog-react-native` package to your project as well as th
|
|
|
10
40
|
|
|
11
41
|
#### Expo apps
|
|
12
42
|
|
|
13
|
-
Terminal
|
|
14
|
-
|
|
15
43
|
```bash
|
|
16
44
|
npx expo install posthog-react-native expo-file-system expo-application expo-device expo-localization
|
|
17
45
|
```
|
|
18
46
|
|
|
19
47
|
#### React Native apps
|
|
20
48
|
|
|
21
|
-
Terminal
|
|
22
|
-
|
|
23
49
|
```bash
|
|
24
50
|
yarn add posthog-react-native @react-native-async-storage/async-storage react-native-device-info react-native-localize
|
|
25
51
|
# or
|
|
@@ -34,7 +60,7 @@ If you're using [React Native Web](https://github.com/necolas/react-native-web)
|
|
|
34
60
|
|
|
35
61
|
#### With the PosthogProvider
|
|
36
62
|
|
|
37
|
-
The recommended way to set up PostHog for React Native is to use the `PostHogProvider`. This utilizes the Context API to pass the PostHog client around, and enables [autocapture](/docs/product-analytics/autocapture.md).
|
|
63
|
+
The recommended way to set up PostHog for React Native is to use the `PostHogProvider`. This utilizes the Context API to pass the PostHog client around, and enables [autocapture](https://posthog.com/docs/product-analytics/autocapture.md).
|
|
38
64
|
|
|
39
65
|
To set up `PostHogProvider`, add it to your `App.js` or `App.ts` file:
|
|
40
66
|
|
|
@@ -59,8 +85,6 @@ export function MyApp() {
|
|
|
59
85
|
|
|
60
86
|
Then you can access PostHog using the `usePostHog()` hook:
|
|
61
87
|
|
|
62
|
-
React Native
|
|
63
|
-
|
|
64
88
|
```jsx
|
|
65
89
|
const MyComponent = () => {
|
|
66
90
|
const posthog = usePostHog()
|
|
@@ -88,8 +112,6 @@ export const posthog = new PostHog('<ph_project_token>', {
|
|
|
88
112
|
|
|
89
113
|
Then you can access PostHog by importing your instance:
|
|
90
114
|
|
|
91
|
-
React Native
|
|
92
|
-
|
|
93
115
|
```jsx
|
|
94
116
|
import { posthog } from './posthog'
|
|
95
117
|
|
|
@@ -104,8 +126,6 @@ export function MyApp1() {
|
|
|
104
126
|
|
|
105
127
|
You can even use this instance with the PostHogProvider:
|
|
106
128
|
|
|
107
|
-
React Native
|
|
108
|
-
|
|
109
129
|
```jsx
|
|
110
130
|
import { posthog } from './posthog'
|
|
111
131
|
|
|
@@ -130,8 +150,6 @@ This verification does not cover Expo or other React Native versions. Use CocoaP
|
|
|
130
150
|
|
|
131
151
|
Use the standard React Native CocoaPods flow:
|
|
132
152
|
|
|
133
|
-
Terminal
|
|
134
|
-
|
|
135
153
|
```bash
|
|
136
154
|
cd ios
|
|
137
155
|
pod install
|
|
@@ -143,8 +161,6 @@ The plugin podspec adds `posthog-ios` as a CocoaPods dependency. You do not need
|
|
|
143
161
|
|
|
144
162
|
Add the following property to `ios/Podfile.properties.json`:
|
|
145
163
|
|
|
146
|
-
JSON
|
|
147
|
-
|
|
148
164
|
```json
|
|
149
165
|
{
|
|
150
166
|
"posthog.useSpm": "true"
|
|
@@ -153,16 +169,12 @@ JSON
|
|
|
153
169
|
|
|
154
170
|
Add dynamic frameworks to your `ios/Podfile`:
|
|
155
171
|
|
|
156
|
-
Ruby
|
|
157
|
-
|
|
158
172
|
```ruby
|
|
159
173
|
use_frameworks! :linkage => :dynamic
|
|
160
174
|
```
|
|
161
175
|
|
|
162
176
|
Then install the pods:
|
|
163
177
|
|
|
164
|
-
Terminal
|
|
165
|
-
|
|
166
178
|
```bash
|
|
167
179
|
cd ios
|
|
168
180
|
pod install
|
|
@@ -176,8 +188,6 @@ This path uses React Native's experimental CocoaPods-free iOS integration. Every
|
|
|
176
188
|
|
|
177
189
|
Install your JavaScript dependencies first. Make a clean commit or a backup of your iOS project before the conversion. Then run this command from the `ios` directory:
|
|
178
190
|
|
|
179
|
-
Terminal
|
|
180
|
-
|
|
181
191
|
```bash
|
|
182
192
|
npx react-native spm add --deintegrate --yes
|
|
183
193
|
```
|
|
@@ -186,23 +196,23 @@ The `--deintegrate` option removes the complete CocoaPods integration from the i
|
|
|
186
196
|
|
|
187
197
|
PostHog CI verifies this path with the configuration in the requirements table. The verified app sets its deployment target to iOS 15.1. The plugin package manifest has a separate iOS 15 minimum. The CocoaPods and hybrid paths keep the plugin podspec's iOS 13 minimum.
|
|
188
198
|
|
|
189
|
-
Set up a reverse proxy (recommended)
|
|
199
|
+
**Set up a reverse proxy (recommended)**
|
|
190
200
|
|
|
191
|
-
We recommend [setting up a reverse proxy](/docs/advanced/proxy.md), so that events are less likely to be intercepted by tracking blockers.
|
|
201
|
+
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.
|
|
192
202
|
|
|
193
|
-
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.
|
|
203
|
+
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.
|
|
194
204
|
|
|
195
|
-
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).
|
|
205
|
+
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).
|
|
196
206
|
|
|
197
|
-
Grouping products in one project (recommended)
|
|
207
|
+
**Grouping products in one project (recommended)**
|
|
198
208
|
|
|
199
|
-
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).
|
|
209
|
+
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).
|
|
200
210
|
|
|
201
211
|
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.
|
|
202
212
|
|
|
203
|
-
Add IPs to Firewall/WAF allowlists (recommended)
|
|
213
|
+
**Add IPs to Firewall/WAF allowlists (recommended)**
|
|
204
214
|
|
|
205
|
-
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.
|
|
215
|
+
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.
|
|
206
216
|
|
|
207
217
|
**EU**: `3.75.65.221`, `18.197.246.42`, `3.120.223.253`
|
|
208
218
|
|
|
@@ -212,7 +222,7 @@ These are public, stable IPs used by PostHog services.
|
|
|
212
222
|
|
|
213
223
|
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).
|
|
214
224
|
|
|
215
|
-
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).
|
|
225
|
+
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).
|
|
216
226
|
|
|
217
227
|
### Configuration options
|
|
218
228
|
|
|
@@ -229,7 +239,7 @@ You can further customize how PostHog works through its configuration on initial
|
|
|
229
239
|
| `defaultOptIn` **Type:** Boolean **Default:** `true` | If set to false, the SDK will not track until the `optIn()` function is called. |
|
|
230
240
|
| `sendFeatureFlagEvent` **Type:** Boolean **Default:** `true` | Whether to track that `getFeatureFlag` was called (used by experiments). |
|
|
231
241
|
| `preloadFeatureFlags` **Type:** Boolean **Default:** `true` | Whether to load feature flags when initialized or not. |
|
|
232
|
-
| `bootstrap` **Type:** Object **Default:** `{}` | Seeds identity (`distinctId`, `isIdentifiedId`) and feature flag state (`featureFlags`, `featureFlagPayloads`) during initialization. See [SDK bootstrapping](/docs/libraries/bootstrapping.md). |
|
|
242
|
+
| `bootstrap` **Type:** Object **Default:** `{}` | Seeds identity (`distinctId`, `isIdentifiedId`) and feature flag state (`featureFlags`, `featureFlagPayloads`) during initialization. See [SDK bootstrapping](https://posthog.com/docs/libraries/bootstrapping.md). |
|
|
233
243
|
| `disableRemoteFeatureFlags` **Type:** Boolean **Default:** `false` | When `true`, the SDK never fetches or evaluates feature flags from PostHog, and `identify()`, `group()`, and `reset()` stop triggering `/flags` requests. Supply flag values yourself via `bootstrap` (at startup) and `updateFlags()` (at runtime). Available in version 4.49.0+. |
|
|
234
244
|
| `fetchRetryCount` **Type:** Number **Default:** `3` | How many times HTTP requests will be retried. |
|
|
235
245
|
| `fetchRetryDelay` **Type:** Number **Default:** `3000` | The delay between HTTP request retries. |
|
|
@@ -242,12 +252,12 @@ You can further customize how PostHog works through its configuration on initial
|
|
|
242
252
|
| `captureAppLifecycleEvents` **Type:** Boolean **Default:** `true` | Captures app lifecycle events such as Application Installed, Application Updated, Application Opened, Application Became Active, and Application Backgrounded. Enabled by default since version 4.39.0. |
|
|
243
253
|
| `disableGeoip` **Type:** Boolean **Default:** `false` | When true, disables automatic GeoIP resolution for events and feature flags. |
|
|
244
254
|
| `enableSessionReplay` **Type:** Boolean **Default:** `false` | Enable Recording of Session replay for Android and iOS. |
|
|
245
|
-
| `sessionReplayConfig` **Type:** Object **Default:** `null` | Session replay configuration. See the [replay install docs](/docs/session-replay/installation.md) for more details. |
|
|
255
|
+
| `sessionReplayConfig` **Type:** Object **Default:** `null` | Session replay configuration. See the [replay install docs](https://posthog.com/docs/session-replay/installation.md) for more details. |
|
|
246
256
|
| `enablePersistSessionIdAcrossRestart` **Type:** Boolean **Default:** `false` | When true, persists the `$session_id` across app restarts. If false, `$session_id` always resets on app restart. |
|
|
247
|
-
| `evaluationContexts` **Type:** Array of Strings **Default:** `undefined` | Evaluation context tags that constrain which feature flags are evaluated. When set, only flags with matching evaluation context tags (or no evaluation context tags) will be returned. This helps reduce unnecessary flag evaluations and improves performance. See [evaluation contexts documentation](/docs/feature-flags/evaluation-contexts.md) for more details. Available in version 4.21.0+. The legacy parameter `evaluationEnvironments` (version 4.10.0+) is also supported for backward compatibility. |
|
|
257
|
+
| `evaluationContexts` **Type:** Array of Strings **Default:** `undefined` | Evaluation context tags that constrain which feature flags are evaluated. When set, only flags with matching evaluation context tags (or no evaluation context tags) will be returned. This helps reduce unnecessary flag evaluations and improves performance. See [evaluation contexts documentation](https://posthog.com/docs/feature-flags/evaluation-contexts.md) for more details. Available in version 4.21.0+. The legacy parameter `evaluationEnvironments` (version 4.10.0+) is also supported for backward compatibility. |
|
|
248
258
|
| `addTracingHeaders` **Type:** Array of Strings **Default:** `undefined` | Hostnames for which PostHog should add tracing headers to outgoing `fetch` requests. Matching requests include `X-POSTHOG-DISTINCT-ID` and `X-POSTHOG-SESSION-ID`, which lets backend events, errors, and LLM traces link back to frontend sessions and replays. Use hostnames only, without the protocol or path. |
|
|
249
259
|
| `before_send` **Type:** Function **Default:** `undefined` | A callback function that is called before each event is sent to PostHog. You can use it to modify, filter, or suppress events. Return `null` to drop the event, or return the modified event to send it. See [customizing exception capture](#customizing-exception-capture-with-before_send) for details. |
|
|
250
|
-
| `capturePushNotificationSubscriptions` **Type:** Boolean **Default:** `true` | Whether to automatically register this device's push token so [Workflows](/docs/workflows.md) can target it. Requires `@posthog/react-native-plugin`. See [push notifications](#push-notifications). Available in version 4.62.0+. |
|
|
260
|
+
| `capturePushNotificationSubscriptions` **Type:** Boolean **Default:** `true` | Whether to automatically register this device's push token so [Workflows](https://posthog.com/docs/workflows.md) can target it. Requires `@posthog/react-native-plugin`. See [push notifications](#push-notifications). Available in version 4.62.0+. |
|
|
251
261
|
| `capturePushNotificationOpened` **Type:** Boolean **Default:** `true` | Whether to automatically capture `$push_notification_opened` when the user taps a push notification. Requires `@posthog/react-native-plugin`. See [push notifications](#push-notifications). Available in version 4.62.0+. |
|
|
252
262
|
| `pushIdentityProvider` **Type:** Function **Default:** `undefined` | Supplies a signed identity-verification token for push subscription requests. Only needed when your push channel requires identity verification. See [identity verification](#identity-verification). Available in version 4.62.0+. |
|
|
253
263
|
|
|
@@ -255,8 +265,6 @@ You can further customize how PostHog works through its configuration on initial
|
|
|
255
265
|
|
|
256
266
|
Use `addTracingHeaders` to connect React Native network requests to backend events, errors, and LLM traces captured by a server-side PostHog SDK:
|
|
257
267
|
|
|
258
|
-
typescript
|
|
259
|
-
|
|
260
268
|
```typescript
|
|
261
269
|
const posthog = new PostHog('<ph_project_token>', {
|
|
262
270
|
host: 'https://us.i.posthog.com',
|
|
@@ -270,8 +278,6 @@ Hostnames are matched exactly. The SDK patches global `fetch` and sends `X-POSTH
|
|
|
270
278
|
|
|
271
279
|
You can send custom events using `capture`:
|
|
272
280
|
|
|
273
|
-
React Native
|
|
274
|
-
|
|
275
281
|
```jsx
|
|
276
282
|
posthog.capture('user_signed_up')
|
|
277
283
|
```
|
|
@@ -280,9 +286,7 @@ posthog.capture('user_signed_up')
|
|
|
280
286
|
|
|
281
287
|
### Setting event properties
|
|
282
288
|
|
|
283
|
-
Optionally, you can include additional information with the event by including a [properties](/docs/data/events.md#event-properties) object:
|
|
284
|
-
|
|
285
|
-
React Native
|
|
289
|
+
Optionally, you can include additional information with the event by including a [properties](https://posthog.com/docs/data/events.md#event-properties) object:
|
|
286
290
|
|
|
287
291
|
```jsx
|
|
288
292
|
posthog.capture('user_signed_up', {
|
|
@@ -295,12 +299,10 @@ posthog.capture('user_signed_up', {
|
|
|
295
299
|
|
|
296
300
|
#### With `@react-navigation/native` and autocapture:
|
|
297
301
|
|
|
298
|
-
When using [@react-navigation/native](https://reactnavigation.org/docs/6.x/getting-started) v6 or lower, screen tracking is automatically captured if the [`autocapture`](/docs/libraries/react-native.md#autocapture) property is used in the `PostHogProvider`:
|
|
302
|
+
When using [@react-navigation/native](https://reactnavigation.org/docs/6.x/getting-started) v6 or lower, screen tracking is automatically captured if the [`autocapture`](https://posthog.com/docs/libraries/react-native.md#autocapture) property is used in the `PostHogProvider`:
|
|
299
303
|
|
|
300
304
|
It is important that the `PostHogProvider` is configured as a child of the `NavigationContainer`:
|
|
301
305
|
|
|
302
|
-
React Native
|
|
303
|
-
|
|
304
306
|
```jsx
|
|
305
307
|
// App.(js|ts)
|
|
306
308
|
|
|
@@ -320,8 +322,6 @@ export function App() {
|
|
|
320
322
|
|
|
321
323
|
When using [@react-navigation/native](https://reactnavigation.org/docs/7.x/getting-started) v7 or higher, screen tracking has to be manually captured:
|
|
322
324
|
|
|
323
|
-
React Native
|
|
324
|
-
|
|
325
325
|
```jsx
|
|
326
326
|
// App.(js|ts)
|
|
327
327
|
|
|
@@ -347,8 +347,6 @@ Check out and set it up the official way for [Screen tracking for analytics](htt
|
|
|
347
347
|
|
|
348
348
|
Then call the `screen` method within the `trackScreenView` method.
|
|
349
349
|
|
|
350
|
-
React Native
|
|
351
|
-
|
|
352
350
|
```jsx
|
|
353
351
|
const posthog = usePostHog() // use the usePostHog hook if using the PostHogProvider or your own custom posthog instance
|
|
354
352
|
// you can read the params from `getCurrentRoute()`
|
|
@@ -359,8 +357,6 @@ posthog.screen(currentRouteName, params)
|
|
|
359
357
|
|
|
360
358
|
First, simplify the wrapping of your screens with a shared PostHogProvider:
|
|
361
359
|
|
|
362
|
-
React Native
|
|
363
|
-
|
|
364
360
|
```jsx
|
|
365
361
|
import PostHog, { PostHogProvider } from 'posthog-react-native'
|
|
366
362
|
import { Navigation } from 'react-native-navigation';
|
|
@@ -381,8 +377,6 @@ export const SharedPostHogProvider = (props: any) => {
|
|
|
381
377
|
|
|
382
378
|
Then, every screen needs to be wrapped with this provider if you want to capture touches or use the `usePostHog()` hook
|
|
383
379
|
|
|
384
|
-
React Native
|
|
385
|
-
|
|
386
380
|
```jsx
|
|
387
381
|
export const MyScreen = () => {
|
|
388
382
|
return (
|
|
@@ -415,8 +409,6 @@ Check out and set it up the official way for [Screen tracking for analytics](htt
|
|
|
415
409
|
|
|
416
410
|
Then call the `screen` method within the `useEffect` callback.
|
|
417
411
|
|
|
418
|
-
React Native
|
|
419
|
-
|
|
420
412
|
```jsx
|
|
421
413
|
const posthog = usePostHog() // use the usePostHog hook if using the PostHogProvider or your own custom posthog instance
|
|
422
414
|
posthog.screen(pathname, params)
|
|
@@ -426,8 +418,6 @@ posthog.screen(pathname, params)
|
|
|
426
418
|
|
|
427
419
|
If you prefer not to use autocapture, you can manually capture screen views by calling `posthog.screen()`. This function requires a `name`. You may also pass in an optional `properties` object.
|
|
428
420
|
|
|
429
|
-
JavaScript
|
|
430
|
-
|
|
431
421
|
```javascript
|
|
432
422
|
posthog.screen('dashboard', {
|
|
433
423
|
background: 'blue',
|
|
@@ -444,7 +434,7 @@ PostHog autocapture can automatically track the following events for you:
|
|
|
444
434
|
- **Application Backgrounded** – when the app is sent to the background by the user
|
|
445
435
|
- **Application Installed** – when the app is installed.
|
|
446
436
|
- **Application Updated** – when the app is updated.
|
|
447
|
-
- **$screen** – when the user navigates (if using `@react-navigation/native` (v6 or lower) or `react-native-navigation`), check out the [capturing screen views](/docs/libraries/react-native.md#capturing-screen-views) section
|
|
437
|
+
- **$screen** – when the user navigates (if using `@react-navigation/native` (v6 or lower) or `react-native-navigation`), check out the [capturing screen views](https://posthog.com/docs/libraries/react-native.md#capturing-screen-views) section
|
|
448
438
|
- **$autocapture** – touch events when the user interacts with the screen
|
|
449
439
|
- **$exception** – when the app throws exceptions.
|
|
450
440
|
|
|
@@ -454,24 +444,20 @@ PostHog autocapture can automatically track the following events for you:
|
|
|
454
444
|
>
|
|
455
445
|
> Because of this change, automatic screen tracking may throw errors if PostHog is initialized outside a screen context. This commonly affects apps upgrading from React Navigation v6 to v7.
|
|
456
446
|
>
|
|
457
|
-
> For React Navigation v7, we recommend disabling automatic screen capture for screens and manually calling `posthog.screen()` inside each screen component. See the [Capturing screen views](/docs/libraries/react-native.md#capturing-screen-views) section below.
|
|
447
|
+
> For React Navigation v7, we recommend disabling automatic screen capture for screens and manually calling `posthog.screen()` inside each screen component. See the [Capturing screen views](https://posthog.com/docs/libraries/react-native.md#capturing-screen-views) section below.
|
|
458
448
|
|
|
459
449
|
Application lifecycle events are enabled by default. Screen capture is enabled by default in `PostHogProvider` unless you set `captureScreens: false`. Touch capture is disabled by default and requires `captureTouches: true`.
|
|
460
450
|
|
|
461
|
-
When touch capture is enabled, touch events for children of `PostHogProvider` are tracked, capturing a snapshot of the view hierarchy at that point. This enables you to create [insights](/docs/product-analytics/insights.md) in PostHog without adding custom events.
|
|
451
|
+
When touch capture is enabled, touch events for children of `PostHogProvider` are tracked, capturing a snapshot of the view hierarchy at that point. This enables you to create [insights](https://posthog.com/docs/product-analytics/insights.md) in PostHog without adding custom events.
|
|
462
452
|
|
|
463
453
|
PostHog will try to generate a sensible name for touched elements based on the React component `displayName` or `name`. If you prefer, you can set your own name using the `ph-label` prop:
|
|
464
454
|
|
|
465
|
-
React Native
|
|
466
|
-
|
|
467
455
|
```jsx
|
|
468
456
|
<View ph-label="my-special-label"></View>
|
|
469
457
|
```
|
|
470
458
|
|
|
471
459
|
### Autocapture configuration
|
|
472
460
|
|
|
473
|
-
React Native
|
|
474
|
-
|
|
475
461
|
```jsx
|
|
476
462
|
<PostHogProvider apiKey="<ph_project_token>" autocapture={{
|
|
477
463
|
captureTouches: true, // Disabled by default
|
|
@@ -503,8 +489,6 @@ React Native
|
|
|
503
489
|
|
|
504
490
|
If there are elements you don't want to be captured, you can add the `ph-no-capture` property. If this property is found anywhere in the view hierarchy, the entire touch event is ignored:
|
|
505
491
|
|
|
506
|
-
React Native
|
|
507
|
-
|
|
508
492
|
```jsx
|
|
509
493
|
<View ph-no-capture>Sensitive view here</View>
|
|
510
494
|
```
|
|
@@ -515,8 +499,6 @@ With `captureScreens: true` (the default in `PostHogProvider`), PostHog captures
|
|
|
515
499
|
|
|
516
500
|
To manually send a screen capture event, use the `screen` method:
|
|
517
501
|
|
|
518
|
-
React Native
|
|
519
|
-
|
|
520
502
|
```jsx
|
|
521
503
|
posthog.screen('Dashboard', { fromIcon: 'bottom' })
|
|
522
504
|
```
|
|
@@ -531,8 +513,6 @@ Because it's just a function, you can filter however you like – an **ignorelis
|
|
|
531
513
|
|
|
532
514
|
`before_send` is a client option, so pass it via the provider's `options` prop (or to `new PostHog(...)` if you create the client yourself):
|
|
533
515
|
|
|
534
|
-
React Native
|
|
535
|
-
|
|
536
516
|
```jsx
|
|
537
517
|
const IGNORED_SCREENS = new Set(['Splash', 'Debug'])
|
|
538
518
|
|
|
@@ -562,8 +542,6 @@ Swap the check for an allowlist (`return TRACKED_SCREENS.has(screenName) ? event
|
|
|
562
542
|
|
|
563
543
|
**Drop a specific event.** Stop an internal or debug event from ever being sent:
|
|
564
544
|
|
|
565
|
-
React Native
|
|
566
|
-
|
|
567
545
|
```jsx
|
|
568
546
|
const posthog = new PostHog('<ph_project_token>', {
|
|
569
547
|
before_send: (event) => {
|
|
@@ -577,8 +555,6 @@ const posthog = new PostHog('<ph_project_token>', {
|
|
|
577
555
|
|
|
578
556
|
**Log events instead of sending them.** Handy while debugging what would be captured:
|
|
579
557
|
|
|
580
|
-
React Native
|
|
581
|
-
|
|
582
558
|
```jsx
|
|
583
559
|
const posthog = new PostHog('<ph_project_token>', {
|
|
584
560
|
before_send: (event) => {
|
|
@@ -590,8 +566,6 @@ const posthog = new PostHog('<ph_project_token>', {
|
|
|
590
566
|
|
|
591
567
|
**Redact sensitive properties.** Strip a value before it leaves the device:
|
|
592
568
|
|
|
593
|
-
React Native
|
|
594
|
-
|
|
595
569
|
```jsx
|
|
596
570
|
const posthog = new PostHog('<ph_project_token>', {
|
|
597
571
|
before_send: (event) => {
|
|
@@ -603,20 +577,18 @@ const posthog = new PostHog('<ph_project_token>', {
|
|
|
603
577
|
})
|
|
604
578
|
```
|
|
605
579
|
|
|
606
|
-
For more examples, see the [JavaScript Web SDK docs](/docs/libraries/js/usage.md#amending-or-sampling-events).
|
|
580
|
+
For more examples, see the [JavaScript Web SDK docs](https://posthog.com/docs/libraries/js/usage.md#amending-or-sampling-events).
|
|
607
581
|
|
|
608
582
|
## Identifying users
|
|
609
583
|
|
|
610
|
-
> We highly recommend reading our section on [Identifying users](/docs/integrate/identifying-users.md) to better understand how to correctly use this method.
|
|
584
|
+
> We highly recommend reading our section on [Identifying users](https://posthog.com/docs/integrate/identifying-users.md) to better understand how to correctly use this method.
|
|
611
585
|
|
|
612
586
|
Using `identify`, you can associate events with specific users. This enables you to gain full insights as to how they're using your product across different sessions, devices, and platforms.
|
|
613
587
|
|
|
614
588
|
An `identify` call has the following arguments:
|
|
615
589
|
|
|
616
590
|
- **distinctId:** Required. A unique identifier for your user. Typically either their email or database ID.
|
|
617
|
-
- **properties:** Optional. A dictionary with key:value pairs to set the [person properties](/docs/product-analytics/person-properties.md)
|
|
618
|
-
|
|
619
|
-
React Native
|
|
591
|
+
- **properties:** Optional. A dictionary with key:value pairs to set the [person properties](https://posthog.com/docs/product-analytics/person-properties.md)
|
|
620
592
|
|
|
621
593
|
```jsx
|
|
622
594
|
posthog.identify('distinctID',
|
|
@@ -627,9 +599,7 @@ posthog.identify('distinctID',
|
|
|
627
599
|
)
|
|
628
600
|
```
|
|
629
601
|
|
|
630
|
-
`$set_once` works just like `$set`, except that it will **only set the property if the user doesn't already have that property set**. [See the difference between `$set` and `$set_once`](/docs/product-analytics/person-properties.md#what-is-the-difference-between-set-and-set_once)
|
|
631
|
-
|
|
632
|
-
React Native
|
|
602
|
+
`$set_once` works just like `$set`, except that it will **only set the property if the user doesn't already have that property set**. [See the difference between `$set` and `$set_once`](https://posthog.com/docs/product-analytics/person-properties.md#what-is-the-difference-between-set-and-set_once)
|
|
633
603
|
|
|
634
604
|
```jsx
|
|
635
605
|
posthog.identify('distinctID',
|
|
@@ -647,7 +617,7 @@ posthog.identify('distinctID',
|
|
|
647
617
|
|
|
648
618
|
You should call `identify` as soon as you're able to. Typically, this is after your user logs in. This ensures that events sent during your user's sessions are correctly associated with them.
|
|
649
619
|
|
|
650
|
-
When you call `identify`, all previously tracked [anonymous events](/docs/data/anonymous-vs-identified-events.md) will be linked to the user.
|
|
620
|
+
When you call `identify`, all previously tracked [anonymous events](https://posthog.com/docs/data/anonymous-vs-identified-events.md) will be linked to the user.
|
|
651
621
|
|
|
652
622
|
## Get the current user's distinct ID
|
|
653
623
|
|
|
@@ -661,25 +631,21 @@ Sometimes, you want to assign multiple distinct IDs to a single user. This is he
|
|
|
661
631
|
|
|
662
632
|
In this case, you can use `alias` to assign another distinct ID to the same user.
|
|
663
633
|
|
|
664
|
-
React Native
|
|
665
|
-
|
|
666
634
|
```jsx
|
|
667
635
|
// Sets alias for current user
|
|
668
636
|
posthog.alias('distinct_id')
|
|
669
637
|
```
|
|
670
638
|
|
|
671
|
-
We strongly recommend reading our docs on [alias](/docs/product-analytics/identify.md#alias-assigning-multiple-distinct-ids-to-the-same-user) to best understand how to correctly use this method.
|
|
639
|
+
We strongly recommend reading our docs on [alias](https://posthog.com/docs/product-analytics/identify.md#alias-assigning-multiple-distinct-ids-to-the-same-user) to best understand how to correctly use this method.
|
|
672
640
|
|
|
673
641
|
## Setting person properties
|
|
674
642
|
|
|
675
|
-
Person properties enable you to capture, manage, and analyze specific data about a user. You can use them to create [filters](/docs/product-analytics/trends.md#filtering-events-based-on-properties) or [cohorts](/docs/data/cohorts.md), which can then be used in [insights](/docs/product-analytics/insights.md), [feature flags](/docs/feature-flags.md), and more.
|
|
643
|
+
Person properties enable you to capture, manage, and analyze specific data about a user. You can use them to create [filters](https://posthog.com/docs/product-analytics/trends.md#filtering-events-based-on-properties) or [cohorts](https://posthog.com/docs/data/cohorts.md), which can then be used in [insights](https://posthog.com/docs/product-analytics/insights.md), [feature flags](https://posthog.com/docs/feature-flags.md), and more.
|
|
676
644
|
|
|
677
645
|
To set a user's properties, include the `$set` or `$set_once` property when capturing any event:
|
|
678
646
|
|
|
679
647
|
### $set
|
|
680
648
|
|
|
681
|
-
JavaScript
|
|
682
|
-
|
|
683
649
|
```javascript
|
|
684
650
|
posthog.capture('some_event', { $set: { userProperty: 'value' } })
|
|
685
651
|
```
|
|
@@ -688,13 +654,11 @@ posthog.capture('some_event', { $set: { userProperty: 'value' } })
|
|
|
688
654
|
|
|
689
655
|
`$set_once` works just like `$set`, except it **only sets the property if the user doesn't already have that property set**.
|
|
690
656
|
|
|
691
|
-
JavaScript
|
|
692
|
-
|
|
693
657
|
```javascript
|
|
694
658
|
posthog.capture('some_event', { $set_once: { userProperty: 'value' } })
|
|
695
659
|
```
|
|
696
660
|
|
|
697
|
-
You can also use `setPersonProperties()` and `unsetPersonProperties()` to manage person properties directly. See [person properties](/docs/product-analytics/person-properties.md) for examples.
|
|
661
|
+
You can also use `setPersonProperties()` and `unsetPersonProperties()` to manage person properties directly. See [person properties](https://posthog.com/docs/product-analytics/person-properties.md) for examples.
|
|
698
662
|
|
|
699
663
|
## Super properties
|
|
700
664
|
|
|
@@ -704,8 +668,6 @@ They are set using `posthog.register`, which takes a properties object as a para
|
|
|
704
668
|
|
|
705
669
|
For example:
|
|
706
670
|
|
|
707
|
-
JavaScript
|
|
708
|
-
|
|
709
671
|
```javascript
|
|
710
672
|
posthog.register({
|
|
711
673
|
'icecream pref': 'vanilla',
|
|
@@ -721,8 +683,6 @@ This does **not** set the user's properties. This only sets the properties for t
|
|
|
721
683
|
|
|
722
684
|
Super Properties are persisted across sessions so you have to explicitly remove them if they are no longer relevant. In order to stop sending a Super Property with events, you can use `posthog.unregister`, like so:
|
|
723
685
|
|
|
724
|
-
JavaScript
|
|
725
|
-
|
|
726
686
|
```javascript
|
|
727
687
|
posthog.unregister('icecream pref'),
|
|
728
688
|
```
|
|
@@ -741,8 +701,6 @@ You can configure how many events queue before flushing with `flushAt`. Setting
|
|
|
741
701
|
|
|
742
702
|
You can also configure the flush interval with `flushInterval`, in milliseconds (default `10000`), after which queued events are sent regardless of how many have been gathered:
|
|
743
703
|
|
|
744
|
-
JavaScript
|
|
745
|
-
|
|
746
704
|
```javascript
|
|
747
705
|
const posthog = new PostHog('<ph_project_token>', {
|
|
748
706
|
flushAt: 20,
|
|
@@ -752,8 +710,6 @@ const posthog = new PostHog('<ph_project_token>', {
|
|
|
752
710
|
|
|
753
711
|
You can also manually flush the queue to start sending events immediately instead of waiting for the next batch:
|
|
754
712
|
|
|
755
|
-
JavaScript
|
|
756
|
-
|
|
757
713
|
```javascript
|
|
758
714
|
await posthog.flush()
|
|
759
715
|
```
|
|
@@ -766,8 +722,6 @@ Flushing is best-effort and asynchronous – it starts sending queued events in
|
|
|
766
722
|
|
|
767
723
|
To reset the user's ID and anonymous ID, call `reset`. Usually you would do this right after the user logs out.
|
|
768
724
|
|
|
769
|
-
JavaScript
|
|
770
|
-
|
|
771
725
|
```javascript
|
|
772
726
|
posthog.reset()
|
|
773
727
|
```
|
|
@@ -788,19 +742,17 @@ You can give your users the option to opt in or out by calling the relevant meth
|
|
|
788
742
|
|
|
789
743
|
To opt in/out of tracking, use the following calls.
|
|
790
744
|
|
|
791
|
-
JavaScript
|
|
792
|
-
|
|
793
745
|
```javascript
|
|
794
746
|
posthog.optedOut // See if a user has opted out
|
|
795
747
|
posthog.optIn() // opt in
|
|
796
748
|
posthog.optOut() // opt out
|
|
797
749
|
```
|
|
798
750
|
|
|
799
|
-
If you still wish capture these events but want to create a distinction between users and team in PostHog, you should look into [Cohorts](/docs/user-guides/cohorts.md#differentiating-team-vs-users-traffic).
|
|
751
|
+
If you still wish capture these events but want to create a distinction between users and team in PostHog, you should look into [Cohorts](https://posthog.com/docs/user-guides/cohorts.md#differentiating-team-vs-users-traffic).
|
|
800
752
|
|
|
801
753
|
## Feature Flags
|
|
802
754
|
|
|
803
|
-
PostHog's [feature flags](/docs/feature-flags.md) enable you to safely deploy and roll back new features as well as target specific users and groups with them.
|
|
755
|
+
PostHog's [feature flags](https://posthog.com/docs/feature-flags.md) enable you to safely deploy and roll back new features as well as target specific users and groups with them.
|
|
804
756
|
|
|
805
757
|
There are two ways to implement feature flags in React Native:
|
|
806
758
|
|
|
@@ -811,8 +763,6 @@ There are two ways to implement feature flags in React Native:
|
|
|
811
763
|
|
|
812
764
|
#### Example 1: Boolean feature flags
|
|
813
765
|
|
|
814
|
-
React Native
|
|
815
|
-
|
|
816
766
|
```jsx
|
|
817
767
|
import { useFeatureFlag } from 'posthog-react-native'
|
|
818
768
|
|
|
@@ -832,8 +782,6 @@ const MyComponent = () => {
|
|
|
832
782
|
|
|
833
783
|
#### Example 2: Multivariate feature flags
|
|
834
784
|
|
|
835
|
-
React Native
|
|
836
|
-
|
|
837
785
|
```jsx
|
|
838
786
|
import { useFeatureFlag } from 'posthog-react-native'
|
|
839
787
|
|
|
@@ -855,8 +803,6 @@ const MyComponent = () => {
|
|
|
855
803
|
|
|
856
804
|
### Method 2: Loading the flag directly
|
|
857
805
|
|
|
858
|
-
React Native
|
|
859
|
-
|
|
860
806
|
```jsx
|
|
861
807
|
// Defaults to undefined if not loaded yet or if there was a problem loading
|
|
862
808
|
posthog.isFeatureEnabled('key-for-your-boolean-flag')
|
|
@@ -875,8 +821,6 @@ posthog.getFeatureFlagResult('key-for-your-multivariate-flag')?.payload
|
|
|
875
821
|
|
|
876
822
|
You can inspect all currently loaded feature flags with `getAllFeatureFlags()`. It returns each flag's `key`, `enabled` state, `variant`, and `payload`, and does not send a `$feature_flag_called` event, so calling it won't affect your experiment results or flag usage analytics:
|
|
877
823
|
|
|
878
|
-
React Native
|
|
879
|
-
|
|
880
824
|
```jsx
|
|
881
825
|
for (const flag of posthog.getAllFeatureFlags()) {
|
|
882
826
|
console.log(flag.key, flag.enabled, flag.variant, flag.payload)
|
|
@@ -891,8 +835,6 @@ This means that for most screens, the feature flags are available immediately
|
|
|
891
835
|
|
|
892
836
|
To handle this, you can use the `onFeatureFlags` callback to wait for the feature flag request to finish:
|
|
893
837
|
|
|
894
|
-
React Native
|
|
895
|
-
|
|
896
838
|
```jsx
|
|
897
839
|
posthog.onFeatureFlags((flags) => {
|
|
898
840
|
// feature flags are guaranteed to be available at this point
|
|
@@ -908,16 +850,12 @@ PostHog loads feature flags when instantiated and refreshes whenever methods are
|
|
|
908
850
|
|
|
909
851
|
If want to manually trigger a refresh, you can call `reloadFeatureFlagsAsync()`:
|
|
910
852
|
|
|
911
|
-
React Native
|
|
912
|
-
|
|
913
853
|
```jsx
|
|
914
854
|
posthog.reloadFeatureFlagsAsync().then((refreshedFlags) => console.log(refreshedFlags))
|
|
915
855
|
```
|
|
916
856
|
|
|
917
857
|
Or when you want to trigger the reload, but don't care about the result:
|
|
918
858
|
|
|
919
|
-
React Native
|
|
920
|
-
|
|
921
859
|
```jsx
|
|
922
860
|
posthog.reloadFeatureFlags()
|
|
923
861
|
```
|
|
@@ -930,8 +868,6 @@ For example, if a user last opened your app when a flag was `false`, that value
|
|
|
930
868
|
|
|
931
869
|
To ensure fresh flag values:
|
|
932
870
|
|
|
933
|
-
React Native
|
|
934
|
-
|
|
935
871
|
```jsx
|
|
936
872
|
// Force refresh on app start
|
|
937
873
|
await posthog.reloadFeatureFlagsAsync()
|
|
@@ -939,8 +875,6 @@ await posthog.reloadFeatureFlagsAsync()
|
|
|
939
875
|
|
|
940
876
|
Or clear cached values for inactive users:
|
|
941
877
|
|
|
942
|
-
React Native
|
|
943
|
-
|
|
944
878
|
```jsx
|
|
945
879
|
if (lastActiveDate < migrationDate) {
|
|
946
880
|
posthog.reset() // Clears all cached data
|
|
@@ -951,8 +885,6 @@ if (lastActiveDate < migrationDate) {
|
|
|
951
885
|
|
|
952
886
|
You can configure the `featureFlagsRequestTimeoutMs` parameter when initializing your PostHog client to set a flag request timeout. This helps prevent your code from being blocked in the case when PostHog's servers are too slow to respond. By default, this is set at 10 seconds.
|
|
953
887
|
|
|
954
|
-
React Native
|
|
955
|
-
|
|
956
888
|
```jsx
|
|
957
889
|
export const posthog = new PostHog('<ph_project_token>', {
|
|
958
890
|
// usually 'https://us.i.posthog.com' or 'https://eu.i.posthog.com'
|
|
@@ -965,8 +897,6 @@ export const posthog = new PostHog('<ph_project_token>', {
|
|
|
965
897
|
|
|
966
898
|
When using the PostHog SDK, it's important to handle potential errors that may occur during feature flag operations. Here's an example of how to wrap PostHog SDK methods in an error handler:
|
|
967
899
|
|
|
968
|
-
React Native
|
|
969
|
-
|
|
970
900
|
```jsx
|
|
971
901
|
function handleFeatureFlag(client, flagKey, distinctId) {
|
|
972
902
|
try {
|
|
@@ -1000,8 +930,6 @@ try {
|
|
|
1000
930
|
|
|
1001
931
|
Sometimes, you might want to evaluate feature flags using properties that haven't been ingested yet, or were set incorrectly earlier. You can do so by setting properties the flag depends on with these calls:
|
|
1002
932
|
|
|
1003
|
-
React Native
|
|
1004
|
-
|
|
1005
933
|
```jsx
|
|
1006
934
|
posthog.setPersonPropertiesForFlags({'property1': 'value', property2: 'value2'})
|
|
1007
935
|
```
|
|
@@ -1010,23 +938,17 @@ Note that these are set for the entire session. Successive calls are additive: a
|
|
|
1010
938
|
|
|
1011
939
|
Whenever you set these properties, we also trigger a reload of feature flags to ensure we have the latest values. You can disable this by passing in the optional parameter for reloading:
|
|
1012
940
|
|
|
1013
|
-
React Native
|
|
1014
|
-
|
|
1015
941
|
```jsx
|
|
1016
942
|
posthog.setPersonPropertiesForFlags({'property1': 'value', property2: 'value2'}, false)
|
|
1017
943
|
```
|
|
1018
944
|
|
|
1019
945
|
At any point, you can reset these properties by calling `resetPersonPropertiesForFlags`:
|
|
1020
946
|
|
|
1021
|
-
React Native
|
|
1022
|
-
|
|
1023
947
|
```jsx
|
|
1024
948
|
posthog.resetPersonPropertiesForFlags()
|
|
1025
949
|
```
|
|
1026
950
|
|
|
1027
|
-
The same holds for [group](/docs/product-analytics/group-analytics.md) properties:
|
|
1028
|
-
|
|
1029
|
-
React Native
|
|
951
|
+
The same holds for [group](https://posthog.com/docs/product-analytics/group-analytics.md) properties:
|
|
1030
952
|
|
|
1031
953
|
```jsx
|
|
1032
954
|
// set properties for a group
|
|
@@ -1066,8 +988,6 @@ To have your feature flags available immediately, you can initialize PostHog wit
|
|
|
1066
988
|
|
|
1067
989
|
Pass `bootstrap` in the initialization options to seed identity and flag values:
|
|
1068
990
|
|
|
1069
|
-
React Native
|
|
1070
|
-
|
|
1071
991
|
```jsx
|
|
1072
992
|
<PostHogProvider
|
|
1073
993
|
apiKey="<ph_project_token>"
|
|
@@ -1087,16 +1007,14 @@ React Native
|
|
|
1087
1007
|
</PostHogProvider>
|
|
1088
1008
|
```
|
|
1089
1009
|
|
|
1090
|
-
See [bootstrapping Feature Flags](/docs/feature-flags/bootstrapping.md) for server-side evaluation and flag lifecycle, and [SDK bootstrapping](/docs/libraries/bootstrapping.md) for cross-SDK identity behavior.
|
|
1010
|
+
See [bootstrapping Feature Flags](https://posthog.com/docs/feature-flags/bootstrapping.md) for server-side evaluation and flag lifecycle, and [SDK bootstrapping](https://posthog.com/docs/libraries/bootstrapping.md) for cross-SDK identity behavior.
|
|
1091
1011
|
|
|
1092
1012
|
### Supplying flags from your own backend
|
|
1093
1013
|
|
|
1094
|
-
If you evaluate feature flags outside the SDK – for example on your own server with [`posthog-node` local evaluation](/docs/feature-flags/local-evaluation.md), then pass the results into your app – you can have the SDK use those values and never fetch flags itself.
|
|
1014
|
+
If you evaluate feature flags outside the SDK – for example on your own server with [`posthog-node` local evaluation](https://posthog.com/docs/feature-flags/local-evaluation.md), then pass the results into your app – you can have the SDK use those values and never fetch flags itself.
|
|
1095
1015
|
|
|
1096
1016
|
Set `disableRemoteFeatureFlags: true` so the SDK never requests `/flags` (including the refetches that `identify()`, `group()`, and `reset()` normally trigger), then push your evaluated flags at runtime with `updateFlags(flags, payloads?, { merge })`:
|
|
1097
1017
|
|
|
1098
|
-
React Native
|
|
1099
|
-
|
|
1100
1018
|
```jsx
|
|
1101
1019
|
const posthog = new PostHog('<ph_project_token>', {
|
|
1102
1020
|
host: 'https://us.i.posthog.com',
|
|
@@ -1126,32 +1044,53 @@ Note that `reset()` (called on logout) clears the supplied flags, so re-push the
|
|
|
1126
1044
|
|
|
1127
1045
|
## Experiments (A/B tests)
|
|
1128
1046
|
|
|
1129
|
-
Since [experiments](/docs/experiments/start-here.md) use feature flags, the code for running an experiment is very similar to the feature flags code. See [adding experiment code](/docs/experiments/adding-experiment-code.md) for React Native examples.
|
|
1047
|
+
Since [experiments](https://posthog.com/docs/experiments/start-here.md) use feature flags, the code for running an experiment is very similar to the feature flags code. See [adding experiment code](https://posthog.com/docs/experiments/adding-experiment-code.md) for React Native examples.
|
|
1130
1048
|
|
|
1131
|
-
It's also possible to [run experiments without using feature flags](/docs/experiments/running-experiments-without-feature-flags.md).
|
|
1049
|
+
It's also possible to [run experiments without using feature flags](https://posthog.com/docs/experiments/running-experiments-without-feature-flags.md).
|
|
1132
1050
|
|
|
1133
1051
|
## Group analytics
|
|
1134
1052
|
|
|
1135
|
-
Group analytics allows you to associate the events for that person's session with a group (e.g. teams, organizations, etc.). See [Group Analytics](/docs/product-analytics/group-analytics.md) for implementation details.
|
|
1053
|
+
Group analytics allows you to associate the events for that person's session with a group (e.g. teams, organizations, etc.). See [Group Analytics](https://posthog.com/docs/product-analytics/group-analytics.md) for implementation details.
|
|
1136
1054
|
|
|
1137
|
-
> **Note:** This is a paid feature and is not available on the open-source or free cloud plan. Learn more on the [pricing page](/pricing.md).
|
|
1055
|
+
> **Note:** This is a paid feature and is not available on the open-source or free cloud plan. Learn more on the [pricing page](https://posthog.com/pricing.md).
|
|
1138
1056
|
|
|
1139
1057
|
## Error tracking
|
|
1140
1058
|
|
|
1141
|
-
To set up error tracking in your project, see the [error tracking docs](/docs/error-tracking.md).
|
|
1059
|
+
To set up error tracking in your project, see the [error tracking docs](https://posthog.com/docs/error-tracking.md).
|
|
1142
1060
|
|
|
1143
1061
|
### Native crash autocapture
|
|
1144
1062
|
|
|
1145
|
-
|
|
1063
|
+
JavaScript autocapture only covers exceptions thrown in your JS/TS code. To capture crashes in native code – a native module, the React Native runtime, or a C/C++ library – install the optional `@posthog/react-native-plugin` package and enable one or both of these options. What each option covers depends on the platform:
|
|
1064
|
+
|
|
1065
|
+
| Option | iOS | Android |
|
|
1066
|
+
| --- | --- | --- |
|
|
1067
|
+
| `nativeCrashes` | Every native crash: uncaught Objective-C exceptions, Mach exceptions, and signals such as `SIGSEGV` and `SIGABRT`, including crashes in C/C++ code | Java/Kotlin crashes only |
|
|
1068
|
+
| `androidNdkCrashes` | Ignored | C/C++ (NDK) crashes, on Android 12 (API 31) or later. Requires `posthog-react-native` 4.78.0 and `@posthog/react-native-plugin` 2.12.0 or later |
|
|
1069
|
+
|
|
1070
|
+
To capture every native crash on both platforms, enable both:
|
|
1146
1071
|
|
|
1147
|
-
|
|
1072
|
+
```jsx
|
|
1073
|
+
const posthog = new PostHog('<ph_project_token>', {
|
|
1074
|
+
host: 'https://us.i.posthog.com',
|
|
1075
|
+
errorTracking: {
|
|
1076
|
+
autocapture: {
|
|
1077
|
+
nativeCrashes: true,
|
|
1078
|
+
androidNdkCrashes: true,
|
|
1079
|
+
},
|
|
1080
|
+
},
|
|
1081
|
+
})
|
|
1082
|
+
```
|
|
1083
|
+
|
|
1084
|
+
Native capture is gated by your project's **Enable exception autocapture** setting, and crash reports need native debug symbols uploaded at build time to produce readable stack traces.
|
|
1085
|
+
|
|
1086
|
+
An Android NDK crash kills the process immediately, so PostHog captures it on the next app launch from the records the OS kept. Properties such as `$app_version` and the identity describe that launch, not the crash. The first launch after you enable `androidNdkCrashes` also captures NDK crashes the OS still holds from before.
|
|
1087
|
+
|
|
1088
|
+
Follow the [React Native installation guide](https://posthog.com/docs/error-tracking/installation/react-native.md) for the full setup, and [native crash symbolication](https://posthog.com/docs/error-tracking/upload-source-maps/react-native.md#native-crash-symbolication) to upload symbols.
|
|
1148
1089
|
|
|
1149
1090
|
### Error boundaries
|
|
1150
1091
|
|
|
1151
1092
|
You can use the `PostHogErrorBoundary` component to capture React rendering errors thrown by components:
|
|
1152
1093
|
|
|
1153
|
-
React Native
|
|
1154
|
-
|
|
1155
1094
|
```jsx
|
|
1156
1095
|
import { PostHogProvider, PostHogErrorBoundary } from 'posthog-react-native'
|
|
1157
1096
|
import { View, Text } from 'react-native'
|
|
@@ -1194,8 +1133,6 @@ You can use the `before_send` callback to modify, filter, or suppress exception
|
|
|
1194
1133
|
- Suppressing specific types of exceptions
|
|
1195
1134
|
- Redacting sensitive information
|
|
1196
1135
|
|
|
1197
|
-
React Native
|
|
1198
|
-
|
|
1199
1136
|
```jsx
|
|
1200
1137
|
const posthog = new PostHog('<ph_project_token>', {
|
|
1201
1138
|
host: 'https://us.i.posthog.com',
|
|
@@ -1222,27 +1159,27 @@ const posthog = new PostHog('<ph_project_token>', {
|
|
|
1222
1159
|
})
|
|
1223
1160
|
```
|
|
1224
1161
|
|
|
1225
|
-
You can also use `before_send` to sample or filter other event types. See the [JavaScript Web SDK documentation](/docs/libraries/js/usage.md#amending-or-sampling-events) for more examples.
|
|
1162
|
+
You can also use `before_send` to sample or filter other event types. See the [JavaScript Web SDK documentation](https://posthog.com/docs/libraries/js/usage.md#amending-or-sampling-events) for more examples.
|
|
1226
1163
|
|
|
1227
1164
|
## Logs
|
|
1228
1165
|
|
|
1229
|
-
To set up [logs](/docs/logs.md) in your React Native app, follow the [React Native logs installation guide](/docs/logs/installation/react-native.md). The SDK exposes `posthog.captureLog`, `posthog.logger.{trace,debug,info,warn,error,fatal}`, and `posthog.flushLogs` for sending structured records to PostHog Logs.
|
|
1166
|
+
To set up [logs](https://posthog.com/docs/logs.md) in your React Native app, follow the [React Native logs installation guide](https://posthog.com/docs/logs/installation/react-native.md). The SDK exposes `posthog.captureLog`, `posthog.logger.{trace,debug,info,warn,error,fatal}`, and `posthog.flushLogs` for sending structured records to PostHog Logs.
|
|
1230
1167
|
|
|
1231
1168
|
> **Minimum version:** `posthog-react-native@4.44.0` or later.
|
|
1232
1169
|
|
|
1233
1170
|
## Session replay
|
|
1234
1171
|
|
|
1235
|
-
To set up [session replay](/docs/session-replay/mobile.md) in your project, all you need to do is install the React Native SDK and the Session replay plugin, then follow the [instructions to enable Session Replay](/docs/session-replay/installation/react-native.md) for React Native.
|
|
1172
|
+
To set up [session replay](https://posthog.com/docs/session-replay/mobile.md) in your project, all you need to do is install the React Native SDK and the Session replay plugin, then follow the [instructions to enable Session Replay](https://posthog.com/docs/session-replay/installation/react-native.md) for React Native.
|
|
1236
1173
|
|
|
1237
1174
|
## Surveys
|
|
1238
1175
|
|
|
1239
|
-
To set up surveys, follow the [additional installation instructions for React Native](/docs/surveys/installation/react-native.md). Surveys launched with [popover presentation](/docs/surveys/creating-surveys.md#presentation) are automatically shown to users matching the [display conditions](/docs/surveys/creating-surveys.md#display-conditions) you set up.
|
|
1176
|
+
To set up surveys, follow the [additional installation instructions for React Native](https://posthog.com/docs/surveys/installation/react-native.md). Surveys launched with [popover presentation](https://posthog.com/docs/surveys/creating-surveys.md#presentation) are automatically shown to users matching the [display conditions](https://posthog.com/docs/surveys/creating-surveys.md#display-conditions) you set up.
|
|
1240
1177
|
|
|
1241
1178
|
> Note: URL and CSS selector targeting are not supported in React Native. Surveys that rely on these conditions will not appear.
|
|
1242
1179
|
|
|
1243
1180
|
## Push notifications
|
|
1244
1181
|
|
|
1245
|
-
The React Native SDK can register a device for [Workflows](/docs/workflows.md) push notifications and capture when a user opens one. For setup, including automatic and manual registration, capturing opens, opting out, and identity verification, see [Push notifications](/docs/workflows/push-notifications.md).
|
|
1182
|
+
The React Native SDK can register a device for [Workflows](https://posthog.com/docs/workflows.md) push notifications and capture when a user opens one. For setup, including automatic and manual registration, capturing opens, opting out, and identity verification, see [Push notifications](https://posthog.com/docs/workflows/push-notifications.md).
|
|
1246
1183
|
|
|
1247
1184
|
## Debug mode
|
|
1248
1185
|
|
|
@@ -1250,8 +1187,6 @@ If you're not seeing the expected events being captured, the feature flags being
|
|
|
1250
1187
|
|
|
1251
1188
|
You can enable debug mode by setting the `debug` option to `true` in the `PostHogProvider` options. This will enable verbose logs about the inner workings of the SDK.
|
|
1252
1189
|
|
|
1253
|
-
React Native
|
|
1254
|
-
|
|
1255
1190
|
```jsx
|
|
1256
1191
|
<PostHogProvider
|
|
1257
1192
|
debug={true}
|
|
@@ -1264,8 +1199,6 @@ React Native
|
|
|
1264
1199
|
|
|
1265
1200
|
You can also call the `debug()` method in your code.
|
|
1266
1201
|
|
|
1267
|
-
React Native
|
|
1268
|
-
|
|
1269
1202
|
```jsx
|
|
1270
1203
|
posthog.debug()
|
|
1271
1204
|
```
|
|
@@ -1274,8 +1207,6 @@ posthog.debug()
|
|
|
1274
1207
|
|
|
1275
1208
|
You may want to disable PostHog when working locally or in a test environment. You can do this by setting the `disable` option to `true` when initializing PostHog. Helpfully this allows you to continue using `usePostHog` and safely calling it without anything actually happening.
|
|
1276
1209
|
|
|
1277
|
-
React Native
|
|
1278
|
-
|
|
1279
1210
|
```jsx
|
|
1280
1211
|
// App.(js|ts)
|
|
1281
1212
|
import { usePostHog, PostHogProvider } from 'posthog-react-native'
|
|
@@ -1312,8 +1243,6 @@ For Android, it is unfortunately not possible for persisted Android data to be l
|
|
|
1312
1243
|
|
|
1313
1244
|
Events such as `Application Installed` and `Application Updated` that require previously persisted data were unable to be migrated, the side effect being that you may see much higher numbers for `Application Installed` events. This is due to the fact that there is no native way of detecting a real "install" and as such, we store a marker the first time the SDK loads and treat that as an install.
|
|
1314
1245
|
|
|
1315
|
-
JSX
|
|
1316
|
-
|
|
1317
1246
|
```jsx
|
|
1318
1247
|
// DEPRECATED V1 Setup
|
|
1319
1248
|
|
|
@@ -1372,11 +1301,3 @@ const posthog = new PostHog('<ph_project_token>', {
|
|
|
1372
1301
|
posthog.setPersonPropertiesForFlags(...) // instead of `personProperties`
|
|
1373
1302
|
posthog.setGroupPropertiesForFlags(...) // instead of `groupProperties`
|
|
1374
1303
|
```
|
|
1375
|
-
|
|
1376
|
-
### Still have questions?
|
|
1377
|
-
|
|
1378
|
-
Ask PostHog AI
|
|
1379
|
-
|
|
1380
|
-
### Was this page useful?
|
|
1381
|
-
|
|
1382
|
-
HelpfulCould be better
|