Home
What is June?
Quick start

SDK Guides

Browser
React
Node.js
Python
Ruby
HTTP API
Log in

Node.js API

Instant insights from any Node app

Installing

To install the package from NPM into a server-side project, simply run:

1
npm install @june-so/analytics-node --save

Configuring

Now, you must configure the June SDK with a valid API key, which you can get from your June workspace.

1
// Import June SDK:
2
import Analytics from '@june-so/analytics-node';
3
4
// Instantiate the client:
5
const analytics = new Analytics('YOUR_WRITE_KEY');

Identifying users

You can use the identify method to identify your users. Replace USER_ID with the unique identifier for the user in your database.

1
// Send an identify call
2
analytics.identify({
3
userId: 'USER_ID',
4
traits: {
5
email: 'test@example.com',
6
},
7
});

Identifying companies (optional)

You can use the group method to identify your companies. Replace GROUP_ID and USER_ID with the unique identifier for the company and user in your database.

1
// Send a group call
2
analytics.group({
3
userId: 'USER_ID',
4
groupId: 'GROUP_ID',
5
traits: {
6
name: 'Acme Inc',
7
},
8
});

Send track events

In order to track user behaviour, you can use the track method.

Note: If you're identifying companies, you should pass the groupId in the track context, as shown in the example below. Replace GROUP_ID and USER_ID with the unique identifier for the company and user in your database.

1
// Send a track event
2
analytics.track({
3
userId: 'USER_ID',
4
event: 'Created Account',
5
properties: {
6
plan: 'Pro',
7
},
8
context: {
9
groupId: 'GROUP_ID',
10
},
11
});

Our SDK is based on Segment's SDK. You can find more documentation here: https://segment.com/docs/connections/sources/catalog/libraries/server/node