You're in the right place! Segment documentation is now part of Twilio Docs. The content you are used to is still here—just in a new home with a refreshed look.
Analytics for Node.js Migration Guide
If you're using the classic version of Analytics Node.js (named analytics-node on npm), upgrade to the latest version of Analytics Node.js (named @segment/analytics-node on npm).
-
Change the named imports.
Before:import Analytics from 'analytics-node'After:
import { Analytics } from '@segment/analytics-node' -
Change instantiation to have an object as the first argument.
Before:var analytics = new Analytics('YOUR_WRITE_KEY');After:
const analytics = new Analytics({ writeKey: '<YOUR_WRITE_KEY>' }) -
Change flushing to graceful shutdown.
Before:1await analytics.flush((err, batch) => {2console.log('Flushed, and now this program can exit!');3});After:
await analytics.flush({ close: true })
-
The callback call signature changed.
Before:(err, batch) => voidAfter:
(err, ctx) => void -
The
enablesetting (for disabling analytics during tests) changed todisable.enable: falsechanged todisable: true.
The updated Analytics Node.js removed these configuration options:
errorHandler(see the docs on error handling for more information)
The updated Analytics Node.js library removed undocumented behavior around track properties
Before:
1analytics.track({2...3event: 'Ultimate Played',4myProp: 'abc'5})
After:
1analytics.track({2...3event: 'Ultimate Played',4properties: {5myProp: 'abc'6}7})