You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This guide outlines the steps required to set up the Signals SDK in your JavaScript website.
7
7
8
-
You'll learn how to add Auto-Instrumentation sources, integrate dependencies, and ensure that your setup captures and processes data as intended.
8
+
You'll learn how to add Auto-Instrumentation sources, integrate dependencies, and ensure that your setup captures and processes data as intended.
9
9
10
10
> info "Auto-Instrumentation Private Beta"
11
11
> Auto-Instrumentation is currently in Private Beta and is governed by Segment's [First Access and Beta Preview Terms](https://www.twilio.com/en-us/legal/tos){:target="_blank"}. Segment is actively iterating on and improving the Auto-Instrumentation user experience.
@@ -15,53 +15,180 @@ You'll learn how to add Auto-Instrumentation sources, integrate dependencies, an
15
15
16
16
## Step 1: Add a source and get its write key
17
17
18
-
You'll first need to add a source and copy its write key:
18
+
You'll first need to add a source and copy its write key:
19
19
20
20
1. In your Segment workspace, navigate to **Connections > Auto-Instrumentation** and click **Add source**.
21
21
2. Select a source, give the source a name, and click **Save**.
22
-
3. Return to **Connections > Sources** to view your sources.
22
+
3. Return to **Connections > Sources** to view your sources.
23
23
4. In the **My sources** table, find and click the new source you just set up.
24
-
5. In the **Initialize the Client** section, look for and copy the `writeKey` displayed in the code block.
24
+
5. In the **Initialize the Client** section, look for and copy the `writeKey` displayed in the code block.
25
25
26
26
## Step 2: Add dependencies and initialization code
27
27
28
-
Next, you'll need to add the Signals SDKs to your web environment.
28
+
Next, you'll need to add the Signals SDKs to your web environment.
29
+
30
+
Choose the installation method that matches your setup:
31
+
32
+
-**Option A:** For websites loading Segment through the HTML snippet.
33
+
-**Option B:** For projects using npm, yarn, or pnpm.
34
+
35
+
### Option A: Websites using the Segment snippet (HTML)
36
+
37
+
> warning ""
38
+
> Include only one Segment snippet per page. Replacing your existing snippet prevents duplicate `analytics.load()` calls.
39
+
40
+
If your site uses the standard Segment snippet, **replace it** with the following version, which includes the Signals SDK:
41
+
42
+
```html
43
+
<head>
44
+
<title>My Website</title>
45
+
<!-- Replace <YOUR_WRITE_KEY> in 'data-segment-write-key' -->
46
+
<scriptdata-segment-write-key="<YOUR_WRITE_KEY>">
47
+
!(function () {
48
+
var i ="analytics",
49
+
analytics = (window[i] =window[i] || []);
50
+
if (!analytics.initialize)
51
+
if (analytics.invoked)
52
+
window.console&&
53
+
console.error&&
54
+
console.error("Segment snippet included twice.");
55
+
else {
56
+
analytics.invoked=!0;
57
+
analytics.methods= [
58
+
"trackSubmit",
59
+
"trackClick",
60
+
"trackLink",
61
+
"trackForm",
62
+
"pageview",
63
+
"identify",
64
+
"reset",
65
+
"group",
66
+
"track",
67
+
"ready",
68
+
"alias",
69
+
"debug",
70
+
"page",
71
+
"screen",
72
+
"once",
73
+
"off",
74
+
"on",
75
+
"addSourceMiddleware",
76
+
"addIntegrationMiddleware",
77
+
"setAnonymousId",
78
+
"addDestinationMiddleware",
79
+
"register",
80
+
];
81
+
analytics.factory=function (e) {
82
+
returnfunction () {
83
+
if (window[i].initialized)
84
+
returnwindow[i][e].apply(window[i], arguments);
85
+
var n =Array.prototype.slice.call(arguments);
86
+
if (
87
+
[
88
+
"track",
89
+
"screen",
90
+
"alias",
91
+
"group",
92
+
"page",
93
+
"identify",
94
+
].indexOf(e) >-1
95
+
) {
96
+
var c =document.querySelector("link[rel='canonical']");
97
+
n.push({
98
+
__t:"bpc",
99
+
c: (c &&c.getAttribute("href")) ||void0,
100
+
p:location.pathname,
101
+
u:location.href,
102
+
s:location.search,
103
+
t:document.title,
104
+
r:document.referrer,
105
+
});
106
+
}
107
+
n.unshift(e);
108
+
analytics.push(n);
109
+
return analytics;
110
+
};
111
+
};
112
+
for (var n =0; n <analytics.methods.length; n++) {
Verify that you replaced `<WRITE_KEY>` with the actual write key you copied in Step 1.
184
+
analytics.load({
185
+
writeKey: "<YOUR_WRITE_KEY>",
186
+
});
187
+
```
63
188
64
-
4. Build and run your app.
189
+
Verify that you replaced `<YOUR_WRITE_KEY>` with the actual write key you copied in Step 1.
190
+
191
+
3. Build and run your app.
65
192
66
193
## Step 3: Verify and deploy events
67
194
@@ -71,70 +198,129 @@ After integrating the SDK and running your app, verify that Segment is collectin
71
198
2. In the source overview, look for the **Event Builder** tab. If the tab doesn’t appear:
72
199
- Make sure you've installed the SDK correctly.
73
200
- Reach out to your Segment CSM to confirm that your workspace has the necessary feature flags enabled.
74
-

