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
Copy file name to clipboardExpand all lines: src/connections/sources/catalog/libraries/server/node/index.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ All of Segment's server-side libraries are built for high-performance, so you ca
19
19
> warning ""
20
20
> Make sure you're using a version of Node that's 14 or higher.
21
21
22
-
1. Run the following to add Segment's Node library module to your `package.json`.
22
+
1. Run the relevant command to add Segment's Node library module to your `package.json`.
23
23
24
24
```bash
25
25
# npm
@@ -43,7 +43,7 @@ All of Segment's server-side libraries are built for high-performance, so you ca
43
43
44
44
Be sure to replace `YOUR_WRITE_KEY` with your actual **Write Key** which you can find in Segment by navigating to: **Connections > Sources** and selecting your source and going to the **Settings** tab.
45
45
46
-
This creates an instance of `Analytics` that you can use to send data to Segment for your project. The default initialization settings are production-ready and queue 20 messages before sending any requests. In development you might want to use [development settings](/docs/connections/sources/catalog/libraries/server/node/#development).
46
+
This creates an instance of `Analytics` that you can use to send data to Segment for your project. The default initialization settings are production-ready and queue 20 messages before sending any requests.
47
47
48
48
49
49
## Basic tracking methods
@@ -96,7 +96,7 @@ Field | Details
96
96
`userId` _String, optional_ | The ID for this user in your database. _Note: at least one of `userId` or `anonymousId` must be included in any identify call._
97
97
`anonymousId` _String, optional_ | An ID associated with the user when you don't know who they are (for example, [the anonymousId generated by `analytics.js`](/docs/connections/sources/catalog/libraries/website/javascript/#anonymous-id)). _Note: You must include at least one of `userId` or `anonymousId` in all identify calls._
98
98
`traits` _Object, optional_ | A dictionary of [traits](/docs/connections/spec/identify#traits) you know about the user. Things like: `email`, `name` or `friends`.
99
-
`timestamp` _Date, optional_ | A JavaScript date object representing when the identify took place. If the identify just happened, leave it out and we'll use the server's time. If you're importing data from the past make sure you to send a `timestamp`.
99
+
`timestamp` _Date, optional_ | A JavaScript date object representing when the identify took place. If the identify just happened, leave it out as Segment uses the server's time. If you're importing data from the past make sure to send a `timestamp`.
100
100
`context` _Object, optional_ | A dictionary of extra [context](https://segment.com/docs/connections/spec/common/#context) to attach to the call. _Note: `context` differs from `traits` because it is not attributes of the user itself._
101
101
102
102
Find details on the **identify method payload**in Segment's [Spec](/docs/connections/spec/identify/).
When you develop against Analytics 2.0, the plugins you write can augment functionality, enrich data, and control the flow and delivery of events. From modifying event payloads to changing analytics functionality, plugins help to speed up the process of getting things done.
362
+
When you develop against [Analytics.js 2.0](/docs/connections/sources/catalog/libraries/website/javascript/), the plugins you write can augment functionality, enrich data, and control the flow and delivery of events. From modifying event payloads to changing analytics functionality, plugins help to speed up the process of getting things done.
363
363
364
364
Though middlewares functionthe same as plugins, it's best to use plugins as they are easier to implement and are more testable.
365
365
366
366
### Plugin categories
367
-
Plugins are bound by Analytics 2.0 which handles operations such as observability, retries, and error handling. There are two different categories of plugins:
367
+
Plugins are bound by Analytics.js 2.0 which handles operations such as observability, retries, and error handling. There are two different categories of plugins:
368
368
* **Critical Plugins**: Analytics.js expects this plugin to be loaded before starting event delivery. Failure to load a critical plugin halts event delivery. Use this category sparingly, and only for plugins that are critical to your tracking.
369
369
* **Non-critical Plugins**: Analytics.js can start event delivery before this plugin finishes loading. This means your plugin can fail to load independently from all other plugins. For example, every Analytics.js destination is a non-critical plugin. This makes it possible for Analytics.js to continue working if a partner destination fails to load, or if users have ad blockers turned on that are targeting specific destinations.
> This version of Analytics for Node.js is in beta and Segment is actively working on this feature. Segment's [First-Access and Beta terms](https://segment.com/legal/first-access-beta-preview/) govern this feature.
9
+
10
+
If you're using the [classic version of Analytics Node.js](/docs/connections/sources/catalog/libraries/server/node/classic), follow these steps to upgrade to the [latest version of Analytics Node.js](/connections/sources/catalog/libraries/server/node/).
11
+
12
+
1. Change the named imports.
13
+
14
+
<br> Before:
15
+
```javascript
16
+
importAnalyticsfrom'analytics-node'
17
+
```
18
+
19
+
After:
20
+
```javascript
21
+
import { Analytics } from '@segment/analytics-node'
22
+
```
23
+
2. Change instantiation to have an object as the first argument.
24
+
25
+
<br> Before:
26
+
```javascript
27
+
var analytics = new Analytics('YOUR_WRITE_KEY');
28
+
```
29
+
30
+
After:
31
+
```javascript
32
+
const analytics = new Analytics({ writeKey: '<MY_WRITE_KEY>' })
33
+
```
34
+
3. Change flushing to [graceful shutdown](/docs/connections/sources/catalog/libraries/server/node//#graceful-shutdown).
35
+
36
+
<br> Before:
37
+
```javascript
38
+
await analytics.flush(function(err, batch) {
39
+
console.log('Flushed, and now this program can exit!');
40
+
});
41
+
```
42
+
43
+
After:
44
+
```javascript
45
+
await analytics.closeAndFlush()
46
+
```
47
+
48
+
### Differences to note between the classic and updated version
49
+
50
+
* The callback call signature changed.
51
+
52
+
<br>Before:
53
+
```javascript
54
+
(err, batch) => void
55
+
```
56
+
57
+
After:
58
+
```javascript
59
+
(err, ctx) => void
60
+
```
61
+
* The `flushAt` configuration option changed to `maxEventsInBatch`.
62
+
63
+
#### Removals
64
+
The updated Analytics Node.js removed these configuration options:
65
+
-`enable`
66
+
-`errorHandler` (see the docs on [error handling](/docs/connections/sources/catalog/libraries/server/node//#error-handling) for more information)
67
+
68
+
The updated Analytics Node.js library removed undocumented behavior around `track` properties
0 commit comments