Auto-Instrumentation Setup
Segment's Signals library powers Auto-Instrumentation in Android apps, capturing user interactions and behavior without manual event tracking.
This guide shows how to install and configure the library, as well as how to enable optional plugins for screen views, network activity, and more.
Auto-Instrumentation in public beta
Auto-Instrumentation is in public beta, and Segment is actively working on this feature. Some functionality may change before it becomes generally available.
Regional availability
Auto-Instrumentation isn't supported in EU workspaces.
To use Signals with Android, you need:
- An active Segment workspace with Auto-Instrumentation enabled.
- Android Gradle Plugin version 7.0 or later.
- A minimum compile SDK version of 21.
Signals supports Jetpack Compose and traditional Android UI frameworks. It also includes optional plugins for network tracking using OkHttp3, Retrofit, or HttpURLConnection.
Segment recommends testing in a development environment before deploying Signals in production. For more information, see Debug mode.
Auto-Instrumentation (also known as Signals) works on top of Analytics and Live Plugins. Make sure to add the following dependencies to your module's Gradle file if you don't have them already.
1// analytics kotlin2implementation ("com.segment.analytics.kotlin:android:1.22.0")3// live plugin4implementation("com.segment.analytics.kotlin:analytics-kotlin-live:1.3.0")
To get started:
- Add Signals Core:
1// signal core2implementation ("com.segment.analytics.kotlin.signals:core:1.0.0")
- Initialize Signals. For a complete list of Signals configuration options, see configuration options.
1//... <analytics config>....2analytics.add(LivePlugins()) // Make sure LivePlugins is added3analytics.add(Signals) // Add the signals plugin45Signals.configuration = Configuration(6// sendDebugSignalsToSegment will relay events to Segment server. Should only be true for development purposes.7sendDebugSignalsToSegment = true8// obfuscateDebugSignals will obfuscate sensitive data9obfuscateDebugSignals = true10// .. other options11)
- Add proper dependency and plugin as needed to:
- Add the dependency to your module's Gradle build file:
implementation ("com.segment.analytics.kotlin.signals:compose:1.0.0")
- Add
SignalsComposeTrackingPluginto analytics:analytics.add(SignalsComposeTrackingPlugin())
- Add the uitoolkit Gradle Plugin dependency to project-level
build.gradle:1buildscript {2dependencies {3classpath 'com.segment.analytics.kotlin.signals:uitoolkit-gradle-plugin:1.0.0'4}5} - Apply the plugin in your app-level
build.gradleand add the dependency:1plugins {2// ...other plugins3id 'com.segment.analytics.kotlin.signals.uitoolkit-tracking'4}56dependencies {7// ..other dependencies8implementation ("com.segment.analytics.kotlin.signals:uitoolkit:1.0.0")9}
- Add the dependency:
implementation ("com.segment.analytics.kotlin.signals:okhttp3:1.0.0")
- Add
SignalsOkHttp3TrackingPluginas an interceptor to your OkHttpClient:1private val okHttpClient = OkHttpClient.Builder()2.addInterceptor(SignalsOkHttp3TrackingPlugin())3.build()
- Add the dependency:
implementation ("com.segment.analytics.kotlin.signals:okhttp3:1.0.0")
- Add
SignalsOkHttp3TrackingPluginas an interceptor to your Retrofit client:1private val okHttpClient = OkHttpClient.Builder()2.addInterceptor(SignalsOkHttp3TrackingPlugin())3.build()45val retrofit = Retrofit.Builder()6.client(okHttpClient)7.build()
- Add the dependency:
implementation ("com.segment.analytics.kotlin.signals:java-net:1.0.0")
- Install the
JavaNetTrackingPluginon where you initialize analytics:JavaNetTrackingPlugin.install()
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.
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.
In addition, the SDK obfuscates signals sent to Segment by default. To view the completed data, you need to turn off obfuscateDebugSignals.
Warning
Only enable sendDebugSignalsToSegment in development environments. Avoid using sendDebugSignalsToSegment in production apps.
You can enable sendDebugSignalsToSegment and turn off obfuscateDebugSignals in one of two ways.
Configure sendDebugSignalsToSegment and obfuscateDebugSignals at build time using Android product flavors.
-
In your
build.gradlefile, define two flavors:1android {2...3productFlavors {4prod {5buildConfigField "boolean", "SEND_DEBUG_SIGNALS_TO_SEGMENT", "false"6buildConfigField "boolean", "OBFUSCATE_DEBUG_SIGNALS", "true"7}8dev {9buildConfigField "boolean", "SEND_DEBUG_SIGNALS_TO_SEGMENT", "true"10buildConfigField "boolean", "OBFUSCATE_DEBUG_SIGNALS", "false"11}12}13} -
Update the Signals configuration to use the flag:
1Signals.configuration = Configuration(2// ... other config options3sendDebugSignalsToSegment = BuildConfig.SEND_DEBUG_SIGNALS_TO_SEGMENT4obfuscateDebugSignals = BuildConfig.OBFUSCATE_DEBUG_SIGNALS5)
If your app uses Firebase Remote Config or a similar system, you can control sendDebugSignalsToSegment and obfuscateDebugSignals remotely.
1Signals.configuration = Configuration(2...3sendDebugSignalsToSegment = remoteConfig.getBoolean("sendDebugSignalsToSegment")4obfuscateDebugSignals = remoteConfig.getBoolean("obfuscateDebugSignals")5)
Next, return to the source settings to turn on Auto-Instrumentation:
- Go to Connections > Sources.
- Select the source you used in Step 1.
- From the source's overview tab, go to Settings > Advanced.
- Toggle Auto-Instrumention on.
After you build and run your app, use the Event Builder to confirm that Signals are being collected correctly.
-
In your Segment workspace, go to Connections > Sources and select the Android Source you configured.
-
Open the Event Builder tab.
-
Interact with your app on a simulator or test device:
- Navigate between screens.
- Tap buttons and UI elements.
- Trigger network requests.
(success)`sendDebugSignalsToSegment`
If
sendDebugSignalsToSegmentis enabled, Signals appear in real time as you interact with the app. -
In the Event Builder, select a signal and click Configure event to define a new event.
-
After you add any event mappings, click Publish event rules to save them.
What if I don't see the Event Builder tab?
If you don't see the Event Builder tab, confirm that the SDK is installed correctly and make sure sendDebugSignalsToSegment is enabled. Verify that Auto-Instrumentation is enabled in Settings > Advanced. If you still don't see it, reach out to your CSM.
Use the Signals.configuration object to control how captured signals are stored, relayed, and displayed.
The following table lists the available options:
| Option | Required | Value | Description |
|---|---|---|---|
| maximumBufferSize | No | Integer | The number of signals to be kept for JavaScript inspection. This buffer is first-in, first-out. Default is 1000. |
| relayCount | No | Integer | Relays every X signals to Segment. Default is 20. |
| relayInterval | No | Integer | Relays signals to Segment every X seconds. Default is 60. |
| broadcasters | No | List<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. |
| sendDebugSignalsToSegment | No | Boolean | 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. |
| obfuscateDebugSignals | No | Boolean | Obfuscates signals being relayed to Segment. Default is true. |
After you've confirmed that signals show up in the Event Builder, use the Generate Events from Signals guide to configure how signals get translated into analytics events.