1npm install @june-so/analytics-node --save
To install the package from NPM into a server-side project, simply run:
1npm install @june-so/analytics-node --save
Now, you must configure the June SDK with a valid API key, which you can get from your June workspace.
1// Import June SDK: 2import Analytics from '@june-so/analytics-node'; 3 4// Instantiate the client: 5const analytics = new Analytics('YOUR_WRITE_KEY');
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 2analytics.identify({ 3userId: 'USER_ID', 4traits: { 5email: 'test@example.com', 6}, 7});
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 2analytics.group({ 3userId: 'USER_ID', 4groupId: 'GROUP_ID', 5traits: { 6name: 'Acme Inc', 7}, 8});
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 2analytics.track({ 3userId: 'USER_ID', 4event: 'Created Account', 5properties: { 6plan: 'Pro', 7}, 8context: { 9groupId: '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