Skip to content

Commit e38c3d1

Browse files
committed
Signal types
1 parent fa124ad commit e38c3d1

File tree

2 files changed

+160
-6
lines changed

2 files changed

+160
-6
lines changed

src/connections/auto-instrumentation/configuration.md

Lines changed: 157 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ hidden: true
44
---
55

66

7-
## Configure Signals
7+
## Signals Configuration
88

9+
Using the Signals Configuration object, you can control the destination, frequency, and types of signals that Segment automatically tracks within your application. The following tables detail the configuration options for both Signals-Swift and Signals-Kotlin.
910

10-
11-
### Swift
12-
11+
### Signals-Swift
1312

1413
| `Option` | Required | Value | Description |
1514
| ---------------------- | -------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
@@ -25,7 +24,7 @@ hidden: true
2524
| `blockedNetworkHosts` | No | [String] | |
2625

2726

28-
### Kotlin
27+
### Signals-Kotlin
2928

3029
| `Option` | Required | Value | Description |
3130
| ------------------- | -------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -35,8 +34,160 @@ hidden: true
3534
| `broadcasters` | No | `List<SignalBroadcaster>` | An array of broadcasters. These objects forward signal data to their destinations, like `WebhookBroadcaster` or `DebugBroadcaster` writing to the developer console. Default is `SegmentBroadcaster`. |
3635

3736

38-
## Converting Signals to events
37+
## Converting signals to events
38+
39+
After you set up the Signals SDK to capture the signals you want to target, you can create rules in your Segment workspace to translate the captured signals into traditional Segment analytics events. These rules are deployed in your application the next time a user launches your app.
40+
41+
### Getting started with rule creation
42+
43+
1. In your Segment workspace, go to to **Connections > Auto-Instrumentation** and click on a source.
44+
2. Click **Create Rules**.
45+
46+
### Using the Rules Editor
47+
48+
The Rules Editor is where you define rules that transform raw signal data into analytics events. In the editor, you write functions that convert signals into events and then call them in the `processSignal()` function.
49+
50+
The Rules Editor also lets you test your rules with recent signals to verify that they produce the data you need before you deploy.
51+
52+
The following example tracks all Screen events:
53+
54+
```javascript
55+
function screenCall(currentSignal) {
56+
if (currentSignal.type == SignalType.Navigation && currentSignal.data.action == NavigationAction.Entering) {
57+
analytics.screen(currentSignal.data.screen, null, null)
58+
}
59+
}
60+
61+
function processSignal(signal) {
62+
screenCall(signal)
63+
}
64+
```
65+
66+
## Signal definitions
67+
68+
Signals come in various types, each associated with specific data that you can use to create analytics events. This section contains code samples that detail each signal type. Because Segment has standardized these definitions across both the Signals-Swift and Signals Kotlin libraries, they're useful when you create rules in your Segment workspace.
69+
70+
### Base Signal
71+
72+
The Base Signal serves as the foundation for all other signal types. It's defined by the `RawSignal<T>` interface, where `T` represents the data type associated with the signal.
73+
74+
This interface ensures that every signal inherits essential properties:
75+
76+
```java
77+
interface RawSignal<T> {
78+
var anonymousId: String // A unique identifier for the user.
79+
var type: SignalType // Specifies the signal category.
80+
var timestamp: String // The exact time when the signal was generated.
81+
var index: Int // An integer representing the signal's position.
82+
var data: T // The specific data of type `T` associated with the signal.
83+
}
84+
```
85+
86+
### Signal Types
87+
88+
The Signal Type enum defines the different types of signals the SDK can collect:
89+
90+
```java
91+
enum SignalType {
92+
Interaction, // User interactions like clicks or touches
93+
Navigation, // Navigation events.
94+
Network, // Network requests and responses.
95+
LocalData, // Data loaded from local or other external sources
96+
Instrumentation, // Events generated from Segment Track/Screen/... events.
97+
UserDefined // Custom events defined by the user.
98+
}
99+
```
100+
101+
### Interaction Signals
102+
103+
The SDK collects Interaction Signals when you enable one of the "UI autoSignal" options, like `useSwiftUIAutoSignal: true`. These signals primarily track user interactions with UI components:
104+
105+
```java
106+
class InteractionData {
107+
var component: String // The type of UI component interacted with, like "Button" or "Image".
108+
var title: String? // Optional title of the component, if applicable.
109+
var data: Object? // Additional data related to the interaction, if any.
110+
}
111+
112+
class InteractionSignal extends RawSignal<InteractionData> {
113+
type = SignalType.UIInteraction // Sets the signal type to UI Interaction.
114+
}
115+
```
116+
117+
### Navigation Signals
118+
119+
The SDK collects Navigation Signals when you enable one of the "UI autoSignal" options, like `useSwiftUIAutoSignal: true`. These signals are generated when a user interacts with navigation components in your application's UI, giving you insight into how users move through and interact with your application:
120+
121+
```java
122+
enum NavigationAction {
123+
Forward, // Navigation to the next item or page
124+
Backward, // Navigation to the previous item or page
125+
Modal, // Opening a modal window
126+
Entering, // Entering a new screen
127+
Leaving, // Leaving a screen
128+
Page, // Navigation involving a full page
129+
Popup // Interaction with a popup
130+
}
131+
132+
class NavigationData {
133+
var action: NavigationAction // The type of navigation action performed
134+
var screen: String // The screen or component name involved in the navigation.
135+
}
136+
137+
class NavigationSignal extends RawSignal<NavigationData> {
138+
type = SignalType.Navigation // Sets the signal type to Navigation.
139+
}
140+
```
141+
142+
### Network Signals
143+
144+
The SDK collects Network Signals when you enable the `useNetworkAutoSignal` option in your Signals Configuration, like `useNetworkAutoSignal: true`. These signals are generated when your application makes network requests:
39145

