Skip to content

Commit 7edc2f3

Browse files
committed
edits [netlify-build]
1 parent b5d18b5 commit 7edc2f3

File tree

3 files changed

+100
-6
lines changed

3 files changed

+100
-6
lines changed

src/_data/sidenav/strat.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,7 @@ sections:
197197
title: Analytics-Node.js
198198
- path: /connections/sources/catalog/libraries/server/node/quickstart/
199199
title: Quickstart Node.js
200+
- path: /connections/sources/catalog/libraries/server/node/classic/
201+
title: Analytics-Node.js Classic
202+
- path: /connections/sources/catalog/libraries/server/node/migration/
203+
title: Analytics-Node.js Migration Guide

src/connections/sources/catalog/libraries/server/node/index.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ All of Segment's server-side libraries are built for high-performance, so you ca
1919
> warning ""
2020
> Make sure you're using a version of Node that's 14 or higher.
2121
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`.
2323

2424
```bash
2525
# npm
@@ -43,7 +43,7 @@ All of Segment's server-side libraries are built for high-performance, so you ca
4343
4444
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.
4545
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.
4747
4848
4949
## Basic tracking methods
@@ -96,7 +96,7 @@ Field | Details
9696
`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._
9797
`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._
9898
`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`.
100100
`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._
101101
102102
Find details on the **identify method payload** in Segment's [Spec](/docs/connections/spec/identify/).
@@ -359,12 +359,12 @@ analytics.on('track', (ctx) => console.log(ctx))
359359
```
360360
361361
## Plugin architecture
362-
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.
363363
364364
Though middlewares function the same as plugins, it's best to use plugins as they are easier to implement and are more testable.
365365
366366
### 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:
368368
* **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.
369369
* **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.
370370
@@ -455,7 +455,7 @@ await analytics.register(pluginA, pluginB, pluginC)
455455
Deregister a plugin by using:
456456
457457
```js
458-
await analytics.dereigsrer("pluginNameA", "pluginNameB") // takes strings
458+
await analytics.deregister("pluginNameA", "pluginNameB") // takes strings
459459
```
460460
461461
## Selecting Destinations
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: Analytics for Node.js Migration Guide
3+
repo: analytics-next
4+
strat: node-js
5+
---
6+
7+
> info ""
8+
> 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+
import Analytics from '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
69+
70+
Before:
71+
72+
```javascript
73+
analytics.track({
74+
...
75+
event: 'Ultimate Played',
76+
myProp: 'abc'
77+
})
78+
```
79+
80+
After:
81+
82+
```javascript
83+
analytics.track({
84+
...
85+
event: 'Ultimate Played',
86+
properties: {
87+
myProp: 'abc'
88+
}
89+
})
90+
```

0 commit comments

Comments
 (0)