The `amplitude` package provides a server-side Node.js wrapper for Amplitude's HTTP API, facilitating event tracking and user identification. Currently at stable version 6.0.0, this library integrates with Amplitude's V2 HTTP API for sending analytics data. It supports both individual event tracking and batch submissions, and includes functionality for Amplitude's Identify API to manage user properties without event logging. A notable feature is its built-in handling for Amplitude's past SSL certificate issues, allowing users to configure an alternative endpoint if needed. The package ships with TypeScript type definitions, ensuring type safety for TypeScript projects. While its release cadence isn't extremely rapid, updates address API changes and maintain compatibility with modern Node.js environments.
npm install amplitudeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the Amplitude client, track a single user event, and update user properties using the Identify API. It emphasizes using environment variables for the API token.
Consult Amplitude's HTTP API V2 documentation for required fields and data format. Specifically, ensure `event_type` and either `user_id` or `device_id` are present.
Ensure all `user_id` and `device_id` values passed to `amplitude.track()` or `amplitude.identify()` are at least 5 characters long.
If encountering connection issues, particularly SSL-related, try setting `AMPLITUDE_TOKEN_ENDPOINT='https://api2.amplitude.com'` environment variable or passing `{ tokenEndpoint: 'https://api2.amplitude.com' }` to the `Amplitude` constructor.Ensure that every event payload includes either a `user_id` or a `device_id`, and that its value is a string of 5 or more characters. Example: `user_id: 'user-abcde'`.
Add an `event_type` string to your event data object, e.g., `{ event_type: 'Product Viewed' }`.For ESM, use `import { Amplitude } from 'amplitude';`. For CommonJS, use `const Amplitude = require('amplitude');`.No dependency data recorded yet.