Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@amplitude/analytics-node
Advanced tools
@amplitude/analytics-node is an npm package that allows you to integrate Amplitude's analytics capabilities into your Node.js applications. It provides functionalities for tracking events, identifying users, and setting user properties, which can help you understand user behavior and improve your product.
Track Events
This feature allows you to track events that occur in your application. The code sample demonstrates how to log a 'user_signup' event with associated properties.
const amplitude = require('@amplitude/analytics-node');
const client = amplitude.init('YOUR_API_KEY');
client.logEvent({
event_type: 'user_signup',
user_id: 'user123',
event_properties: {
plan: 'premium'
}
});
Identify Users
This feature allows you to identify users and set their properties. The code sample shows how to identify a user and set their email and name.
const amplitude = require('@amplitude/analytics-node');
const client = amplitude.init('YOUR_API_KEY');
client.identify({
user_id: 'user123',
user_properties: {
$set: {
email: 'user@example.com',
name: 'John Doe'
}
}
});
Set User Properties
This feature allows you to set or update properties for a user. The code sample demonstrates how to set the age and gender properties for a user.
const amplitude = require('@amplitude/analytics-node');
const client = amplitude.init('YOUR_API_KEY');
client.identify({
user_id: 'user123',
user_properties: {
$set: {
age: 30,
gender: 'male'
}
}
});
Mixpanel is a powerful analytics tool that helps you track user interactions with web and mobile applications. It offers similar functionalities to @amplitude/analytics-node, such as event tracking, user identification, and setting user properties. Mixpanel also provides advanced features like A/B testing and user segmentation.
Segment is a customer data platform that allows you to collect, clean, and control your customer data. It provides functionalities for tracking events, identifying users, and setting user properties, similar to @amplitude/analytics-node. Segment also integrates with a wide range of other analytics and marketing tools, making it a versatile choice for managing customer data.
Heap is an analytics platform that automatically captures all user interactions with your web and mobile applications. It offers functionalities similar to @amplitude/analytics-node, such as event tracking and user identification. Heap's unique selling point is its ability to retroactively analyze data without requiring manual event tracking.
Official Amplitude SDK for Node.js
See our Typescript Analytics Node SDK Reference for a list and description of all available SDK methods.
Please visit our :100:Developer Center for instructions on installing and using our the SDK.
To get started with using Amplitude Node.js SDK, install the package to your project via NPM.
This package is published on NPM registry and is available to be installed using npm and yarn.
# npm
npm install @amplitude/analytics-node
# yarn
yarn add @amplitude/analytics-node
Initialization is necessary before any instrumentation is done. The API key for your Amplitude project is required.
amplitude.init(API_KEY);
Events represent how users interact with your application. For example, "Button Clicked" may be an action you want to note.
import { track } from '@amplitude/analytics-node';
// Track a basic event
track('Button Clicked', undefined, {
user_id: 'user@amplitude.com',
});
// Track events with additional properties
const eventProperties = {
selectedColors: ['red', 'blue'],
};
track('Button Clicked', eventProperties, {
user_id: 'user@amplitude.com',
});
User properties help you understand your users at the time they performed some action within your app such as their device details, their preferences, or language.
import { Identify, identify } from '@amplitude/analytics-node';
const event = new Identify();
// sets the value of a user property
event.set('key1', 'value1');
// sets the value of a user property only once
event.setOnce('key1', 'value1');
// increments a user property by some numerical value.
event.add('value1', 10);
// pre inserts a value or values to a user property
event.preInsert('ab-tests', 'new-user-test');
// post inserts a value or values to a user property
event.postInsert('ab-tests', 'new-user-test');
// removes a value or values to a user property
event.remove('ab-tests', 'new-user-test')
// sends identify event
identify(event);
import { setGroup } from '@amplitude/analytics-node';
// set group with single group name
setGroup('orgId', '15');
// set group with multiple group names
setGroup('sport', ['soccer', 'tennis']);
This feature is only available to Growth and Enterprise customers who have purchased the Accounts add-on.
Use the Group Identify API to set or update properties of particular groups. However, these updates will only affect events going forward.
import { Identify, groupIdentify } from '@amplitude/analytics-node';
const groupType = 'plan';
const groupName = 'enterprise';
const identity = new Identify()
identity.set('key1', 'value1');
groupIdentify(groupType, groupName, identity);
Revenue instances will store each revenue transaction and allow you to define several special revenue properties (such as 'revenueType', 'productIdentifier', etc.) that are used in Amplitude's Event Segmentation and Revenue LTV charts. These Revenue instance objects are then passed into revenue
to send as revenue events to Amplitude. This allows us to automatically display data relevant to revenue in the platform. You can use this to track both in-app and non-in-app purchases.
import { Revenue, revenue } from '@amplitude/analytics-node';
const event = new Revenue()
.setProductId('com.company.productId')
.setPrice(3.99)
.setQuantity(3);
revenue(event);
All asynchronous API are optionally awaitable through a specific Promise interface. This also serves as callback interface.
// Using async/await
const results = await track('Button Clicked').promise;
result.event; // {...} (The final event object sent to Amplitude)
result.code; // 200 (The HTTP response status code of the request.
result.message; // "Event tracked successfully" (The response message)
// Using promises
track('Button Clicked').promise.then((result) => {
result.event; // {...} (The final event object sent to Amplitude)
result.code; // 200 (The HTTP response status code of the request.
result.message; // "Event tracked successfully" (The response message)
});
FAQs
Official Amplitude SDK for NodeJS
The npm package @amplitude/analytics-node receives a total of 66,937 weekly downloads. As such, @amplitude/analytics-node popularity was classified as popular.
We found that @amplitude/analytics-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 21 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.