Skip to content

Commit 0d6c5b3

Browse files
committed
link to external docs
1 parent 7e52d15 commit 0d6c5b3

File tree

1 file changed

+100
-21
lines changed

1 file changed

+100
-21
lines changed

src/connections/auto-instrumentation/kotlin-setup.md

Lines changed: 100 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,43 +102,122 @@ When you run this code, keep the following in mind:
102102
- `debugMode` sends signals to Segment for use in the Event Builder. Only enable it in development environments.
103103
- If your app doesn't use Jetpack Compose or Navigation, you can skip those plugin lines.
104104

105-
For more options, see [Configuration options reference].
105+
For more options, see [Configuration options reference](#tbd).
106106

107-
<!-->
108-
2. Add the initialization code and configuration options:
107+
## Step 3: Track network requests
109108

110-
> success ""
111-
> see [configuration options](#configuration-options) for a complete list.
109+
Signals supports automatic tracking of network activity for apps that use OkHttp3, Retrofit, or `HttpURLConnection`.
110+
111+
Add the relevant plugin based on your network stack.
112+
113+
### OkHttp3
114+
115+
1. Add the dependency to your Gradle file:
116+
117+
```groovy
118+
implementation("com.segment.analytics.kotlin.signals:okhttp3:0.5.0")
119+
```
120+
121+
2. Add the tracking plugin to your `OkHttpClient`:
112122
113123
```kotlin
114-
// Configure Analytics with your settings
115-
{... <analytics config>....}
124+
val okHttpClient = OkHttpClient.Builder()
125+
.addInterceptor(SignalsOkHttp3TrackingPlugin())
126+
.build()
127+
```
116128
117-
// Add live plugins for real-time analytics
118-
analytics.add(LivePlugins())
129+
### Retrofit
119130
120-
// Configure and add the Signals plugin
121-
Signals.configuration = Configuration(
122-
writeKey = "<WRITE_KEY>", // Replace <WRITE_KEY> with the write key you previously copied
123-
maximumBufferSize = 1000,
124-
broadcasters = listOf(SegmentBroadcaster(analytics))
125-
)
131+
Retrofit is built on top of OkHttp, so the setup is similar.
132+
133+
1. Add the same OkHttp3 plugin shown in the previous sectiion:
126134
127-
// Add the Compose plugin for UI events and screen tracking
128-
analytics.add(SignalsComposeTrackingPlugin())
135+
```groovy
136+
implementation("com.segment.analytics.kotlin.signals:okhttp3:0.5.0")
129137
```
130138
131-
3. (Optional:) If you want to track network activity, configure your OkHttpClient to use the Signals OkHttp3 plugin:
139+
2. Attach the plugin through your Retrofit client configuration:
132140
133141
```kotlin
134-
private val okHttpClient = OkHttpClient.Builder()
142+
val okHttpClient = OkHttpClient.Builder()
135143
.addInterceptor(SignalsOkHttp3TrackingPlugin())
136144
.build()
145+
146+
val retrofit = Retrofit.Builder()
147+
.client(okHttpClient)
148+
.baseUrl("https://your.api.endpoint")
149+
.build()
150+
```
151+
152+
### HttpURLConnection
153+
154+
1. Add the JavaNet plugin dependency:
155+
156+
```groovy
157+
implementation("com.segment.analytics.kotlin.signals:java-net:0.5.0")
158+
```
159+
160+
2. Install the plugin at runtime:
161+
162+
```kotlin
163+
JavaNetTrackingPlugin.install()
164+
```
165+
166+
---
167+
168+
Depending on your app’s network stack, you may only need one plugin. If your app uses multiple clients, you can install more than one.
169+
170+
## Step 4: Enable debug mode
171+
172+
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.
173+
174+
To view captured signals in the Event Builder and create event generation rules, you need to enable `debugMode`. This setting temporarily lets the SDK send signal data to Segment while you're testing.
175+
176+
> warning ""
177+
> Only enable `debugMode` in development environments. Avoid using `debugMode` in production apps.
178+
179+
You can enable `debugMode` in one of two ways.
180+
181+
### Option 1: Use build flavors
182+
183+
Configure `debugMode` at build time using [Android product flavors](https://developer.android.com/build/build-variants#product-flavors){:target="_blank"}.
184+
185+
1. In your `build.gradle` file, define two flavors:
186+
187+
```groovy
188+
android {
189+
...
190+
productFlavors {
191+
prod {
192+
buildConfigField "boolean", "DEBUG_MODE", "false"
193+
}
194+
dev {
195+
buildConfigField "boolean", "DEBUG_MODE", "true"
196+
}
197+
}
198+
}
137199
```
138200
139-
4. Build and run your app.
201+
2. Update the Signals configuration to use the flag:
202+
203+
```kotlin
204+
Signals.configuration = Configuration(
205+
...
206+
debugMode = BuildConfig.DEBUG_MODE
207+
)
208+
```
209+
210+
### Option 2: Use a feature flag
211+
212+
If your app uses [Firebase Remote Config](https://firebase.google.com/docs/remote-config){:target="_blank"} or a similar system, you can control `debugMode` remotely.
213+
214+
```kotlin
215+
Signals.configuration = Configuration(
216+
...
217+
debugMode = remoteConfig.getBoolean("debug_mode")
218+
)
140219
141-
## Step 3: Verify and deploy events
220+
<!--## Step 3: Verify and deploy events
142221
143222
After integrating the SDK and running your app, verify that Segment is collecting signals:
144223

0 commit comments

Comments
 (0)