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,12 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
# iOS SDK usage
|
|
4
4
|
|
|
5
|
+
Canonical URL: https://posthog.com/docs/libraries/ios/usage
|
|
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
|
+
- [Capturing events](#capturing-events)
|
|
12
|
+
- [Autocapture](#autocapture)
|
|
13
|
+
- [Preventing sensitive data capture](#preventing-sensitive-data-capture)
|
|
14
|
+
- [Identifying users](#identifying-users)
|
|
15
|
+
- [Get the current user's distinct ID](#get-the-current-users-distinct-id)
|
|
16
|
+
- [Alias](#alias)
|
|
17
|
+
- [Anonymous vs identified events](#anonymous-vs-identified-events)
|
|
18
|
+
- [Setting person properties](#setting-person-properties)
|
|
19
|
+
- [Super properties](#super-properties)
|
|
20
|
+
- [Reset after logout](#reset-after-logout)
|
|
21
|
+
- [Group analytics](#group-analytics)
|
|
22
|
+
- [Opt out of data capture](#opt-out-of-data-capture)
|
|
23
|
+
- [Feature flags](#feature-flags)
|
|
24
|
+
- [Experiments (A/B tests)](#experiments-ab-tests)
|
|
25
|
+
- [A note about IDFA (identifier for advertisers) collection in iOS 14](#a-note-about-idfa-identifier-for-advertisers-collection-in-ios-14)
|
|
26
|
+
- [Session replay](#session-replay)
|
|
27
|
+
- [Surveys](#surveys)
|
|
28
|
+
- [Error tracking](#error-tracking)
|
|
29
|
+
- [Debug mode](#debug-mode)
|
|
30
|
+
|
|
5
31
|
## Capturing events
|
|
6
32
|
|
|
7
33
|
You can send custom events using `capture`:
|
|
8
34
|
|
|
9
|
-
Swift
|
|
10
|
-
|
|
11
35
|
```swift
|
|
12
36
|
PostHogSDK.shared.capture("user_signed_up")
|
|
13
37
|
```
|
|
@@ -16,9 +40,7 @@ PostHogSDK.shared.capture("user_signed_up")
|
|
|
16
40
|
|
|
17
41
|
### Setting event properties
|
|
18
42
|
|
|
19
|
-
Optionally, you can include additional information with the event by including a [properties](/docs/data/events.md#event-properties) object:
|
|
20
|
-
|
|
21
|
-
Swift
|
|
43
|
+
Optionally, you can include additional information with the event by including a [properties](https://posthog.com/docs/data/events.md#event-properties) object:
|
|
22
44
|
|
|
23
45
|
```swift
|
|
24
46
|
PostHogSDK.shared.capture("user_signed_up", properties: ["login_type": "email"], userProperties: ["is_free_trial": true])
|
|
@@ -40,19 +62,17 @@ PostHog autocapture automatically tracks the following events for you:
|
|
|
40
62
|
|
|
41
63
|
### Capturing screen views
|
|
42
64
|
|
|
43
|
-
With [`configuration.captureScreenViews`](/docs/libraries/ios/configuration.md#all-configuration-options) set as `true`, PostHog will try to record all screen changes automatically.
|
|
65
|
+
With [`configuration.captureScreenViews`](https://posthog.com/docs/libraries/ios/configuration.md#all-configuration-options) set as `true`, PostHog will try to record all screen changes automatically.
|
|
44
66
|
|
|
45
67
|
If you want to manually send a new screen capture event, use the `screen` function.
|
|
46
68
|
|
|
47
|
-
Swift
|
|
48
|
-
|
|
49
69
|
```swift
|
|
50
70
|
PostHogSDK.shared.screen("Dashboard", properties: ["fromIcon": "bottom"])
|
|
51
71
|
```
|
|
52
72
|
|
|
53
73
|
> **Important:** While `captureScreenViews` works with both `UIKit` and `SwiftUI`, the screen names captured in `SwiftUI` may not be very meaningful as they are based on internal SwiftUI view identifiers. For `SwiftUI` applications, we recommend turning this option off and instead using the `.postHogScreenView()` view modifier (see next section) to capture screen views with meaningful names.
|
|
54
74
|
|
|
55
|
-
> **Note:** You can use the `BeforeSendBlock` to filter or drop any undesired screen events, giving you control over which screen views are sent to PostHog. See [Amending, dropping or sampling events](/docs/libraries/ios.md#amending-dropping-or-sampling-events) for implementation examples.
|
|
75
|
+
> **Note:** You can use the `BeforeSendBlock` to filter or drop any undesired screen events, giving you control over which screen views are sent to PostHog. See [Amending, dropping or sampling events](https://posthog.com/docs/libraries/ios.md#amending-dropping-or-sampling-events) for implementation examples.
|
|
56
76
|
|
|
57
77
|
### Capturing screen views in SwiftUI
|
|
58
78
|
|
|
@@ -90,8 +110,6 @@ While this provides basic tracking, it can be challenging to pinpoint specific i
|
|
|
90
110
|
|
|
91
111
|
To assign a custom label to a UIView, use the `postHogLabel` property:
|
|
92
112
|
|
|
93
|
-
Swift
|
|
94
|
-
|
|
95
113
|
```swift
|
|
96
114
|
let view = UIView()
|
|
97
115
|
view.postHogLabel = "usernameTextField"
|
|
@@ -103,8 +121,6 @@ In this example, interactions with the UITextField will be captured with an addi
|
|
|
103
121
|
|
|
104
122
|
In SwiftUI, use the `.postHogLabel(_:)` modifier instead:
|
|
105
123
|
|
|
106
|
-
Swift
|
|
107
|
-
|
|
108
124
|
```swift
|
|
109
125
|
var body: some View {
|
|
110
126
|
...
|
|
@@ -119,8 +135,6 @@ Since SwiftUI's `TextField` uses `UITextField` under the hood, interactions with
|
|
|
119
135
|
|
|
120
136
|
The generated analytics element in the examples above will have the following form:
|
|
121
137
|
|
|
122
|
-
Swift
|
|
123
|
-
|
|
124
138
|
```swift
|
|
125
139
|
<UITextField id="usernameTextField">text value</UITextField>
|
|
126
140
|
```
|
|
@@ -144,8 +158,6 @@ Interaction autocapture records when users interact with UI elements in your app
|
|
|
144
158
|
|
|
145
159
|
Interaction autocapture is **not enabled by default**. You can enable it by setting `captureElementInteractions` to `true` in the config.
|
|
146
160
|
|
|
147
|
-
Swift
|
|
148
|
-
|
|
149
161
|
```swift
|
|
150
162
|
let config = PostHogConfig(projectToken: "<ph_project_token>", host: "https://us.i.posthog.com")
|
|
151
163
|
config.captureElementInteractions = true // Disabled by default
|
|
@@ -162,8 +174,6 @@ This is captured as a `$rageclick` event. You can use this event to identify opp
|
|
|
162
174
|
|
|
163
175
|
It is enabled by default (`rageClickConfig.enabled = true`).
|
|
164
176
|
|
|
165
|
-
Swift
|
|
166
|
-
|
|
167
177
|
```swift
|
|
168
178
|
let config = PostHogConfig(projectToken: "<ph_project_token>", host: "https://us.i.posthog.com")
|
|
169
179
|
config.rageClickConfig.enabled = true // Enabled by default
|
|
@@ -175,15 +185,15 @@ PostHogSDK.shared.setup(config)
|
|
|
175
185
|
|
|
176
186
|
### Autocapture configuration
|
|
177
187
|
|
|
178
|
-
You can enable or disable autocapture through the `PostHogConfig` object. Find more details about autocapture configuration in the [configuration page](/docs/libraries/ios/configuration.md#autocapture-configuration).
|
|
188
|
+
You can enable or disable autocapture through the `PostHogConfig` object. Find more details about autocapture configuration in the [configuration page](https://posthog.com/docs/libraries/ios/configuration.md#autocapture-configuration).
|
|
179
189
|
|
|
180
190
|
## Preventing sensitive data capture
|
|
181
191
|
|
|
182
|
-
To exclude specific UI elements from autocapture or Session Replay, add `ph-no-capture` as either an `accessibilityLabel` or `accessibilityIdentifier`. See [privacy controls](/docs/session-replay/privacy?tab=iOS.md) for masking behavior and iOS examples.
|
|
192
|
+
To exclude specific UI elements from autocapture or Session Replay, add `ph-no-capture` as either an `accessibilityLabel` or `accessibilityIdentifier`. See [privacy controls](https://posthog.com/docs/session-replay/privacy?tab=iOS.md) for masking behavior and iOS examples.
|
|
183
193
|
|
|
184
194
|
## Identifying users
|
|
185
195
|
|
|
186
|
-
> We highly recommend reading our section on [Identifying users](/docs/integrate/identifying-users.md) to better understand how to correctly use this method.
|
|
196
|
+
> 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.
|
|
187
197
|
|
|
188
198
|
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.
|
|
189
199
|
|
|
@@ -191,10 +201,8 @@ An `identify` call has the following arguments:
|
|
|
191
201
|
|
|
192
202
|
- `distinct_id` which uniquely identifies your user in your database
|
|
193
203
|
|
|
194
|
-
- **userProperties:** Optional. A dictionary with key:value pairs to set the [person properties](/docs/product-analytics/person-properties.md)
|
|
195
|
-
- **userPropertiesSetOnce:** Optional. Similar to `userProperties`. [See the difference between `userProperties` and `userPropertiesSetOnce`](/docs/product-analytics/person-properties.md#what-is-the-difference-between-set-and-set_once)
|
|
196
|
-
|
|
197
|
-
Swift
|
|
204
|
+
- **userProperties:** Optional. A dictionary with key:value pairs to set the [person properties](https://posthog.com/docs/product-analytics/person-properties.md)
|
|
205
|
+
- **userPropertiesSetOnce:** Optional. Similar to `userProperties`. [See the difference between `userProperties` and `userPropertiesSetOnce`](https://posthog.com/docs/product-analytics/person-properties.md#what-is-the-difference-between-set-and-set_once)
|
|
198
206
|
|
|
199
207
|
```swift
|
|
200
208
|
PostHogSDK.shared.identify("user_id_from_your_database",
|
|
@@ -218,19 +226,17 @@ Sometimes, you want to assign multiple distinct IDs to a single user. This is he
|
|
|
218
226
|
|
|
219
227
|
In this case, you can use `alias` to assign another distinct ID to the same user.
|
|
220
228
|
|
|
221
|
-
Swift
|
|
222
|
-
|
|
223
229
|
```swift
|
|
224
230
|
PostHogSDK.shared.alias("alias_id")
|
|
225
231
|
```
|
|
226
232
|
|
|
227
|
-
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.
|
|
233
|
+
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.
|
|
228
234
|
|
|
229
235
|
## Anonymous vs identified events
|
|
230
236
|
|
|
231
|
-
PostHog captures two types of events: [**anonymous** and **identified**](/docs/data/anonymous-vs-identified-events.md)
|
|
237
|
+
PostHog captures two types of events: [**anonymous** and **identified**](https://posthog.com/docs/data/anonymous-vs-identified-events.md)
|
|
232
238
|
|
|
233
|
-
**Identified events** enable you to attribute events to specific users, and attach [person properties](/docs/product-analytics/person-properties.md). They're best suited for logged-in users.
|
|
239
|
+
**Identified events** enable you to attribute events to specific users, and attach [person properties](https://posthog.com/docs/product-analytics/person-properties.md). They're best suited for logged-in users.
|
|
234
240
|
|
|
235
241
|
Scenarios where you want to capture identified events are:
|
|
236
242
|
|
|
@@ -238,7 +244,7 @@ Scenarios where you want to capture identified events are:
|
|
|
238
244
|
- Doing user segmented product analysis
|
|
239
245
|
- Growth and marketing teams wanting to analyze the *complete* conversion lifecycle
|
|
240
246
|
|
|
241
|
-
**Anonymous events** are events without individually identifiable data. They're best suited for [web analytics](/docs/web-analytics.md) or apps where users aren't logged in.
|
|
247
|
+
**Anonymous events** are events without individually identifiable data. They're best suited for [web analytics](https://posthog.com/docs/web-analytics.md) or apps where users aren't logged in.
|
|
242
248
|
|
|
243
249
|
Scenarios where you want to capture anonymous events are:
|
|
244
250
|
|
|
@@ -246,15 +252,15 @@ Scenarios where you want to capture anonymous events are:
|
|
|
246
252
|
- Content-focused sites
|
|
247
253
|
- B2C apps where users don't sign up or log in
|
|
248
254
|
|
|
249
|
-
Under the hood, the key difference between identified and anonymous events is that for identified events we create a [person profile](/docs/data/persons.md) for the user, whereas for anonymous events we do not.
|
|
255
|
+
Under the hood, the key difference between identified and anonymous events is that for identified events we create a [person profile](https://posthog.com/docs/data/persons.md) for the user, whereas for anonymous events we do not.
|
|
250
256
|
|
|
251
257
|
> **Important:** Due to the reduced cost of processing them, anonymous events can be up to 4x cheaper than identified ones, so we recommended you only capture identified events when needed.
|
|
252
258
|
|
|
253
259
|
### How to capture anonymous events
|
|
254
260
|
|
|
255
|
-
The iOS SDK captures anonymous events by default. However, this may change depending on your `personProfiles` [config](/docs/libraries/ios/configuration.md#all-configuration-options) when initializing PostHog:
|
|
261
|
+
The iOS SDK captures anonymous events by default. However, this may change depending on your `personProfiles` [config](https://posthog.com/docs/libraries/ios/configuration.md#all-configuration-options) when initializing PostHog:
|
|
256
262
|
|
|
257
|
-
1. `personProfiles: .identifiedOnly` *(recommended)* *(default)* - Anonymous events are captured by default. PostHog only captures identified events for users where [person profiles](/docs/data/persons.md) have already been created.
|
|
263
|
+
1. `personProfiles: .identifiedOnly` *(recommended)* *(default)* - Anonymous events are captured by default. PostHog only captures identified events for users where [person profiles](https://posthog.com/docs/data/persons.md) have already been created.
|
|
258
264
|
|
|
259
265
|
2. `personProfiles: .always` - Capture identified events for all events.
|
|
260
266
|
|
|
@@ -262,8 +268,6 @@ The iOS SDK captures anonymous events by default. However, this may change depen
|
|
|
262
268
|
|
|
263
269
|
For example:
|
|
264
270
|
|
|
265
|
-
iOS
|
|
266
|
-
|
|
267
271
|
```swift
|
|
268
272
|
let config = PostHogConfig(
|
|
269
273
|
projectToken: POSTHOG_PROJECT_TOKEN,
|
|
@@ -275,40 +279,34 @@ PostHogSDK.shared.setup(config)
|
|
|
275
279
|
|
|
276
280
|
### How to capture identified events
|
|
277
281
|
|
|
278
|
-
If you've set the [`personProfiles` config](/docs/libraries/ios/configuration.md#all-configuration-options) to `.identifiedOnly` (the default option), anonymous events are captured by default. Then, to capture identified events, call any of the following functions:
|
|
282
|
+
If you've set the [`personProfiles` config](https://posthog.com/docs/libraries/ios/configuration.md#all-configuration-options) to `.identifiedOnly` (the default option), anonymous events are captured by default. Then, to capture identified events, call any of the following functions:
|
|
279
283
|
|
|
280
|
-
- [`identify()`](/docs/product-analytics/identify.md)
|
|
281
|
-
- [`alias()`](/docs/product-analytics/identify.md#alias-assigning-multiple-distinct-ids-to-the-same-user)
|
|
282
|
-
- [`group()`](/docs/product-analytics/group-analytics.md)
|
|
284
|
+
- [`identify()`](https://posthog.com/docs/product-analytics/identify.md)
|
|
285
|
+
- [`alias()`](https://posthog.com/docs/product-analytics/identify.md#alias-assigning-multiple-distinct-ids-to-the-same-user)
|
|
286
|
+
- [`group()`](https://posthog.com/docs/product-analytics/group-analytics.md)
|
|
283
287
|
|
|
284
|
-
When you call any of these functions, it creates a [person profile](/docs/data/persons.md) for the user. Once this profile is created, all subsequent events for this user will be captured as identified events.
|
|
288
|
+
When you call any of these functions, it creates a [person profile](https://posthog.com/docs/data/persons.md) for the user. Once this profile is created, all subsequent events for this user will be captured as identified events.
|
|
285
289
|
|
|
286
290
|
Alternatively, you can set `personProfiles` to `.always` to capture identified events by default.
|
|
287
291
|
|
|
288
292
|
## Setting person properties
|
|
289
293
|
|
|
290
|
-
To set [properties](/docs/product-analytics/person-properties.md) on your users via an event, you can leverage the event properties `userProperties` and `userPropertiesSetOnce`.
|
|
294
|
+
To set [properties](https://posthog.com/docs/product-analytics/person-properties.md) on your users via an event, you can leverage the event properties `userProperties` and `userPropertiesSetOnce`.
|
|
291
295
|
|
|
292
296
|
When capturing an event, you can pass a property called `$set` as an event property, and specify its value to be an object with properties to be set on the user that will be associated with the user who triggered the event.
|
|
293
297
|
|
|
294
|
-
Swift
|
|
295
|
-
|
|
296
298
|
```swift
|
|
297
299
|
PostHogSDK.shared.capture("signed_up", properties: ["plan": "Pro++"], userProperties: ["user_property_name": "your_value"])
|
|
298
300
|
```
|
|
299
301
|
|
|
300
302
|
`userPropertiesSetOnce` works just like `userProperties`, except that it will **only set the property if the user doesn't already have that property set**.
|
|
301
303
|
|
|
302
|
-
Swift
|
|
303
|
-
|
|
304
304
|
```swift
|
|
305
305
|
PostHogSDK.shared.capture("signed_up", properties: ["plan": "Pro++"], userPropertiesSetOnce: ["user_property_name": "your_value"])
|
|
306
306
|
```
|
|
307
307
|
|
|
308
308
|
Use `setPersonProperties` when you want to update the current person's profile without also capturing a custom event. This sends a `$set` event to PostHog.
|
|
309
309
|
|
|
310
|
-
Swift
|
|
311
|
-
|
|
312
310
|
```swift
|
|
313
311
|
PostHogSDK.shared.setPersonProperties(userPropertiesToSet: ["plan": "Pro++"])
|
|
314
312
|
|
|
@@ -326,8 +324,6 @@ They are set using `PostHogSDK.shared.register`, which takes a properties object
|
|
|
326
324
|
|
|
327
325
|
For example, take a look at the following call:
|
|
328
326
|
|
|
329
|
-
Swift
|
|
330
|
-
|
|
331
327
|
```swift
|
|
332
328
|
PostHogSDK.shared.register(["team_id": 22])
|
|
333
329
|
```
|
|
@@ -340,8 +336,6 @@ However, please note that this does not store properties against the User, only
|
|
|
340
336
|
|
|
341
337
|
Super properties persist across sessions so you have to explicitly remove them if they are no longer relevant. To stop sending a super property with events, you can use `PostHogSDK.shared.unregister`, like so:
|
|
342
338
|
|
|
343
|
-
Swift
|
|
344
|
-
|
|
345
339
|
```swift
|
|
346
340
|
PostHogSDK.shared.unregister("team_id")
|
|
347
341
|
```
|
|
@@ -352,26 +346,24 @@ If you are doing this as part of a user logging out, you can instead simply use
|
|
|
352
346
|
|
|
353
347
|
## Reset after logout
|
|
354
348
|
|
|
355
|
-
To reset the user's ID and anonymous ID after logout, call `reset`. See [Identifying users](/docs/product-analytics/identify.md#reset) for the shared reset guidance and iOS example.
|
|
349
|
+
To reset the user's ID and anonymous ID after logout, call `reset`. See [Identifying users](https://posthog.com/docs/product-analytics/identify.md#reset) for the shared reset guidance and iOS example.
|
|
356
350
|
|
|
357
351
|
## Group analytics
|
|
358
352
|
|
|
359
|
-
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 iOS examples and implementation details.
|
|
353
|
+
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 iOS examples and implementation details.
|
|
360
354
|
|
|
361
|
-
> **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).
|
|
355
|
+
> **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).
|
|
362
356
|
|
|
363
357
|
## Opt out of data capture
|
|
364
358
|
|
|
365
|
-
You can completely opt users out from data capture by default or on a per-person basis. See [Complete opt-out](/docs/product-analytics/privacy.md#complete-opt-out) for iOS examples.
|
|
359
|
+
You can completely opt users out from data capture by default or on a per-person basis. See [Complete opt-out](https://posthog.com/docs/product-analytics/privacy.md#complete-opt-out) for iOS examples.
|
|
366
360
|
|
|
367
361
|
## Feature flags
|
|
368
362
|
|
|
369
|
-
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.
|
|
363
|
+
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.
|
|
370
364
|
|
|
371
365
|
### Boolean feature flags
|
|
372
366
|
|
|
373
|
-
Swift
|
|
374
|
-
|
|
375
367
|
```swift
|
|
376
368
|
if let result = PostHogSDK.shared.getFeatureFlagResult("flag-key"), result.enabled {
|
|
377
369
|
// Do something differently for this user
|
|
@@ -383,8 +375,6 @@ if let result = PostHogSDK.shared.getFeatureFlagResult("flag-key"), result.enabl
|
|
|
383
375
|
|
|
384
376
|
### Multivariate feature flags
|
|
385
377
|
|
|
386
|
-
Swift
|
|
387
|
-
|
|
388
378
|
```swift
|
|
389
379
|
if let result = PostHogSDK.shared.getFeatureFlagResult("flag-key"), result.variant == "variant-key" { // replace "variant-key" with the key of your variant
|
|
390
380
|
// Do something differently for this user
|
|
@@ -398,8 +388,6 @@ if let result = PostHogSDK.shared.getFeatureFlagResult("flag-key"), result.varia
|
|
|
398
388
|
|
|
399
389
|
If your payload is a JSON object, you can decode it into a `Decodable` type:
|
|
400
390
|
|
|
401
|
-
Swift
|
|
402
|
-
|
|
403
391
|
```swift
|
|
404
392
|
struct FlagPayload: Decodable {
|
|
405
393
|
let title: String
|
|
@@ -415,8 +403,6 @@ if let result = PostHogSDK.shared.getFeatureFlagResult("flag-key"),
|
|
|
415
403
|
|
|
416
404
|
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:
|
|
417
405
|
|
|
418
|
-
Swift
|
|
419
|
-
|
|
420
406
|
```swift
|
|
421
407
|
for flag in PostHogSDK.shared.getAllFeatureFlags() ?? [] {
|
|
422
408
|
print(flag.key, flag.enabled, flag.variant as Any, flag.payload as Any)
|
|
@@ -427,8 +413,6 @@ for flag in PostHogSDK.shared.getAllFeatureFlags() ?? [] {
|
|
|
427
413
|
|
|
428
414
|
Feature flag values are cached. If something has changed with your user and you'd like to refetch their flag values, call:
|
|
429
415
|
|
|
430
|
-
Swift
|
|
431
|
-
|
|
432
416
|
```swift
|
|
433
417
|
PostHogSDK.shared.reloadFeatureFlags()
|
|
434
418
|
```
|
|
@@ -439,43 +423,55 @@ Every time a user opens the app, we send a request in the background to fetch th
|
|
|
439
423
|
|
|
440
424
|
This means that for most screens, the feature flags are available immediately – **except for the first time a user visits**.
|
|
441
425
|
|
|
442
|
-
To handle this, you can use the `
|
|
443
|
-
|
|
444
|
-
Swift
|
|
426
|
+
To handle this, you can use the `onFeatureFlags` callback to be notified when flags are loaded or change. It's available in version 3.89.0+:
|
|
445
427
|
|
|
446
428
|
```swift
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
//
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
429
|
+
let subscription = PostHogSDK.shared.onFeatureFlags { loaded in
|
|
430
|
+
if loaded.errorsLoading {
|
|
431
|
+
// Loading failed, so the flags are the last known values, which can be empty.
|
|
432
|
+
// Fall back to your default experience if you need fresh values.
|
|
433
|
+
return
|
|
434
|
+
}
|
|
435
|
+
if PostHogSDK.shared.isFeatureEnabled("flag-key") {
|
|
436
|
+
// do something
|
|
437
|
+
}
|
|
438
|
+
}
|
|
456
439
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
440
|
+
// Later, to stop receiving updates
|
|
441
|
+
subscription.unsubscribe()
|
|
442
|
+
```
|
|
460
443
|
|
|
461
|
-
|
|
444
|
+
The callback runs on the main thread. It's called when flags load – including from [bootstrap values](https://posthog.com/docs/feature-flags/bootstrapping.md) – and again each time they're reloaded, for example after `reloadFeatureFlags()`, `reset()`, or an `identify()` or `group()` call that changes the distinct ID or group. A reload doesn't have to change any values, so treat each call as "flags may have changed". If flags have already loaded when you register, it's called shortly afterwards with the current values. You can register before calling `setup()`.
|
|
462
445
|
|
|
463
|
-
|
|
446
|
+
#### Callback parameters
|
|
464
447
|
|
|
465
|
-
|
|
466
|
-
}
|
|
448
|
+
The callback receives a `PostHogFeatureFlagsLoaded` object with the following properties:
|
|
467
449
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
450
|
+
- `flags: [String]`: The keys of the enabled feature flags.
|
|
451
|
+
|
|
452
|
+
- `variants: [String: Any]`: The values of the enabled feature flags, keyed by flag key. A value is `true` for an enabled boolean flag, or the variant key for a multivariate flag.
|
|
453
|
+
|
|
454
|
+
- `errorsLoading: Bool`: `true` if the latest attempt to load feature flags failed, for example because the device is offline. The flags and variants then hold the last known values, which can be empty – for example, on a fresh install with no [bootstrap values](https://posthog.com/docs/feature-flags/bootstrapping.md). In that case, `isFeatureEnabled` returns `false` because the flag is unknown, not because PostHog evaluated it as disabled.
|
|
455
|
+
|
|
456
|
+
On versions earlier than 3.89.0, observe the `PostHogSDK.didReceiveFeatureFlags` notification instead. Register the observer before calling `setup()`:
|
|
457
|
+
|
|
458
|
+
```swift
|
|
459
|
+
let observer = NotificationCenter.default.addObserver(
|
|
460
|
+
forName: PostHogSDK.didReceiveFeatureFlags,
|
|
461
|
+
object: nil,
|
|
462
|
+
queue: .main
|
|
463
|
+
) { _ in
|
|
464
|
+
if PostHogSDK.shared.isFeatureEnabled("flag-key") {
|
|
465
|
+
// do something
|
|
471
466
|
}
|
|
472
467
|
}
|
|
468
|
+
|
|
469
|
+
// Later, to stop receiving updates
|
|
470
|
+
NotificationCenter.default.removeObserver(observer)
|
|
473
471
|
```
|
|
474
472
|
|
|
475
473
|
Alternatively, you can use the completion block of the `reloadFeatureFlags(_:)` method. This allows you to execute logic immediately after the flags are reloaded:
|
|
476
474
|
|
|
477
|
-
Swift
|
|
478
|
-
|
|
479
475
|
```swift
|
|
480
476
|
// Reload feature flags and check if a specific feature is enabled
|
|
481
477
|
PostHogSDK.shared.reloadFeatureFlags {
|
|
@@ -489,8 +485,6 @@ PostHogSDK.shared.reloadFeatureFlags {
|
|
|
489
485
|
|
|
490
486
|
To track when someone sees or interacts with a feature, use `captureFeatureView` and `captureFeatureInteraction`.
|
|
491
487
|
|
|
492
|
-
Swift
|
|
493
|
-
|
|
494
488
|
```swift
|
|
495
489
|
PostHogSDK.shared.captureFeatureView(flag: "flag-key", flagVariant: "variant-key")
|
|
496
490
|
PostHogSDK.shared.captureFeatureInteraction(flag: "flag-key", flagVariant: "variant-key")
|
|
@@ -504,8 +498,6 @@ To have your feature flags available immediately, you can initialize PostHog wit
|
|
|
504
498
|
|
|
505
499
|
Set `config.bootstrap` before calling `setup()` to seed identity and flag values before the first `/flags` response (requires iOS SDK `3.66.0`+):
|
|
506
500
|
|
|
507
|
-
Swift
|
|
508
|
-
|
|
509
501
|
```swift
|
|
510
502
|
let config = PostHogConfig(projectToken: "<ph_project_token>", host: "https://us.i.posthog.com")
|
|
511
503
|
config.bootstrap = PostHogBootstrapConfig(
|
|
@@ -527,13 +519,13 @@ PostHogSDK.shared.setup(config)
|
|
|
527
519
|
|
|
528
520
|
The feature-flags-loaded signal fires as soon as bootstrapped flags are applied, so startup logic can read them immediately. These SDKs don't support the `sessionID` bootstrap option. When person profiles are set to `never`, the SDK preserves a different anonymous identity instead of merging it into an identified bootstrap.
|
|
529
521
|
|
|
530
|
-
See the [SDK bootstrapping guide](/docs/libraries/bootstrapping.md) for the cross-SDK overview.
|
|
522
|
+
See the [SDK bootstrapping guide](https://posthog.com/docs/libraries/bootstrapping.md) for the cross-SDK overview.
|
|
531
523
|
|
|
532
524
|
## Experiments (A/B tests)
|
|
533
525
|
|
|
534
|
-
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 iOS examples.
|
|
526
|
+
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 iOS examples.
|
|
535
527
|
|
|
536
|
-
It's also possible to [run experiments without using feature flags](/docs/experiments/running-experiments-without-feature-flags.md).
|
|
528
|
+
It's also possible to [run experiments without using feature flags](https://posthog.com/docs/experiments/running-experiments-without-feature-flags.md).
|
|
537
529
|
|
|
538
530
|
## A note about IDFA (identifier for advertisers) collection in iOS 14
|
|
539
531
|
|
|
@@ -545,15 +537,15 @@ Hence **starting with posthog-ios version 1.2.0** we have removed all references
|
|
|
545
537
|
|
|
546
538
|
> **Note:** Session replay is currently only available on iOS. For future macOS support, please follow and upvote [this GitHub issue](https://github.com/PostHog/posthog-ios/issues/200).
|
|
547
539
|
|
|
548
|
-
To set up [session replay](/docs/session-replay/mobile.md) in your project, all you need to do is install the iOS SDK, enable "Record user sessions" in [your project settings](https://us.posthog.com/settings/project-replay) and enable the `sessionReplay` option.
|
|
540
|
+
To set up [session replay](https://posthog.com/docs/session-replay/mobile.md) in your project, all you need to do is install the iOS SDK, enable "Record user sessions" in [your project settings](https://us.posthog.com/settings/project-replay) and enable the `sessionReplay` option.
|
|
549
541
|
|
|
550
542
|
## Surveys
|
|
551
543
|
|
|
552
|
-
[Surveys](/docs/surveys.md) 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.
|
|
544
|
+
[Surveys](https://posthog.com/docs/surveys.md) 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.
|
|
553
545
|
|
|
554
546
|
## Error tracking
|
|
555
547
|
|
|
556
|
-
To set up error tracking in your project, see the [error tracking docs](/docs/error-tracking.md).
|
|
548
|
+
To set up error tracking in your project, see the [error tracking docs](https://posthog.com/docs/error-tracking.md).
|
|
557
549
|
|
|
558
550
|
## Debug mode
|
|
559
551
|
|
|
@@ -561,8 +553,6 @@ If you're not seeing the expected events being captured, the feature flags being
|
|
|
561
553
|
|
|
562
554
|
You can enable debug mode by setting the `debug` option to `true` in the `PostHogConfig` object. A common pattern is to set this to `true` in development environments only for local development.
|
|
563
555
|
|
|
564
|
-
Swift
|
|
565
|
-
|
|
566
556
|
```swift
|
|
567
557
|
let config = PostHogConfig(projectToken: "<ph_project_token>", host: "https://us.i.posthog.com")
|
|
568
558
|
config.debug = true
|
|
@@ -573,8 +563,6 @@ This will enable verbose logs about the inner workings of the SDK.
|
|
|
573
563
|
|
|
574
564
|
You can also toggle debug by calling the `PostHogSDK.shared.debug()` method in your code.
|
|
575
565
|
|
|
576
|
-
Swift
|
|
577
|
-
|
|
578
566
|
```swift
|
|
579
567
|
// Enable debug mode
|
|
580
568
|
PostHogSDK.shared.debug(true)
|
|
@@ -582,11 +570,3 @@ PostHogSDK.shared.debug(true)
|
|
|
582
570
|
// Disable debug mode
|
|
583
571
|
PostHogSDK.shared.debug(false)
|
|
584
572
|
```
|
|
585
|
-
|
|
586
|
-
### Still have questions?
|
|
587
|
-
|
|
588
|
-
Ask PostHog AI
|
|
589
|
-
|
|
590
|
-
### Was this page useful?
|
|
591
|
-
|
|
592
|
-
HelpfulCould be better
|