75
-
3. Open the **Event Builder** and follow the on-screen instructions to start signal detection.
201
+

202
+
203
+
3. Open the **Event Builder** and follow the on-screen instructions to start signal detection.
76
204
- To collect signals in the UI, visit your site in a browser using the query string:`?segment_signals_debug=true`
77
205
4. Interact with your app to trigger signals: click buttons, navigate pages, submit forms, and so on. Segment collects and displays these as signals in real time.
78
206
5. From the signals list, click **Configure event** to define a new event based on one or more signals. After configuring the event, click **Publish event rules**.
79
207
80
-
81
208
### Debugging
209
+
82
210
#### Enable debug mode
211
+
83
212
Values sent to the signals API are redacted by default.
84
-
This adds a local storage key. To disable redaction, add a magic query string:
213
+
This adds a local storage key. To disable redaction, add a magic query string:
If you get CSP errors, you can use the experimental 'global' sandbox strategy:
277
+
278
+
```ts
279
+
newSignalsPlugin({ sandboxStrategy: "global" });
120
280
```
121
281
122
282
## Configuration Options
123
283
124
-
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.
284
+
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 Web.
|`maxBufferSize`| No | number | The number of signals to be kept for JavaScript inspection. This buffer is first-in, first-out. Default is `1000`. |
289
+
|`enableDebugLogging`| No | boolean | Enable debug logs. |
290
+
|`disableSignalRedaction`| No | boolean | Disable default Signal data redaction. |
291
+
|`apiHost`| No | string | Override the default signals API host. Default is `signals.segment.io/v1`. |
292
+
|`functionHost`| No | string | Override the default edge host. Default is `cdn.edgefn.segment.com`|
293
+
|`flushAt`| No | number | How many signals to flush at once when sending to the signals API. Default is `5` . |
294
+
|`flushInterval`| No | number | How many ms to wait before flushing signals to the API. The default is `2000`. |
295
+
|`middleware`| No | SignalsMiddleware[]| Array of middleware to process signals before they are sent. |
296
+
|`sandboxStrategy`| No | 'global' \| 'iframe' | Sandbox strategy for signal collection. Use 'global' if getting CSP errors. Default is 'iframe'. |
297
+
298
+
## Core Signal Types
299
+
300
+
Auto-Instrumentation collects different types of signals automatically:
301
+
302
+
### `interaction`
303
+
304
+
Interaction signals emit in response to a user interaction (like clicks or form submissions)
305
+
306
+
### `instrumentation`
307
+
308
+
Instrumentation signals emit whenever a Segment event is emitted.
309
+
310
+
### `navigation`
311
+
312
+
Navigation signals emit whenever the URL changes.
313
+
314
+
> Note: you can also rely on the initial analytics.page() call, which you can access as an Instrumentation signal.
315
+
316
+
### `network`
317
+
318
+
Network signals emit when an HTTP Request is made, or an HTTP Response is received. To emit a network signal, the network activity must have the following requirements:
|`maxBufferSize`| No | number | The number of signals to be kept for JavaScript inspection. This buffer is first-in, first-out. Default is `1000`. |
130
-
| `processSignal` | No | string | Override the default signal processing function from the edge function. If this is set, the edge function will not be used.
131
-
| `enableDebugLogging` | No | boolean | Enable debug logs.
132
-
| `disableSignalRedaction` | No | boolean | Disable default Signal data redaction.
133
-
| `apiHost` | No | string | Override the default signals API host. Default is `signals.segment.io/v1`.
134
-
| `functionHost` | No | string | Override the default edge host. Default is `cdn.edgefn.segment.com`
135
-
|`flushAt`| No | number | How many signals to flush at once when sending to the signals API. Default is `5` . |
136
-
|`flushInterval`| No | number | How many ms to wait before flushing signals to the API. The default is `2000`. |
320
+
- Initiated using the `fetch` API
321
+
- First party domain (for example, if on `foo.com`, then `foo.com/api/products`, but not `bar.com/api/products`)
322
+
- Contains the content-type: `application/json`
137
323
138
324
## Next steps
139
325
140
-
This guide walked you through initial Signals SDK/Auto-Instrumentation setup. Next, read the [Auto-Instrumentation Signals Implementation Guide](/docs/connections/auto-instrumentation/configuration/), which dives deeper into Signals and offers example rules.
326
+
This guide walked you through initial Signals SDK/Auto-Instrumentation setup. Next, read the [Auto-Instrumentation Signals Implementation Guide](/docs/connections/auto-instrumentation/configuration/), which dives deeper into Signals and offers example rules.
0 commit comments