Node.js (Sources)

  • Sources & SDKs

Getting Started

This library lets you record all analytics data from your node code. You can check out it's open source code here. You can use this library in your web server controller code. It is high-performing in that it uses an internal queue to make identify and track calls non-blocking and fast. It also batches messages and flushes asynchronously to our servers.

Step 1

Install the astronomer npm module.

npm install --save analytics-node

Step 2

Initialize this package with the Source ID found in the settings section of your MetaRouter account.

var Analytics = require('analytics-node')
var analytics = new Analytics('METAROUTER_SOURCE_ID', { host: '' })

Step 3

Set your event methods (identify, track, etc.) throughout your app.

Note: We've standardized to Analytics.js. If you've used a tool like Segment in the past, you will find that instrumenting events in MetaRouter works in the exact same way.

Calls in Node.js

Check out the below calls and their use cases to determine the calls that you need to make. We have also included examples of how you'd call specific objects in node.js.


The identify method helps you associate your users and their actions to a unique and recognizable userID and any optional traits that you know about them. We recommend calling an identify a single time - when the user's account is first created and only again when their traits change.

  userId: '1234qwerty',
  traits: {
    name: 'Arthur Dent',
    email: '',
    hasTowel: True,


To get to a more complete event tracking analytics setup, you can add a track call to your website. This will tell MetaRouter which actions you are performing on your site. With track, each user action triggers an “event,” which can also have associated properties.

  userId: '1234qwerty',
  event: 'Added File',
  properties: {
    fileTitle: 'Life, the Universe, and Everything',
    fileSize: '42kb',
    fileType: 'PDF',


The page method allows you to record page views on your website. It also allows you to pass addtional information about the pages people are viewing.{
  userId: '1234qwerty',
  section: 'Blog',
  name: '10 Questions with Marvin, the clinically depressed robot',
  properties: {
    referrer: '',


The group method associates an identified user with a company, organization, project, etc.{
  userId: '1234qwerty',
  groupId: '5678dvorak',
  traits: {
    name: 'The Hitchhikers',
    relativePosition: '[39.1000° N, 84.5167° W]"',


The alias method combines two unassociated User IDs.

  previousId: anonymous_id,
  userId: assigned_id_or_email,

© 2020 MetaRouter

Disclaimer: MetaRouter Cloud leverages code from several of Segment's fabulous library of open-source tools, including their source SDKs, destinations, and core Analytics.js library. As some of the core configurations outlined in our docs are largely identical to Segment's, we often re-purpose, and in some cases copy, directly from Segment's docs. In the cases where we have forked Segment's tools, we acknowledge and attribute all credit to Segment for their creation and subsequent documentation.