npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kiteco/customerio-node

v0.6.0

Published

A node client for the Customer.io event API. http://customer.io

Downloads

3

Readme

Customerio CircleCI

A node client for the Customer.io REST API.

Installation

npm i --save customerio-node

Usage

Creating a new instance

In order to start using the library, you first need to create an instance of the CIO class:

let CIO = require('customerio-node');
const cio = new CIO(siteId, apiKey);

Both the siteId and apiKey are required in order to create a Basic Authorization header, allowing us to associate the data with your account.


cio.identify(id, data)

Creating a person is as simple as identifying them with this call. You can also use this method to update a persons data.

cio.identify(1, {
  email: '[email protected]',
  created_at: 1361205308,
  first_name: 'Bob',
  plan: 'basic'
});

Options

  • id: String (required)
  • data: Object (optional)
    • email is a required key if you intend to send email messages
    • created_at is a required key if you want to segment based on signed up/created date

cio.destroy(id)

This will delete a person from Customer.io.

cio.destroy(1);

Options

  • id: String (required)

cio.track(id, data)

The track method will trigger events within Customer.io. When sending data along with your event, it is required to send a name key/value pair in you data object.

Simple event tracking

cio.track(1, { name: 'updated' });

Sending data with an event

cio.track(1, {
  name: 'purchase',
  data: {
    price: '23.45',
    product: 'socks'
  }
});

Options

  • id: String (requiredl)
  • data: Object (required)
    • name is a required key on the Object
    • data is an optional key for additional data sent over with the event

cio.trackAnonymous(data)

Anonymous event tracking does not require a customer ID and these events will not be associated with a tracked profile in Customer.io

cio.trackAnonymous({
  name: 'updated',
  data: {
    updated: true,
    plan: 'free'
  }
});

Options

  • data: Object (required)
    • name is a required key on the Object
    • data is an optional key for additional data sent over with the event

cio.trackPageView(id, url)

Sending a page event includes sending over the customers id and the name of the page.

cio.trackPageView(1, '/home');

Options

  • id: String (required)
  • url: String (required)

cio.triggerBroadcast(campaign_id, data, recipients)

Trigger an email broadcast using the email campaign's id. You can also optionally pass along custom data that will be merged with the liquid template, and additional conditions to filter recipients.

cio.triggerBroadcast(1, { name: 'foo'}, { segment: { id: 7 }});

You can also use emails or ids to select recipients, and pass optional API parameters such as email_ignore_missing.

cio.triggerBroadcast(1, { name: 'foo'},  { emails: ['[email protected]'], email_ignore_missing: true }
);

You can learn more about the recipient fields available here.

Options

  • id: String (required)
  • data: Object (optional)
  • recipients: Object (optional)

cio.addDevice(id, device_id, platform, data)

Add a device to send push notifications.

cio.addDevice(1, "device_id", "ios", { primary: true });

Options

  • customer_id: String (required)
  • device_id: String (required)
  • platform: String (required)
  • data: Object (optional)

cio.deleteDevice(id, device_id)

Delete a device to remove it from the associated customer and stop sending push notifications to it.

cio.deleteDevice(1, "device_token")

Options

  • customer_id: String (required)
  • device_token: String (required)

cio.addToSegment(id, customer_ids)

Add customers to a manual segment.

cio.addToSegment(1, ["1", "2", "3"])

Options

  • segment_id: String (required)
  • customer_ids: Array (required)

cio.removeFromSegment(id, customer_ids)

Remove customers from a manual segment.

cio.removeFromSegment(1, ["1", "2", "3"])

Options

  • segment_id: String (required)
  • customer_ids: Array (required)

Using Promises

All calls to the library will return a native promise, allowing you to chain calls as such:

const customerId = 1;

cio.identify(customerId, { first_name: 'Finn' }).then(() => {
  return cio.track(customerId, {
    name: 'updated',
    data: {
      updated: true,
      plan: 'free'
    }
  });
});

Further examples

We've included functional examples in the examples/ directory of the repo to further assist in demonstrating how to use this library to integrate with Customer.io

Tests

npm install && npm test

License

Released under the MIT license. See file LICENSE for more details.