146+
```java
147+
enum NetworkAction {
148+
Request, // A network request is made.
149+
Response // A response is received.
150+
}
151+
152+
class NetworkData {
153+
var action: NetworkAction // The type of network action, either Request or Response.
154+
var url: String // The URL involved in the network action.
155+
var statusCode: Int? // The HTTP status code of the response, if applicable.
156+
var data: Object? // Additional data associated with the network action.
157+
}
158+
159+
class NetworkSignal extends RawSignal<NetworkData> {
160+
type = SignalType.Network // Sets the signal type to Network.
161+
}
162+
```
163+
164+
### LocalData Signals
165+
166+
The SDK collects Local Data Signals when data gets loaded from local soures, like SQLite databases or local caches. These signals help track how your application manages local data:
167+
168+
```java
169+
enum LocalDataAction {
170+
Loaded, // Data was loaded from a local source.
171+
Updated, // Existing data was updated.
172+
Saved, // New data was saved locally.
173+
Deleted, // Data was deleted from a local source.
174+
Undefined // Any other unspecified local data action.
175+
}
176+
177+
class LocalData {
178+
var action: LocalDataAction // The type of action performed on the local data.
179+
var identifier: String // A unique identifier for the data, like "Loaded User Info".
180+
var data: Object? // Additional details or data associated with the action.
181+
}
182+
183+
class LocalDataSignal extends RawSignal<LocalData> {
184+
type = SignalType.LocalData // Sets the signal type to LocalData.
185+
}
186+
```
187+
188+
### Instrumentation Signals
189+
190+
### User-Defined Signals
40191

41192

42193
## Example rule implementations

src/connections/auto-instrumentation/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ With just a few lines of code, Auto-Instrumentation handles device tracking for
1515
1616
## Overview
1717

18+
19+
1820
## How Auto-Instrumentation works
1921

2022

2123
### Privacy
2224

25+

0 commit comments

Comments
 (0)