You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/connections/auto-instrumentation/swift-setup.md
+34-35Lines changed: 34 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ Segment recommends testing in a development environment before deploying Signals
25
25
26
26
## Prerequisites
27
27
28
-
Auto-Instrumentation (aka Signals) works on top of Analytics. Make sure to add the following dependency to your project if you don't have analytics-swift already.
28
+
Auto-Instrumentation (also known as Signals) works on top of Analytics. Make sure to add the following dependency to your project if you don't have analytics-swift already.
29
29
30
30
```swift
31
31
dependencies: [
@@ -42,11 +42,10 @@ dependencies: [
42
42
]
43
43
```
44
44
45
-
2. Import and initialize with your Analytics instance:
46
-
47
-
> success ""
48
-
> See [configuration options](#configuration-options) for a complete list.
49
-
>
45
+
2. Import and initialize with your Analytics instance:
46
+
> success ""
47
+
> See [configuration options](#configuration-options) for a complete list.
48
+
>
50
49
```swift
51
50
import Segment
52
51
import AnalyticsLive
@@ -75,14 +74,14 @@ dependencies: [
75
74
```
76
75
77
76
3. Set up capture for the UI framework(s) you're using:
78
-
* [Capture SwiftUI Interactions](#swiftui)
79
-
* [Capture UIKit Interactions](#uikit)
80
-
* [Capture Network Activity](#capture-network)
77
+
* [Capture SwiftUI interactions](#swiftui).
78
+
* [Capture UIKit interactions](#uikit).
79
+
* [Capture network activity](#capture-network).
81
80
82
81
83
82
## Step 2: Additional setup
84
83
85
-
### Capture Interactions
84
+
### Capture interactions
86
85
87
86
#### SwiftUI
88
87
@@ -119,25 +118,25 @@ SwiftUI automatic signal capture requires adding typealiases to your code. This
119
118
typealias List = SignalList
120
119
```
121
120
122
-
3. Use the controls normally in your SwiftUI code:
121
+
3. Use the controls in your SwiftUI code:
123
122
```swift
124
123
struct ContentView: View {
125
124
var body: some View {
126
125
NavigationStack {
127
126
VStack {
128
127
Button("Click Me") {
129
-
// Button tap will automatically generate a signal
128
+
// Button tap automatically generates a signal
130
129
}
131
130
132
131
TextField("Enter text", text: $text)
133
-
// Text changes will automatically generate signals
132
+
// Text changes automatically generates signals
134
133
}
135
134
}
136
135
}
137
136
}
138
137
```
139
138
140
-
>**Note:**The typealiases replace SwiftUI's native controls with signal-generating versions. Your code remains unchanged, but interactions are now automatically captured.
139
+
The typealiases replace SwiftUI's native controls with signal-generating versions. Your code remains unchanged, but interactions are now automatically captured.
141
140
142
141
#### UIKit
143
142
@@ -152,7 +151,7 @@ UIKit automatic signal capture uses method swizzling and requires no code change
152
151
))
153
152
```
154
153
155
-
2. That's it!The following UIKit interactions and navigation events are automatically captured via method swizzling:
154
+
2. The following UIKit interactions and navigation events are automatically captured via method swizzling:
156
155
157
156
**Interactions:**
158
157
- `UIButton` taps
@@ -167,16 +166,16 @@ UIKit automatic signal capture uses method swizzling and requires no code change
167
166
- `UIViewController` modal presentations and dismissals
168
167
- `UITabBarController` tab switches
169
168
170
-
### Capture Navigation
169
+
### Capture navigation
171
170
172
171
Navigation capture is handled automatically when you enable SwiftUI or UIKit auto-signals:
173
172
174
-
-**SwiftUI**: Captured through `SignalNavigationLink` and `SignalNavigationStack` when you add the typealiases
175
-
-**UIKit**: Captured automatically via `UINavigationController`, `UIViewController`, and `UITabBarController` swizzling
173
+
-**SwiftUI**: Captured through `SignalNavigationLink` and `SignalNavigationStack` when you add the typealiases.
174
+
-**UIKit**: Captured automatically via `UINavigationController`, `UIViewController`, and `UITabBarController` swizzling.
176
175
177
-
No additional setup required beyond enabling the appropriate auto-signal flags.
176
+
No additional setup isrequired beyond enabling the appropriate auto-signal flags.
178
177
179
-
### Capture Network
178
+
### Capture network
180
179
181
180
Network capture automatically tracks URLSession requests and responses.
2. Network requests made via URLSession are automatically captured, including:
195
-
- Request URL, method, headers, and body
196
-
- Response status, headers, and body
197
-
- Request/response correlation via request ID
194
+
- Request URL, method, headers, and body.
195
+
- Response status, headers, and body.
196
+
- Request or response correlation via request ID.
198
197
199
-
>**Note:**Third-party networking libraries that use URLSession underneath (like Alamofire) should work automatically. Segment API endpoints are automatically blocked to prevent recursive tracking.
198
+
Third-party networking libraries that use URLSession underneath (like Alamofire) should work automatically. Segment API endpoints are automatically blocked to prevent recursive tracking.
200
199
201
-
#### Configuring Network Hosts
200
+
#### Configuring network hosts
202
201
203
202
You can control which network requests are tracked:
204
203
@@ -226,7 +225,7 @@ The following hosts are automatically blocked to prevent recursive tracking:
226
225
227
226
By default, Signals stores captured data on the device and doesn't forward it to Segment. This process prevents unnecessary bandwidth use and helps support privacy compliance requirements.
228
227
229
-
To view captured signals in the Event Builder and create event generation rules, you need to enable `sendDebugSignalsToSegment`. This setting temporarily lets the SDK send signal data to Segment while you're testing.
228
+
To view captured signals in the Event Builder and create event generation rules, enable `sendDebugSignalsToSegment`. This setting temporarily lets the SDK send signal data to Segment while you're testing.
230
229
231
230
In addition, the SDK obfuscates signals sent to Segment by default. To view the completed data, you need to turn off `obfuscateDebugSignals`.
232
231
@@ -235,9 +234,9 @@ In addition, the SDK obfuscates signals sent to Segment by default. To view the
235
234
236
235
You can enable `sendDebugSignalsToSegment` and turn off `obfuscateDebugSignals` in one of three ways.
237
236
238
-
### Option 1: Use Build Configurations to Toggle Debug Mode
237
+
### Option 1: Use build configurations to toggle debug mode
239
238
240
-
1. Define different configurations in your project settings (Debug, Release, etc.)
239
+
1. Define different configurations in your project settings (for example, Debug or Release).
241
240
242
241
2. Use compiler flags to control the setting:
243
242
```swift
@@ -254,7 +253,7 @@ You can enable `sendDebugSignalsToSegment` and turn off `obfuscateDebugSignals`
254
253
))
255
254
```
256
255
257
-
### Option 2: Use a Feature Flag System
256
+
### Option 2: Use a Feature Flag system
258
257
If you're using Firebase Remote Config or a similar feature flag system, you can dynamically control `sendDebugSignalsToSegment` and `obfuscateDebugSignals` without requiring a new app build:
259
258
```swift
260
259
let remoteConfig = RemoteConfig.remoteConfig()
@@ -267,7 +266,7 @@ You can enable `sendDebugSignalsToSegment` and turn off `obfuscateDebugSignals`
267
266
))
268
267
```
269
268
270
-
### Option 3: Use Environment Variables (for debugging/testing)
269
+
### Option 3: Use environment variables (for debugging or testing)
271
270
You can check for environment variables or launch arguments during development:
272
271
```swift
273
272
let isDebugEnabled = ProcessInfo.processInfo.environment["SIGNALS_DEBUG"] !=nil
@@ -285,7 +284,7 @@ You can enable `sendDebugSignalsToSegment` and turn off `obfuscateDebugSignals`
285
284
Next, return to the source settings to turn on Auto-Instrumentation:
286
285
287
286
1. Go to **Connections > Sources**.
288
-
2. Select the source you used in Step 1.
287
+
2. Select the source you used in [Step 1](#Step-1-Getting-started).
289
288
3. From the source's overview tab, go to **Settings > Advanced**.
290
289
4. Toggle Auto-Instrumention on.
291
290
@@ -303,7 +302,7 @@ After integrating the SDK and running your app, verify that Segment is collectin
303
302
304
303
## Configuration options
305
304
306
-
Using the Signals Configuration object, you can control the destination, frequency, and types of signals that Segment automatically tracks within your application. The following table details the configuration options for Signals-Swift.
305
+
Using the Signals Configuration object, you can control the destination, frequency, and types of signals that Segment automatically tracks within your application. The following table details the configuration options for Signals-Swift:
307
306
308
307
309
308
| OPTION | REQUIRED | VALUE | DESCRIPTION |
@@ -312,15 +311,15 @@ Using the Signals Configuration object, you can control the destination, frequen
312
311
|**maximumBufferSize**| No | Int | The number of signals to be kept for JavaScript inspection. This buffer is first-in, first-out. Default is **1000**. |
313
312
|**relayCount**| No | Int | Relays every X signals to Segment. Default is **20**. |
314
313
|**relayInterval**| No | TimeInterval | Relays signals to Segment every X seconds. Default is **60**. |
315
-
|**broadcasters**| No |[SignalBroadcaster]| An array of broadcasters. These objects forward signal data to their destinations, like **WebhookBroadcaster**, or you could write your own **DebugBroadcaster** that writes logs to the developer console. **SegmentBroadcaster** is always added by the SDK when `sendDebugSignalsToSegment` is true. |
314
+
|**broadcasters**| No | SignalBroadcaster | An array of broadcasters. These objects forward signal data to their destinations, like **WebhookBroadcaster**, or you could write your own **DebugBroadcaster** that writes logs to the developer console. **SegmentBroadcaster** is always added by the SDK when `sendDebugSignalsToSegment` is true. |
316
315
|**sendDebugSignalsToSegment**| No | Bool | Turns on debug mode and allows the SDK to relay Signals to Segment server. Default is **false**. It should only be set to true for development purposes. |
317
316
|**obfuscateDebugSignals**| No | Bool | Obfuscates signals being relayed to Segment. Default is **true**. |
318
317
|**apiHost**| No | String | API host for signal relay. Default is **"signals.segment.io/v1"**. |
319
318
|**useUIKitAutoSignal**| No | Bool | Enables automatic UIKit signal capture via method swizzling. Default is **false**. |
320
319
|**useSwiftUIAutoSignal**| No | Bool | Enables automatic SwiftUI signal capture (requires typealiases). Default is **false**. |
321
320
|**useNetworkAutoSignal**| No | Bool | Enables automatic network signal capture for URLSession. Default is **false**. |
322
-
|**allowedNetworkHosts**| No |[String]| Array of host patterns to track. Use `["*"]` for all hosts. Default is **["*"]**. |
323
-
|**blockedNetworkHosts**| No |[String]| Array of host patterns to exclude from tracking. Default is **[]**. |
321
+
|**allowedNetworkHosts**| No | String | Array of host patterns to track. Use `["*"]` for all hosts. Default is **["*"]**. |
322
+
|**blockedNetworkHosts**| No | String | Array of host patterns to exclude from tracking. Default is **[]**. |
0 commit comments