Skip to content

Commit 4144486

Browse files
committed
edits
1 parent f217f61 commit 4144486

File tree

2 files changed

+16
-136
lines changed

2 files changed

+16
-136
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ title: Analytics for Node.js Classic
33
redirect_from: '/connections/sources/catalog/libraries/server/node-js/'
44
repo: analytics-node
55
strat: node-js
6+
hidden: true
67
---
78

89
> 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 Analytics Node.js 2.0. See the [Analytics Node.js 2.0] docs to learn more.
10+
> 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.
1011
1112
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.
1213

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

Lines changed: 14 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,6 @@ Be sure to replace `YOUR_WRITE_KEY` with your actual **Write Key** which you can
4141

4242
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).
4343

44-
### Regional configuration
45-
For Business plans with access to [Regional Segment](/docs/guides/regional-segment), you can use the `host` configuration parameter to send data to the desired region:
46-
1. Oregon (Default) — `api.segment.io/v1`
47-
2. Dublin — `events.eu1.segmentapis.com`
48-
49-
An example of setting the host to the EU endpoint using the Node library is:
50-
```javascript
51-
const analytics = new Analytics({
52-
...
53-
host: "https://events.eu1.segmentapis.com"
54-
});
55-
```
5644

5745
## Basic tracking methods
5846
The basic tracking methods below serve as the building blocks of your Segment tracking. They include [Identify](#identify), [Track](#track), [Page](#page), [Group](#group), and [Alias](#alias).
@@ -286,7 +274,7 @@ The `group` call has the following fields:
286274
</tr>
287275
<tr>
288276
<td>`traits` _dict, optional_</td>
289-
<td>A dict of traits you know about the group. For a company, they might be things like `name`, `address`, or `phone`.</td>
277+
<td>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).</td>
290278
</tr>
291279
<tr>
292280
<td>`context` _dict, optional_</td>
@@ -412,6 +400,19 @@ await analytics.closeAndFlush()
412400
console.log(unflushedEvents) // all events that came in after closeAndFlush was called
413401
```
414402

403+
## Regional configuration
404+
For Business plans with access to [Regional Segment](/docs/guides/regional-segment), you can use the `host` configuration parameter to send data to the desired region:
405+
1. Oregon (Default) — `api.segment.io/v1`
406+
2. Dublin — `events.eu1.segmentapis.com`
407+
408+
An example of setting the host to the EU endpoint using the Node library is:
409+
```javascript
410+
const analytics = new Analytics({
411+
...
412+
host: "https://events.eu1.segmentapis.com"
413+
});
414+
```
415+
415416
## Error handling
416417

417418
To keep track of errors, subscribe and log all event delivery errors by running:
@@ -486,13 +487,6 @@ const identityStitching = () => {
486487
type: 'enrichment',
487488
version: '0.1.0',
488489

489-
// use the `load` hook to bootstrap your plugin
490-
// The load hook will receive a context object as its first argument
491-
// followed by a reference to the analytics.js instance from the page
492-
load: async (_ctx, ajs) => {
493-
user = ajs.user()
494-
},
495-
496490
// Used to signal that a plugin has been property loaded
497491
isLoaded: () => user !== undefined,
498492

@@ -521,34 +515,6 @@ const identityStitching = () => {
521515
return identity
522516
}
523517

524-
// Registers Segment's new plugin into Analytics.js
525-
await window.analytics.register(identityStitching())
526-
```
527-
528-
Here's an example of a `utility` plugin that allows you to change the format of the anonymous_id cookie:
529-
530-
```js
531-
532-
window.analytics.ready(() => {
533-
window.analytics.register({
534-
name: 'Cookie Compatibility',
535-
version: '0.1.0',
536-
type: 'utility',
537-
load: (_ctx, ajs) => {
538-
const user = ajs.user()
539-
const cookieJar = user.cookies
540-
const cookieSetter = cookieJar.set.bind(cookieJar)
541-
542-
// blindly convert any values into JSON strings
543-
cookieJar.set = (key, value, opts) => cookieSetter(key, JSON.stringify(value), opts)
544-
545-
// stringify any existing IDs
546-
user.anonymousId(user.anonymousId())
547-
user.id(user.id())
548-
},
549-
isLoaded: () => true
550-
})
551-
})
552518
```
553519

