2.0.1 • Published 9 years ago

segment.js v2.0.1

Weekly downloads
41
License
Apache-2.0
Repository
github
Last release
9 years ago

segment.js

NPM version

Segment.com client that works in the browser (browserify) and Node.js.

Installation

$ npm install segment.js

Usage

Create a Segment.com client:

var Segment = require('segment.js');

var analytics = new Segment({
    writeKey: "your-project-write-key"
});

Default options are:

{
    // Endpoint for the Segment.com API
    endpoint: 'https://api.segment.io/v1/',

    // Write key for your project
    writeKey: "",

    // The number of milliseconds to delay flushing events
    flushWait: 1000,

    // The maximum time flush is allowed to be delayed before it’s invoked
    flushMaxWait: 100
}
Identify

The identify method is how you tie one of your users to a recognizable userId and traits.

analytics.identify({
    userId: '1e810c197e',
    traits: {
        name: 'Bill Lumbergh',
        email: 'bill@initech.com'
    }
});
Track

The track method lets you record any actions your users perform. Here’s a basic example:

analytics.track({
    event: 'Signed Up',
    properties: {
        plan: 'Startup',
        source: 'Analytics Academy'
    }
});
Flush

You can manually flush events to Segment.com using the analytics.flush([sync]) method:

analytics.flush();

It's also possible in the browser to synchronously send events, for example:

window.onbeforeunload = function() {
    analytics.track('Page Closed');
    analytics.flush(true);
};
2.0.1

9 years ago

2.0.0

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago