Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

analytics-node

segmentio1.2mMIT6.2.0TypeScript support: definitely-typed

The hassle-free way to integrate analytics into any Node.js application

analytics, stats, segment.io, segmentio, segment, client, driver

readme

analytics-node CircleCI

A Node.js client for Segment — The hassle-free way to integrate analytics into any application.

You can't fix what you can't measure

Analytics helps you measure your users, product, and business. It unlocks insights into your app's funnel, core business metrics, and whether you have product-market fit.

How to get started

  1. Collect analytics data from your app(s).
    • The top 200 Segment companies collect data from 5+ source types (web, mobile, server, CRM, etc.).
  2. Send the data to analytics tools (for example, Google Analytics, Amplitude, Mixpanel).
    • Over 250+ Segment companies send data to eight categories of destinations such as analytics tools, warehouses, email marketing and remarketing systems, session recording, and more.
  3. Explore your data by creating metrics (for example, new signups, retention cohorts, and revenue generation).
    • The best Segment companies use retention cohorts to measure product market fit. Netflix has 70% paid retention after 12 months, 30% after 7 years.

Segment collects analytics data and allows you to send it to more than 250 apps (such as Google Analytics, Mixpanel, Optimizely, Facebook Ads, Slack, Sentry) just by flipping a switch. You only need one Segment code snippet, and you can turn integrations on and off at will, with no additional code. Sign up with Segment today.

Why?

  1. Power all your analytics apps with the same data. Instead of writing code to integrate all of your tools individually, send data to Segment, once.

  2. Install tracking for the last time. We're the last integration you'll ever need to write. You only need to instrument Segment once. Reduce all of your tracking code and advertising tags into a single set of API calls.

  3. Send data from anywhere. Send Segment data from any device, and we'll transform and send it on to any tool.

  4. Query your data in SQL. Slice, dice, and analyze your data in detail with Segment SQL. We'll transform and load your customer behavioral data directly from your apps into Amazon Redshift, Google BigQuery, or Postgres. Save weeks of engineering time by not having to invent your own data warehouse and ETL pipeline.

    For example, you can capture data on any app:

     analytics.track({ userId: '019mr8mf4r', event: 'Order Completed', properties: { price: 99.84 }});

    Then, query the resulting data in SQL:

     select * from app.order_completed
     order by price desc

🚀 Startup Program

If you are part of a new startup (<$5M raised, <2 years since founding), we just launched a new startup program for you. You can get a Segment Team plan (up to $25,000 value in Segment credits) for free up to 2 years — apply here!

Installation

$ npm install analytics-node

Usage

const Analytics = require('analytics-node');

const client = new Analytics('write key');

client.track({
  event: 'event name',
  userId: 'user id'
});

Notes

Defining sentAt in the payload will cause the specified timestamp to be ignored

Documentation

Documentation is available at https://segment.com/libraries/node.

License

Copyright © 2017 Segment Inc. <friends@segment.com>

changelog