554520
You can view Segment's [existing plugins](https://github.com/segmentio/analytics-next/tree/master/src/plugins){:target="_blank"} to see more examples.
@@ -560,16 +526,8 @@ Registering plugins enable you to modify your analytics implementation to best f
560526
// A promise will resolve once the plugins have been successfully loaded into Analytics.js
561527
// You can register multiple plugins at once by using the variable args interface in Analytics.js
562528
await window.analytics.register(pluginA, pluginB, pluginN)
563-
564-
## Development
565-
566-
You can use this initialization during development to make the library flush every time a message is submitted, so that you can be sure your calls are working properly before pushing to production.
567-
568-
```javascript
569-
var analytics = new Analytics('YOUR_WRITE_KEY', { flushAt: 1 });
570529
```
571530

572-
573531
## Selecting Destinations
574532

575533
The `alias`, `group`, `identify`, `page` and `track` calls can all be passed an object of `integrations` that lets you turn certain destinations on or off. By default all destinations are enabled.
@@ -650,85 +608,6 @@ analytics.flush(function(err, batch){
650608
});
651609
```
652610

653-
<!-- ## Long running process??
654-
655-
You should call `client.track(...)` and know that events will be queued and eventually sent to Segment. To prevent losing messages, be sure to capture any interruption (for example, a server restart) and call flush to know of and delay the process shutdown.
656-
657-
```js
658-
import { randomUUID } from 'crypto';
659-
import Analytics from 'analytics-node'
660-
661-
const WRITE_KEY = '...';
662-
663-
const analytics = new Analytics(WRITE_KEY, { flushAt: 10 });
664-
665-
analytics.track({
666-
anonymousId: randomUUID(),
667-
event: 'Test event',
668-
properties: {
669-
name: 'Test event',
670-
timestamp: new Date()
671-
}
672-
});
673-
674-
const exitGracefully = async (code) => {
675-
console.log('Flushing events');
676-
await analytics.flush(function(err, batch) {
677-
console.log('Flushed, and now this program can exit!');
678-
process.exit(code);
679-
});
680-
};
681-
682-
[
683-
'beforeExit', 'uncaughtException', 'unhandledRejection',
684-
'SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP',
685-
'SIGABRT','SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV',
686-
'SIGUSR2', 'SIGTERM',
687-
].forEach(evt => process.on(evt, exitGracefully));
688-
689-
function logEvery2Seconds(i) {
690-
setTimeout(() => {
691-
console.log('Infinite Loop Test n:', i);
692-
logEvery2Seconds(++i);
693-
}, 2000);
694-
}
695-
696-
logEvery2Seconds(0);
697-
```
698-
699-
## Short lived process??
700-
701-
Short-lived functions have a predictably short and linear lifecycle, so use a queue big enough to hold all messages and then await flush to complete its work. -->
702-
703-
704-
<!-- ```js
705-
import { randomUUID } from 'crypto';
706-
import Analytics from 'analytics-node'
707-
708-
709-
async function lambda()
710-
{
711-
const WRITE_KEY = '...';
712-
const analytics = new Analytics(WRITE_KEY, { flushAt: 20 });
713-
analytics.flushed = true;
714-
715-
analytics.track({
716-
anonymousId: randomUUID(),
717-
event: 'Test event',
718-
properties: {
719-
name: 'Test event',
720-
timestamp: new Date()
721-
}
722-
});
723-
await analytics.flush(function(err, batch) {
724-
console.log('Flushed, and now this program can exit!');
725-
});
726-
}
727-
728-
lambda();
729-
``` -->
730-
731-
732611
## Multiple Clients
733612

734613
Different parts of your application may require different types of batching, or even sending to multiple Segment sources. In that case, you can initialize multiple instances of `Analytics` with different settings:

0 commit comments

Comments
 (0)