Skip to content

Commit 7921aaa

Browse files
committed
Configuration intro and summary
1 parent e38c3d1 commit 7921aaa

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

src/connections/auto-instrumentation/configuration.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ title: Signals Implementation Guide
33
hidden: true
44
---
55

6+
This guide is a reference to configuring and using signals in the Signals SDK with Auto-Instrumentation. In this guide, you'll find details on:
7+
8+
- Setting up and managing signal types in the Signals SDK
9+
- Creating custom rules to capture and translate signals into actionable analytics events
10+
- Example rules that you can use as a basis for further customization
611

712
## Signals Configuration
813

@@ -187,8 +192,114 @@ class LocalDataSignal extends RawSignal<LocalData> {
187192

188193
### Instrumentation Signals
189194

195+
The SDK collects Instrumentation Signals when [traditional Segment analytics events](/docs/connections/spec/) are invoked:
196+
197+
```java
198+
enum EventType {
199+
Track, //
200+
Screen, //
201+
Identify, //
202+
Group, //
203+
Alias, //
204+
Unknown // Any other unspecified event type.
205+
}
206+
207+
class InstrumentationData {
208+
type: EventType // The type of Segment event.
209+
rawEvent: Object? // Additional details of the event.
210+
}
211+
212+
class InstrumentationSignal extends RawSignal<InstrumentationData> {
213+
type = SignalType.Instrumentation // Sets the signal type to Instrumentation.
214+
}
215+
```
216+
190217
### User-Defined Signals
191218

219+
You can also define your own signals. Use the following example as an implementation guideline:
220+
221+
```java
222+
interface MyCustomData {
223+
var event: String // A custom event description or identifier.
224+
}
225+
226+
class MyCustomSignal extends RawSignal<MyCustomData> {
227+
type = SignalType.UserDefined // Sets the signal type to User Defined.
228+
}
229+
```
192230

193231
## Example rule implementations
194232

233+
You can use the Signals data definitions on this page to create tracking rules.
234+
235+
### Example: Identify users
236+
237+
Building off of the screen tracking example, you could create a rule that identifies users:
238+
239+
```javascript
240+
function detectIdentify(currentSignal) {
241+
var loginType;
242+
243+
// Check if the signal is related to network activity on a login URL
244+
if (currentSignal.type == SignalType.Network && currentSignal.data.url.includes("login")) {
245+
loginType = "login";
246+
}
247+
248+
// If a login type was detected, identify the user
249+
if (loginType) {
250+
var traits = new Object();
251+
traits.loggedIn = true; // Set user status to logged in
252+
let loginData = currentSignal.data.data.content; // Extract login data from the signal
253+
traits.userName = loginData.userName; // Capture the user's name
254+
255+
if (loginType === "login") {
256+
var userId = loginData.userId; // Get userID from login data
257+
analytics.identify(userId, traits); // Identify the user with the Identify call
258+
}
259+
}
260+
}
261+
262+
//...other functions
263+
264+
function processSignal(signal) {
265+
//...other functions
266+
detectIdentify(signal); // Process the Identify call based on incoming signals
267+
}
268+
```
269+
270+
271+
### Example: Track `Add to Cart` events
272+
273+
This rule shows how you could implement the core ordering events from [the e-commerce Spec](/docs/connections/spec/ecommerce/v2/#core-ordering-overview):
274+
275+
```javascript
276+
function trackAddToCart(currentSignal) {
277+
// Check if the signal is an interaction with the "Add To Cart" button
278+
if (currentSignal.type == SignalType.Interaction && currentSignal.data.title == "Add To Cart") {
279+
var properties = new Object(); // Initialize an object to store event properties
280+
281+
// Find the network response signal for additional data
282+
let network = signals.find(currentSignal, SignalType.Network, (signal) => {
283+
return signal.data.action === NetworkAction.Response;
284+
});
285+
286+
if (network) {
287+
// Extract and assign product details from the network response
288+
properties.price = network.data.data.content.price; // Product price
289+
properties.currency = network.data.data.content.currency ?? "USD"; // Currency, defaulting to USD if undefined
290+
properties.productId = network.data.data.content.id; // Product ID
291+
properties.productName = network.data.data.content.title; // Product name
292+
}
293+
294+
// Track the "Add To Cart" event with the defined properties
295+
analytics.track(currentSignal.data.title, properties);
296+
}
297+
}
298+
299+
//...other functions
300+
301+
function ProcessSignals(signal) {
302+
//...other functions
303+
trackAddToCart(signal); // Process the "Add To Cart" tracking based on incoming signals
304+
}
305+
```

0 commit comments

Comments
 (0)