v6.1.0 / 2022-07-13

  • Add an errorHandler property to constructor options (#342)
  • Add sentAt note to readme (#340)
  • Update library axios to 0.27.2 (#339)
  • Update code snippet to match analyics-code API (#321)
  • Error thrown in callback function is caught by flush's promise .catch() (#317)
  • Fix callback called twice (#315)
  • Automated dependency upgrades

v6.0.0 / 2021-11-19

  • Change flush threshold from 500kb to 450kb #311
  • Breaking: Flush now properly returns a Promise #288

v5.1.1 / 2021-10-20

  • axios-retry update

v5.1.0 / 2021-9-13

  • Added options for axiosRetryConfig, disable axiosRetry if retryCount is 0 (#285)
  • Optimize timer scheduling (#172)
  • Update Axios to fix a ReDoS vulnerability (#295)
  • Automated dependency upgrades

v5.0.0 / 2021-7-16

  • BREAKING: Dropping support for Node 8.0!
  • Flush the queue when maximum storage has reached (#277)
  • Return a promise from flush (#281)
  • Upgrade uuid package to support treeshaking (#273)
  • Dependency upgrades

v4.0.1 / 2021-2-24

  • Fixed an issue where the optional axiosInstance passed as an option was ignored

v4.0.0 / 2021-2-17

  • BREAKING: throws error when message is over 32kb #268
  • Allow passing in Axios instance in options #270
  • Fix data parameter always undefined on callback for track method #231
  • Allow to update endpoint to send batch events #246
  • Vulnerability fixes #264, #243, #263, #226, #227, #228, #247, #248, #252, #253, #257, #261
  • Fixed a typo to reflect actual code behaviour #233

v3.5.0 / 2021-1-5

  • Update axios to fix the Server-Side Request Forgery vulnerability (#259)

v3.4.1-beta.3 / 2020-10-26

  • Update axios to fix the infinite retry bug (#255)
  • Use a local instance of axios to prevent client options leaking to other contexts (#255)

v3.4.1-beta.2 / 2020-06-10

  • Update lodash (#222) (#221) from segmentio/dependabot/npm_and_yarn/lodash-4.17.11 8e9a91d
  • Fix typo (#220)
  • Update axios (#218)

v3.4.1-beta.1 / 2019-06-20

v3.4.0-beta / 2019-06-12

  • Due to a bug in the release step, this version was not published to NPM. It was instead re-published as v3.4.1-beta.1.

v3.3.0 / 2018-04-24

  • Promote v3.3.0-beta.2 to stable

v3.3.0-beta.2 / 2018-03-02

  • New: Add enable API to disable client from sending messages. This is useful for testing.
  • Improvement: Log when messages exceed our size limits.

v3.3.0-beta.1 / 2018-01-18

  • Improvement: Replace crypto-token with uuid package. This also reduces the total size of the package in the browser by 80%. Note that this will change the structure of the generated messageId values.
  • Improvement: Improve retry logic to better handle server failures.
  • Improvement: Update the user agent format to be RFC 7231 compliant.

v3.0.0 / 2017-07-27

  • Flush on first message (#113)
  • Rename flushAfter to flushInterval (#112)
  • remove caching of dependencies on Circle CI
  • improve readme
  • rename README to readme
  • add license
  • disable npm package locks
  • improve package.json
  • moves files into root
  • remove Makefile in favor of npm scripts
  • remove yarn.lock
  • remove History.md in favor of gh releases
  • add editorconfig
  • Convert to ES6 (#110)
  • Remove continuous deployment (#109)
  • Switch from Mocha to AVA (#108)
  • Skip data in flush callbacks (#105)
  • Reset timer on flush (#103)
  • Remove superagent-retry module (#107)
  • Remove browserify build (#104)
  • Update README.md

2.4.1 / 2017-05-05

  • Preventing webpack to bundle all lodash lib (#94)
  • README: fix header
  • README: fix badge
  • package: upgrade dependencies (#89)
  • standard (#88)
  • yarn (#85)
  • analytics-node.js@2.4.0 [ci skip]

2.4.0 / 2017-03-13

  • test: add _metadata to "screen" assertion (#87)
  • replace Travis with CircleCI (#86)
  • add support for screen events (#82)
  • use correct optional syntax for JSDOC (#83)

2.3.0 / 2017-03-13

  • Add node version to messages via _metadata (#84)
  • remove trailing slash on .host (#81)

2.2.0 / 2017-02-06

  • Replace validation with @segment/loosely-validate-event
  • add releasing notes

2.1.1 / 2017-01-31

  • Merge pull request #74 from alexstrat/master
  • Update dependencies

2.1.0 / 2016-03-31

  • adding a cli

2.0.2 / 2016-03-03

  • updating travis.yml
  • increase messageId entropy, and include one id per message

2.0.1 / 2015-12-11

  • makefile: changing bin paths and nsp target
  • Upgraded vulnerable dependencies and minor change in the tests to support them
  • Adding Node Security Project support

2.0.0 / 2015-09-21

  • update analytics-node.js
  • Remove proxy support
  • Merge pull request #47 from yorkie/patch-1
  • remove the duplicated keyword

1.2.2 / 2015-03-19

  • Update analytics-node.js

1.2.1 / 2015-03-19

  • Try to retry a few times before responding

1.2.0 / 2015-02-18

  • add browserify support
  • Add installation instructions to readme

1.1.1 / 2015-02-03

  • Add sentAt

1.l.0 - 2014-08-22

  • add: proxy requests

    1.0.4 - 2014-08-14

  • fix: given contexts to extended and not wiped out

    1.0.3 - 2014-08-05

  • fix: context data being added to messages

    1.0.2 - 2014-07-23

  • update: debug dependency

    0.6.0 - February 19, 2014


  • add group method