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
-
> 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.
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.
12
12
13
13
> success "Enable Auto-Instrumentation"
14
14
> To enable Auto-Instrumentation in your Segment workspace, reach out to your dedicated account manager.
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 one of the following installation methods based on your setup:
31
+
32
+
### Option A: Snippet Users (HTML)
33
+
34
+
For websites using the Segment snippet, add the SignalsPlugin using a CDN:
35
+
36
+
```html
37
+
<head>
38
+
<title>My Website</title>
39
+
40
+
<!-- Load Segment (find and replace '<YOUR_WRITE_KEY>') -->
41
+
<script>
42
+
!(function () {
43
+
var i ="analytics",
44
+
analytics = (window[i] =window[i] || []);
45
+
if (!analytics.initialize)
46
+
if (analytics.invoked)
47
+
window.console&&
48
+
console.error&&
49
+
console.error("Segment snippet included twice.");
50
+
else {
51
+
analytics.invoked=!0;
52
+
analytics.methods= [
53
+
"trackSubmit",
54
+
"trackClick",
55
+
"trackLink",
56
+
"trackForm",
57
+
"pageview",
58
+
"identify",
59
+
"reset",
60
+
"group",
61
+
"track",
62
+
"ready",
63
+
"alias",
64
+
"debug",
65
+
"page",
66
+
"screen",
67
+
"once",
68
+
"off",
69
+
"on",
70
+
"addSourceMiddleware",
71
+
"addIntegrationMiddleware",
72
+
"setAnonymousId",
73
+
"addDestinationMiddleware",
74
+
"register",
75
+
];
76
+
analytics.factory=function (e) {
77
+
returnfunction () {
78
+
if (window[i].initialized)
79
+
returnwindow[i][e].apply(window[i], arguments);
80
+
var n =Array.prototype.slice.call(arguments);
81
+
if (
82
+
[
83
+
"track",
84
+
"screen",
85
+
"alias",
86
+
"group",
87
+
"page",
88
+
"identify",
89
+
].indexOf(e) >-1
90
+
) {
91
+
var c =document.querySelector("link[rel='canonical']");
92
+
n.push({
93
+
__t:"bpc",
94
+
c: (c &&c.getAttribute("href")) ||void0,
95
+
p:location.pathname,
96
+
u:location.href,
97
+
s:location.search,
98
+
t:document.title,
99
+
r:document.referrer,
100
+
});
101
+
}
102
+
n.unshift(e);
103
+
analytics.push(n);
104
+
return analytics;
105
+
};
106
+
};
107
+
for (var n =0; n <analytics.methods.length; n++) {
If getting CSP errors, you can use the experimental 'global' sandbox strategy:
259
+
114
260
```ts
115
-
const signalsPlugin =newSignalsPlugin()
116
-
signalsPlugin.addSignal({
117
-
type: 'userDefined',
118
-
data: { foo: 'bar' }
119
-
})
261
+
newSignalsPlugin({ sandboxStrategy: "global" });
120
262
```
121
263
122
264
## Configuration Options
123
265
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.
|`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`. |
266
+
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`. |
271
+
|`enableDebugLogging`| No | boolean | Enable debug logs. |
272
+
|`disableSignalRedaction`| No | boolean | Disable default Signal data redaction. |
273
+
|`apiHost`| No | string | Override the default signals API host. Default is `signals.segment.io/v1`. |
274
+
|`functionHost`| No | string | Override the default edge host. Default is `cdn.edgefn.segment.com`|
275
+
|`flushAt`| No | number | How many signals to flush at once when sending to the signals API. Default is `5` . |
276
+
|`flushInterval`| No | number | How many ms to wait before flushing signals to the API. The default is `2000`. |
277
+
|`middleware`| No | SignalsMiddleware[]| Array of middleware to process signals before they are sent. |
278
+
|`sandboxStrategy`| No | 'global' \| 'iframe' | Sandbox strategy for signal collection. Use 'global' if getting CSP errors. Default is 'iframe'. |
279
+
280
+
## Core Signal Types
281
+
282
+
Auto-Instrumentation collects different types of signals automatically:
283
+
284
+
### `interaction`
285
+
286
+
Interaction signals emit in response to a user interaction (clicks, form submissions, etc.)
287
+
288
+
### `instrumentation`
289
+
290
+
Instrumentation signals emit whenever a Segment event is emitted.
291
+
292
+
### `navigation`
293
+
294
+
Navigation signals emit whenever the URL changes.
295
+
296
+
> Note: you can also rely on the initial analytics.page() call, which you can access as an Instrumentation signal.
297
+
298
+
### `network`
299
+
300
+
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:
301
+
302
+
- Initiated using the `fetch` API
303
+
- First party domain (e.g if on `foo.com`, then `foo.com/api/products`, but not `bar.com/api/products`)
0 commit comments