- Notifications
You must be signed in to change notification settings - Fork0
segment-integrations/signals-kotlin-docs
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Auto-Instrumentation (aka 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.
// analytics kotlinimplementation ("com.segment.analytics.kotlin:android:1.22.0")// live pluginimplementation("com.segment.analytics.kotlin:analytics-kotlin-live:1.3.0")
Instrumentation becomes as simple as adding dependencies to your module's Gradle file:
- Add Signals Core
// signal coreimplementation ("com.segment.analytics.kotlin.signals:core:1.0.0")
- Initialize Signals
//... <analytics config>....analytics.add(LivePlugins())// Make sure LivePlugins is addedanalytics.add(Signals)// Add the signals pluginSignals.configuration=Configuration(// sendDebugSignalsToSegment will relay events to Segment server. Should only be true for development purposes. sendDebugSignalsToSegment=true// obfuscateDebugSignals will obfuscate sensitive data obfuscateDebugSignals=true// .. other options)
- 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 analyticsanalytics.add(SignalsComposeTrackingPlugin())
- Add uitoolkit Gradle Plugin dependency to project level
build.gradlebuildscript { dependencies { classpath'com.segment.analytics.kotlin.signals:uitoolkit-gradle-plugin:1.0.0' }} - Apply the plugin in your app level
build.gradleand add the dependencyplugins {// ...other plugins id'com.segment.analytics.kotlin.signals.uitoolkit-tracking'}dependencies {// ..other dependencies implementation ("com.segment.analytics.kotlin.signals:uitoolkit:1.0.0")}
- Add navigation Gradle Plugin dependency to project level
build.gradlebuildscript { dependencies { classpath'com.segment.analytics.kotlin.signals:navigation-gradle-plugin:1.0.0' }} - Apply the plugin in your app level
build.gradleand add the dependencyplugins {// ...other plugins id'com.segment.analytics.kotlin.signals.navigation-tracking'}dependencies {// ..other dependencies implementation ("com.segment.analytics.kotlin.signals:navigation:1.0.0")} - (Optional) Add
SignalsActivityTrackingPluginto analytics to track Activity/Fragment navigation.Not required for Compose Navigationanalytics.add(SignalsActivityTrackingPlugin())
add dependency:
implementation ("com.segment.analytics.kotlin.signals:okhttp3:1.0.0")add
SignalsOkHttp3TrackingPluginas an interceptor to your OkHttpClient:privateval okHttpClient=OkHttpClient.Builder() .addInterceptor(SignalsOkHttp3TrackingPlugin()) .build()
add dependency:
implementation ("com.segment.analytics.kotlin.signals:okhttp3:1.0.0")add
SignalsOkHttp3TrackingPluginas an interceptor to your Retrofit client:privateval okHttpClient=OkHttpClient.Builder() .addInterceptor(SignalsOkHttp3TrackingPlugin()) .build()val retrofit=Retrofit.Builder() .client(okHttpClient) .build()
add dependency:
implementation ("com.segment.analytics.kotlin.signals:java-net:1.0.0")install the
JavaNetTrackingPluginon where you initialize analytics:JavaNetTrackingPlugin.install()
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-Kotlin.
| 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 is1000. |
| relayCount | No | Integer | Relays every X signals to Segment. Default is20. |
| relayInterval | No | Integer | Relays signals to Segment every X seconds. Default is60. |
| broadcasters | No | List | An array of broadcasters. These objects forward signal data to their destinations, likeWebhookBroadcaster, or you could write your ownDebugBroadcaster 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 isfalse. It should only be set to true for development purposes. |
| obfuscateDebugSignals | No | Boolean | Obfuscates signals being relayed to Segment. Default istrue. |
The SDK automatically captures various types of signals, such as interactions, navigation, and network activity. However, relaying all these signals to a destination could consume a significant portion of the end user's bandwidth. Additionally, storing all user signal data on a remote server might violate privacy compliance regulations. Therefore, by default, the SDK disables this capability, ensuring that captured signals remain on the end user's device.
However, being able to view these signals is crucial for creating event generation rules on the Segment Auto-Instrumentation dashboard. To facilitate this, the SDK provides asendDebugSignalsToSegment configuration option that enables signal relaying to a destination and anobfuscateDebugSignals configuration option to obfuscate signals data.
⚠️ Warning:sendDebugSignalsToSegmentshould only be used in a development setting to avoid storing sensitive end-user data.
AlthoughsendDebugSignalsToSegment offers convenience for logging events remotely, having to redistribute the app each time it is toggled on or off can be cumbersome. Below are some suggested workarounds:
Use Build Flavors to Configure
sendDebugSignalsToSegmentandobfuscateDebugSignals:- Define different flavors in
build.gradleproductFlavors { prod { buildConfigField"boolean","SEND_DEBUG_SIGNALS_TO_SEGMENT","false" buildConfigField"boolean","OBFUSCATE_DEBUG_SIGNALS","true" } dev { buildConfigField"boolean","SEND_DEBUG_SIGNALS_TO_SEGMENT","true" buildConfigField"boolean","OBFUSCATE_DEBUG_SIGNALS","false" }} - Initialize Signals with the appropriate configuration:
Signals.configuration=Configuration(// ... other config options sendDebugSignalsToSegment=BuildConfig.SEND_DEBUG_SIGNALS_TO_SEGMENT obfuscateDebugSignals=BuildConfig.OBFUSCATE_DEBUG_SIGNALS)
- Define different flavors in
Use a Feature Flag to Configure
sendDebugSignalsToSegmentandobfuscateDebugSignals. If you're using Firebase Remote Config or a similar feature flag system, you can dynamically controlsendDebugSignalsToSegmentandobfuscateDebugSignalswithout requiring a new app build:Signals.configuration=Configuration(// ... other config options sendDebugSignalsToSegment= remoteConfig.getBoolean("sendDebugSignalsToSegment") obfuscateDebugSignals= remoteConfig.getBoolean("obfuscateDebugSignals") )
About
Resources
Uh oh!
There was an error while loading.Please reload this page.