Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
NotificationsYou must be signed in to change notification settings

segment-integrations/signals-kotlin-docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 

Repository files navigation

Prerequisites

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")

Getting Started

Instrumentation becomes as simple as adding dependencies to your module's Gradle file:

  1. Add Signals Core
    // signal coreimplementation ("com.segment.analytics.kotlin.signals:core:1.0.0")
  2. 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)
  3. Add proper dependency and plugin as needed to:

Additional Setup

Capture Interactions

Kotlin Compose

  1. Add the dependency to your module’s Gradle build file.

    implementation ("com.segment.analytics.kotlin.signals:compose:1.0.0")
  2. AddSignalsComposeTrackingPlugin to analytics

    analytics.add(SignalsComposeTrackingPlugin())

Legacy XML UI

  1. Add uitoolkit Gradle Plugin dependency to project levelbuild.gradle
    buildscript {    dependencies {        classpath'com.segment.analytics.kotlin.signals:uitoolkit-gradle-plugin:1.0.0'    }}
  2. Apply the plugin in your app levelbuild.gradle and add the dependency
    plugins {// ...other plugins    id'com.segment.analytics.kotlin.signals.uitoolkit-tracking'}dependencies {// ..other dependencies  implementation ("com.segment.analytics.kotlin.signals:uitoolkit:1.0.0")}

Capture Navigation

  1. Add navigation Gradle Plugin dependency to project levelbuild.gradle
    buildscript {    dependencies {        classpath'com.segment.analytics.kotlin.signals:navigation-gradle-plugin:1.0.0'    }}
  2. Apply the plugin in your app levelbuild.gradle and add the dependency
    plugins {// ...other plugins    id'com.segment.analytics.kotlin.signals.navigation-tracking'}dependencies {// ..other dependencies  implementation ("com.segment.analytics.kotlin.signals:navigation:1.0.0")}
  3. (Optional) AddSignalsActivityTrackingPlugin to analytics to track Activity/Fragment navigation.Not required for Compose Navigation
    analytics.add(SignalsActivityTrackingPlugin())

Capture Network

OkHttp

  1. add dependency:

    implementation ("com.segment.analytics.kotlin.signals:okhttp3:1.0.0")
  2. addSignalsOkHttp3TrackingPlugin as an interceptor to your OkHttpClient:

    privateval okHttpClient=OkHttpClient.Builder()       .addInterceptor(SignalsOkHttp3TrackingPlugin())       .build()

Retrofit

  1. add dependency:

    implementation ("com.segment.analytics.kotlin.signals:okhttp3:1.0.0")
  2. addSignalsOkHttp3TrackingPlugin as an interceptor to your Retrofit client:

    privateval okHttpClient=OkHttpClient.Builder()       .addInterceptor(SignalsOkHttp3TrackingPlugin())       .build()val retrofit=Retrofit.Builder()       .client(okHttpClient)       .build()

java.net.HttpURLConnection

  1. add dependency:

    implementation ("com.segment.analytics.kotlin.signals:java-net:1.0.0")
  2. install theJavaNetTrackingPlugin on where you initialize analytics:

    JavaNetTrackingPlugin.install()

Configuration Options

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.

OPTIONREQUIREDVALUEDESCRIPTION
maximumBufferSizeNoIntegerThe number of signals to be kept for JavaScript inspection. This buffer is first-in, first-out. Default is1000.
relayCountNoIntegerRelays every X signals to Segment. Default is20.
relayIntervalNoIntegerRelays signals to Segment every X seconds. Default is60.
broadcastersNoListAn 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.
sendDebugSignalsToSegmentNoBooleanTurns 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.
obfuscateDebugSignalsNoBooleanObfuscates signals being relayed to Segment. Default istrue.

Debug Mode

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:sendDebugSignalsToSegment should 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 ConfiguresendDebugSignalsToSegment andobfuscateDebugSignals:

    1. Define different flavors inbuild.gradle
      productFlavors {  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"  }}
    2. Initialize Signals with the appropriate configuration:
      Signals.configuration=Configuration(// ... other config options  sendDebugSignalsToSegment=BuildConfig.SEND_DEBUG_SIGNALS_TO_SEGMENT  obfuscateDebugSignals=BuildConfig.OBFUSCATE_DEBUG_SIGNALS)
  • Use a Feature Flag to ConfiguresendDebugSignalsToSegment andobfuscateDebugSignals. If you're using Firebase Remote Config or a similar feature flag system, you can dynamically controlsendDebugSignalsToSegment andobfuscateDebugSignals without requiring a new app build:

    Signals.configuration=Configuration(// ... other config options      sendDebugSignalsToSegment= remoteConfig.getBoolean("sendDebugSignalsToSegment")      obfuscateDebugSignals= remoteConfig.getBoolean("obfuscateDebugSignals")    )

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp