|
1 | 1 | ---
|
2 | 2 | title: Auto-Instrumentation Setup
|
3 | 3 | hidden: true
|
4 |
| ---- |
| 4 | +--- |
| 5 | + |
| 6 | + |
| 7 | +<!--- something about the SDK --> |
| 8 | + |
| 9 | +## Step 1: Add a source and get its write key |
| 10 | + |
| 11 | +You'll first need to add a source and copy its write key: |
| 12 | + |
| 13 | +1. In your Segment workspace, navigate to **Connections > Auto-Instrumentation** and click **Add source**. |
| 14 | +2. Select a source, give the source a name, and click **Save**. |
| 15 | +3. Return to **Connections > Sources** to view your sources. |
| 16 | +4. In the **My sources** table, find and click the new source you just set up. |
| 17 | +5. In the **Initialize the Client** section, look for and copy the `writeKey` displayed in the code block. |
| 18 | + |
| 19 | +## Step 2: Add dependencies and initialization code |
| 20 | + |
| 21 | +Next, you'll need to add the Signals SDKs to your development environment. |
| 22 | + |
| 23 | +### Swift |
| 24 | + |
| 25 | +Follow these steps to integrate the Signals SDK into your Swift application: |
| 26 | + |
| 27 | +1. Use Swift Package Manager to add the Signals SDK from the following repository: |
| 28 | + |
| 29 | +```https://github.com/segmentio/Signals-swift.git``` |
| 30 | + |
| 31 | +2. Add the initialization code: |
| 32 | + |
| 33 | +```swift |
| 34 | +// Configure Analytics with your settings |
| 35 | +{... <analytics config>....} |
| 36 | + |
| 37 | +// Set up the Signals SDK configuration |
| 38 | +let config = Signals.Configuration( |
| 39 | + writeKey: "<WRITE_KEY>", // Replace <WRITE_KEY> with your actual write key |
| 40 | + maximumBufferSize: 100, |
| 41 | + useSwiftUIAutoSignal: true, |
| 42 | + useNetworkAutoSignal: true |
| 43 | +) |
| 44 | + |
| 45 | +// Locate and set the fallback JavaScript file for edge functions |
| 46 | +let fallbackURL = Bundle.main.url(forResource: "MyEdgeFunctions", withExtension: "js") |
| 47 | + |
| 48 | +// Apply the configuration and add the Signals plugin |
| 49 | +Signals.shared.useConfiguration(config) |
| 50 | +Analytics.main.add(plugin: LivePlugins(fallbackFileURL: fallbackURL)) |
| 51 | +Analytics.main.add(plugin: Signals.shared) |
| 52 | +``` |
| 53 | + |
| 54 | +Verify that you replaced `<WRITE_KEY>` with the actual write key you copied in Step 1. |
| 55 | + |
| 56 | +### Kotlin |
| 57 | + |
| 58 | +Follow these steps to integrate the Signals SDK into your Kotlin application: |
| 59 | + |
| 60 | +1. Update your module’s Gradle build file to add the right dependencies: |
| 61 | + |
| 62 | +```kotlin |
| 63 | +dependencies { |
| 64 | + // Add the Analytics Kotlin library |
| 65 | + implementation("com.segment.analytics.kotlin:android:1.15.0") |
| 66 | + // Add a live plugin for real-time data handling |
| 67 | + implementation("com.segment.analytics.kotlin:analytics-kotlin-live:1.0.0") |
| 68 | + // Add the core Signals library |
| 69 | + implementation("com.segment.analytics.kotlin.signals:core:0.0.1") |
| 70 | + // Compose plugin for Jetpack Compose UI tracking |
| 71 | + implementation("com.segment.analytics.kotlin.signals:compose:0.0.1") |
| 72 | + // OkHttp3 plugin for network activity tracking |
| 73 | + implementation("com.segment.analytics.kotlin.signals:okhttp3:0.0.1") |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +2. Add the following code to your application to initialize the Signals SDK: |
| 78 | + |
| 79 | +```kotlin |
| 80 | +// Configure Analytics with your settings |
| 81 | +{... <analytics config>....} |
| 82 | + |
| 83 | +// Add live plugins for real-time analytics |
| 84 | +analytics.add(LivePlugins()) |
| 85 | + |
| 86 | +// Configure and add the Signals plugin |
| 87 | +Signals.configuration = Configuration( |
| 88 | + maximumBufferSize = 1000, |
| 89 | + broadcasters = listOf(SegmentBroadcaster(analytics)) |
| 90 | +) |
| 91 | + |
| 92 | +// Add the Compose plugin for UI events and screen tracking |
| 93 | +analytics.add(SignalsComposeTrackingPlugin()) |
| 94 | +``` |
| 95 | + |
| 96 | +3. (Optional:) If you want to track network activity, configure your OkHttpClient to use the Signals OkHttp3 plugin: |
| 97 | + |
| 98 | +```kotlin |
| 99 | +private val okHttpClient = OkHttpClient.Builder() |
| 100 | + .addInterceptor(SignalsOkHttp3TrackingPlugin()) |
| 101 | + .build() |
| 102 | +``` |
| 103 | + |
| 104 | +4. Build and run your app. |
| 105 | + |
| 106 | + |
| 107 | +## Step 3: Verify and deploy events |
| 108 | + |
| 109 | +Next, you'll need to verify signal emission and create rules to convert those signals into events. |
| 110 | + |
| 111 | +### Verify signal emission |
| 112 | + |
| 113 | +1. Return to **Connections > Auto-Instrumentation** and click on the new source you created. |
| 114 | +2. Verify that signals appear as expected on the dashboard. |
| 115 | + |
| 116 | + |
| 117 | + |
0 commit comments