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/classic.md
+22-22Lines changed: 22 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,13 @@ hidden: true
6
6
---
7
7
8
8
> warning "Deprecation of Analytics Node.js Classic"
9
-
> On [date], Segment will end support for Analytics Node.js Classic, which includes versions [1.x.x] and older. Upgrade to the new version of Analytics Node.js. See the updated [Analytics Node.js] docs to learn more.
9
+
> On April 1, 2023, Segment will end support for Analytics Node.js Classic, which includes versions 6.2.0 and older. Upgrade to the new version of Analytics Node.js. See the updated [Analytics Node.js docs](/docs/connections/sources/catalog/libraries/server/node) to learn more.
10
10
11
11
Segment's Node.js library lets you record analytics data from your node code. The requests hit Segment's servers, and then Segment routes your data to any destinations you have enabled.
12
12
13
13
The [Segment Node.js library is open-source](https://github.com/segmentio/analytics-node) on GitHub.
14
14
15
-
All of Segment's server-side libraries are built for high-performance, so you can use them in your web server controller code. This library uses an internal queue to make `identify` and `track` calls non-blocking and fast. It also batches messages and flushes asynchronously to our servers.
15
+
All of Segment's server-side libraries are built for high-performance, so you can use them in your web server controller code. This library uses an internal queue to make `identify` and `track` calls non-blocking and fast. It also batches messages and flushes asynchronously to Segment's servers.
16
16
17
17
Want to stay updated on releases? Subscribe to the [release feed](https://github.com/segmentio/analytics-node/releases.atom).
18
18
@@ -24,7 +24,7 @@ Run:
24
24
npm install --save analytics-node
25
25
```
26
26
27
-
This will add our Node library module to your `package.json`. The module exposes an `Analytics` constructor, which you need to initialize with your Segment source's **Write Key**, like so:
27
+
This will add Segment's Node library module to your `package.json`. The module exposes an `Analytics` constructor, which you need to initialize with your Segment source's **Write Key**, like so:
28
28
29
29
```javascript
30
30
var Analytics =require('analytics-node');
@@ -91,18 +91,18 @@ Field | Details
91
91
`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._
92
92
`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._
93
93
`traits`_Object, optional_ | A dictionary of [traits](/docs/connections/spec/identify#traits) you know about the user. Things like: `email`, `name` or `friends`.
94
-
`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`.
94
+
`timestamp`_Date, optional_ | A JavaScript date object representing when the identify call took place. If the identify just happened, leave it out as Segment will use the server's time. If you're importing data from the past make sure you to send a `timestamp`.
95
95
`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._
96
96
97
97
Find details on the **identify method payload** in the Segment [Spec](/docs/connections/spec/identify/).
98
98
99
99
## Track
100
100
101
-
`track` lets you record the actions your users perform. Every action triggers what we call an "event", which can also have associated properties.
101
+
`track` lets you record the actions your users perform. Every action triggers what Segment calls an "event", which can also have associated properties.
102
102
103
103
You'll want to track events that are indicators of success for your site, like **Signed Up**, **Item Purchased** or **Article Bookmarked**.
104
104
105
-
To get started, we recommend tracking just a few important events. You can always add more later!
105
+
To get started, Segment recommends tracking just a few important events. You can always add more later.
106
106
107
107
Example anonymous `track` call:
108
108
@@ -130,7 +130,7 @@ analytics.track({
130
130
});
131
131
```
132
132
133
-
This example `track` call tells us that your user just triggered the **Item Purchased** event with a revenue of $39.95 and chose your hypothetical '2-day' shipping.
133
+
This example `track` call tells that your user just triggered the **Item Purchased** event with a revenue of $39.95 and chose your hypothetical '2-day' shipping.
134
134
135
135
`track` event properties can be anything you want to record. In this case, revenue and shipping method.
136
136
@@ -140,9 +140,9 @@ Field | Details
140
140
----- | --------
141
141
`userId`_String, optional_ | The ID for this user in your database. _Note: at least one of `userId` or `anonymousId` must be included in any track call.
142
142
`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 track calls._
143
-
`event`_String_ | The name of the event you're tracking. We recommend human-readable names like `Song Played` or `Status Updated`.
143
+
`event`_String_ | The name of the event you're tracking. Segment recommends you use human-readable names like `Song Played` or `Status Updated`.
144
144
`properties`_Object, optional_ | A dictionary of properties for the event. If the event was `Product Added`, it might have properties like `price` or `product`.
145
-
`timestamp`_Date, optional_ | A JavaScript date object representing when the track took place. If the track 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`.
145
+
`timestamp`_Date, optional_ | A JavaScript date object representing when the track took place. If the track just happened, leave it out as Segment will use the server's time. If you're importing data from the past make sure you to send a `timestamp`.
146
146
`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._
147
147
148
148
Find details on **best practices in event naming** as well as the **`track` method payload** in the Segment [Spec](/docs/connections/spec/track/).
@@ -151,7 +151,7 @@ Find details on **best practices in event naming** as well as the **`track` meth
151
151
152
152
The [`page`](/docs/connections/spec/page/) method lets you record page views on your website, along with optional extra information about the page being viewed.
153
153
154
-
If you're using our client-side set up in combination with the Node.js library, page calls are **already tracked for you** by default. However, if you want to record your own page views manually and aren't using our client-side library, read on!
154
+
If you're using Segment's client-side set up in combination with the Node.js library, page calls are already tracked for you by default.
155
155
156
156
Example `page` call:
157
157
@@ -174,11 +174,11 @@ The `page` call has the following fields:
174
174
Field | Details
175
175
----- | --------
176
176
`userId`_String, optional_ | The ID for this user in your database. _Note: at least one of `userId` or `anonymousId` must be included in any page call.
177
-
`anonymousId`_String, optional_ | An ID associated with the user when you don't know who they are (eg., [the anonymousId generated by `analytics.js`](/docs/connections/sources/catalog/libraries/website/javascript/#anonymous-id)). _Note: at least one of `userId` or `anonymousId` must be included in any page call._
177
+
`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: at least one of `userId` or `anonymousId` must be included in any page call._
178
178
`category`_String, optional_ | The category of the page. Useful for things like ecommerce where many pages often live under a larger category.
179
179
`name`_String, optional_ | The name of the page, for example **Signup** or **Home**.
180
180
`properties`_Object, optional_ | A dictionary of properties of the page. A few properties specially recognized and automatically translated: `url`, `title`, `referrer` and `path`, but you can add your own too.
181
-
`timestamp`_Date, optional_ | A JavaScript date object representing when the track took place. If the track 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`.
181
+
`timestamp`_Date, optional_ | A JavaScript date object representing when the track took place. If the track just happened, leave it out as Segment will use the server's time. If you're importing data from the past make sure you to send a `timestamp`.
182
182
`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._
183
183
184
184
Find details on the **`page` payload** in the Segment [Spec](/docs/connections/spec/page/).
@@ -207,11 +207,11 @@ The `group` call has the following fields:
207
207
Field | Details
208
208
----- | --------
209
209
`userId`_String, optional_ | The ID for this user in your database. _Note: at least one of `userId` or `anonymousId` must be included in any group call.
210
-
`anonymousId`_String, optional_ | An ID associated with the user when you don't know who they are (eg., [the anonymousId generated by `analytics.js`](/docs/connections/sources/catalog/libraries/website/javascript/#anonymous-id)). _Note: at least one of `userId` or `anonymousId` must be included in any group call._
210
+
`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: at least one of `userId` or `anonymousId` must be included in any group call._
211
211
`groupId`_string | The ID of the group.
212
212
`traits`_dict, optional_ | A dict of traits you know about the group. For a company, they might be things like `name`, `address`, or `phone`. [Learn more about traits](/docs/connections/spec/group/#traits).
213
213
`context`_dict, optional_ | A dict containing any context about the request. To see the full reference of supported keys, check them out in the [context reference](/docs/connections/spec/common/#context)
214
-
`timestamp`_datetime, optional_ | A `datetime` object representing when the group took place. If the group just happened, leave it out and we'll use the server's time. If you're importing data from the past make sure you send `timestamp`.
214
+
`timestamp`_datetime, optional_ | A `datetime` object representing when the group took place. If the group just happened, leave it out as Segment uses the server's time. If you're importing data from the past make sure you send `timestamp`.
215
215
`integrations`_dict, optional_ | A dictionary of destinations to enable or disable.
216
216
217
217
Find more details about `group`, including the **`group` payload**, in the Segment [Spec](/docs/connections/spec/group/).
@@ -238,7 +238,7 @@ Field | Details
238
238
`userId`_String_ | The ID for this user in your database.
239
239
`previousId`_String_ | The previous ID to alias from.
240
240
241
-
Here's a full example of how we might use the `alias` call:
241
+
Here's a full example of how Segment might use the `alias` call:
For more details about `alias`, including the **`alias` call payload**, check out our[Spec](/docs/connections/spec/alias/).
254
+
For more details about `alias`, including the **`alias` call payload**, check out the[Spec](/docs/connections/spec/alias/).
255
255
256
256
---
257
257
@@ -327,13 +327,13 @@ analytics.track({
327
327
})
328
328
```
329
329
330
-
In this case, we're specifying that we want this`track` to only go to Vero. `All: false` says that no destination should be enabled unless otherwise specified. `Vero: true` turns on Vero, etc.
330
+
In this case, Segment specifies the`track` to only go to Vero. `All: false` says that no destination should be enabled unless otherwise specified. `Vero: true` turns on Vero, etc.
331
331
332
-
Destination flags are **case sensitive** and match [the destination's name in the docs](/docs/connections/destinations/) (i.e. "AdLearn Open Platform", "awe.sm", "MailChimp", etc.). In some cases, there may be several names for a destination; if that happens you'll see a "Adding (destination name) to the Integrations Object" section in the destination's doc page with a list of valid names.
332
+
Destination flags are **case sensitive** and match [the destination's name in the docs](/docs/connections/destinations/) (for example, "AdLearn Open Platform", "awe.sm", "MailChimp"). In some cases, there may be several names for a destination; if that happens you'll see a "Adding (destination name) to the Integrations Object" section in the destination's doc page with a list of valid names.
333
333
334
334
**Note:**
335
335
336
-
- Available at the business level, filtering track calls can be done right from the Segment UI on your source schema page. We recommend using the UI if possible since it's a much simpler way of managing your filters and can be updated with no code changes on your side.
336
+
- Available at the business level, filtering track calls can be done right from the Segment UI on your source schema page. Segment recommends using the UI if possible since it's a much simpler way of managing your filters and can be updated with no code changes on your side.
337
337
338
338
- If you are on a grandfathered plan, events sent server-side that are filtered through the Segment dashboard will still count towards your API usage.
339
339
@@ -343,16 +343,16 @@ You can import historical data by adding the `timestamp` argument to any of your
343
343
344
344
Historical imports can only be done into destinations that can accept historical timestamped data. Most analytics tools like Mixpanel, Amplitude, Kissmetrics, etc. can handle that type of data just fine. One common destination that does not accept historical data is Google Analytics since their API cannot accept historical data.
345
345
346
-
**Note:** If you're tracking things that are happening right now, leave out the `timestamp` and our servers will timestamp the requests for you.
346
+
**Note:** If you're tracking things that are happening right now, leave out the `timestamp` and Segment's servers will timestamp the requests for you.
347
347
348
348
349
349
## Batching
350
350
351
-
Our libraries are built to support high performance environments. That means it is safe to use our Node library on a web server that's serving hundreds of requests per second.
351
+
Segment's libraries are built to support high performance environments. That means it is safe to use the Segment Node library on a web server that's serving hundreds of requests per second.
352
352
353
353
Every method you call **does not** result in an HTTP request, but is queued in memory instead. Messages are then flushed in batch in the background, which allows for much faster operation.
354
354
355
-
By default, our library will flush:
355
+
By default, Segment's library flushes:
356
356
357
357
- The very first time it gets a message.
358
358
- Every 20 messages (controlled by `options.flushAt`).
Copy file name to clipboardExpand all lines: src/connections/sources/catalog/libraries/server/node/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ All of Segment's server-side libraries are built for high-performance, so you ca
13
13
14
14
> info "Using Analytics for Node.js Classic?"
15
15
> If you’re still using the classic version of Analytics for Node.js, you can refer to the documentation [here](/docs/connections/sources/catalog/libraries/server/node/classic).
16
-
> <br><br>On [date], Segment will end support for Analytics Node.js Classic, which includes versions [1.x.x] and older. Upgrade to Analytics Node.js 2.0. See the Analytics Node.js 2.0 docs to learn more.
16
+
> <br><br>On April 1, 2023, Segment will end support for Analytics Node.js Classic, which includes versions 6.2.0 and older. Upgrade to new Analytics Node.js. See the updated [Analytics Node.js quickstart guide](/docs/connections/sources/catalog/libraries/server/node/quickstart/) to learn more.
> warning "Deprecation of Analytics Node.js Classic"
8
-
> On [date], Segment will end support for Analytics Node.js Classic, which includes versions [1.x.x] and older. Upgrade to Analytics Node.js 2.0. See the [Analytics Node.js 2.0] docs to learn more.
8
+
> On [date], Segment will end support for [Analytics Node.js Classic](/docs/connections/sources/catalog/libraries/server/node/classic/), which includes versions [6.2.0] and older. Upgrade to Analytics Node.js 2.0. See the [Analytics Node.js 2.0] docs to learn more.
9
9
10
10
This tutorial will help you start sending data from your Node servers to Segment and any destination, using Segment's Node library. Check out the full documentation for [Analytics Node.js](/docs/connections/sources/catalog/libraries/server/node) to learn more.
11
11
@@ -17,19 +17,28 @@ To get started with Analytics Node.js:
17
17
4. Give the source a display name, and enter the URL the source will collect data from.
18
18
* When you create a Source in the Segment web app, it tells the Segment servers that you'll be sending data from a specific source type. When you create or change a Source in the Segment app, Segment generates a new Write Key for that source. You use the write key in your code to tell the Segment servers where the data is coming from, so Segment can route it to your destinations and other tools.
19
19
2. Install the module.
20
-
1. Run the following npm command to install Segment:
20
+
1. Run the following commands to install Segment:
21
21
```
22
-
npm install --save analytics-node
22
+
# npm
23
+
npm install @segment/analytics-node
24
+
# yarn
25
+
yarn add @segment/analytics-node
26
+
# pnpm
27
+
pnpm install @segment/analytics-node
23
28
```
24
29
25
30
This will add the Node library module to your `package.json`. The module exposes an `Analytics` constructor, which you need to initialize with your Segment project's **Write Key**, like so:
26
31
27
32
```javascript
28
-
var Analytics = require('analytics-node');
29
-
var analytics = new Analytics('YOUR_WRITE_KEY');
33
+
import { Analytics } from '@segment/analytics-node'
const analytics = new Analytics({ writeKey: '<YOUR_WRITE_KEY>' })
30
39
```
31
40
32
-
This will create 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).
41
+
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).
33
42
3. Identify Users.
34
43
35
44
* **Note:** For any of the different methods described in this quickstart, you can replace the properties and traits in the code samples with variables that represent the data collected.
0 commit comments