Miss any of our Open RFC calls?Watch the recordings here! »

windsor-node

1.0.0 • Public • Published

windsor-node

Send data for Windsor.io from Node

Get started

  1. Create a Windsor Account
  2. Setup the Node source
  3. Create Users on Windsor
    • With windsor-node, call windsor.user(...) everytime a new user signs up or data about a user changes to keep things updated
  4. Track Events
    • You'll want to see every important event or issue your user runs into. Call windsor.event(...) for every event you want to know a user has taken. You can setup alerts and more from Windsor

Read the docs here.

Why?

You care about your users. You probably already have a slack channel filling up with important events, or you search through logs to see what your users are upto. Windsor is a better way. Track the users and events you care about to Windsor so your company can more easily manage and understand your user behavior.

For example, you can create a new Windsor user from any Node app:

windsor.user({
  userId: "01nc83ns",
  traits: {
    name: "Pranay Prakash",
    email: "hey@windsor.io",
    company: "windsor",
    posts: 42,
  },
});

And track events you'd like to know your users took

windsor.event({
  userId: "01nc83ns",
  event: "Post Created",
  properties: {
    title: "Getting Started",
    private: false,
  },
});

Then follow the user on Windsor

Installation

$ yarn add windsor-node

Usage

const Windsor = require("windsor-node");
 
const windsor = new Windsor("token");
 
windsor.user({
  userId: "user id",
  traits: {
    name: "user name",
    email: "user email",
  },
});
 
windsor.event({
  event: "event name",
  userId: "user id",
});

Advanced Usage

windsor-node batches and sends multiple events together to improve performance on production systems. When using windsor-node on a serverless/lambda environment like AWS Lambda, Vercel or Serverless, you need to ensure that all events are sent before responding to the request.

const Windsor = require("windsor-node");
const windsor = new Windsor("token");
 
exports.handler = async (event) => {
  let greeting = "";
  if (event.queryStringParameters && event.queryStringParameters.greeting) {
    console.log("Received greeting: " + event.queryStringParameters.greeting);
    greeting = event.queryStringParameters.greeting;
  }
 
  // A promise is returned, but instead of using await here
  // we can send multiple analytics events and then await a single
  // call to windsor.flush() before returning the response
  windsor.event({
    event: "Sent Greeting",
    properties: {
      greeting,
    },
  });
 
  const message = `${greeting} World.`;
  const responseBody = { message };
  const response = {
    statusCode: 200,
    body: JSON.stringify(responseBody),
  };
 
  await windsor.flush();
  return response;
};

Documentation

Documentation is available at https://docs.windsor.io/docs/analytics

License

Copyright © 2020 Windsor Software Inc. <team@windsor.io>

See the LICENSE file for details and see the SEGMENT_LICENSE file attribution to the Segment Library this was based off.

Install

npm i windsor-node

DownloadsWeekly Downloads

21

Version

1.0.0

License

MIT

Unpacked Size

14.7 kB

Total Files

4

Last publish

Collaborators

  • avatar