analytics-node
Advanced tools
Comparing version 0.2.6 to 0.2.7
@@ -140,3 +140,3 @@ var _ = require('underscore'), | ||
traits : traits, | ||
context : context, | ||
context : _.extend(context, {library: 'analytics-node'}), | ||
@@ -216,3 +216,3 @@ promise : promise | ||
properties : properties || {}, | ||
context : _.extend(context, {library: 'analytics-node'}), | ||
promise : promise | ||
@@ -356,3 +356,3 @@ }; | ||
else if (response.statusCode !== 200) | ||
return done(new Error((body && body.message) || | ||
return done(new Error((body && body.error && body.error.message) || | ||
'Server error: ' + JSON.stringify(body))); | ||
@@ -359,0 +359,0 @@ else |
@@ -14,3 +14,3 @@ | ||
*/ | ||
host : 'https://api2.segment.io', | ||
host : 'https://api.segment.io', | ||
@@ -17,0 +17,0 @@ /** |
{ | ||
"name": "analytics-node" | ||
, "version": "0.2.6" | ||
, "version": "0.2.7" | ||
, "description": "The hassle-free way to integrate analytics into any node application." | ||
@@ -5,0 +5,0 @@ , "repository": "git://github.com/segmentio/analytics-node" |
analytics-node | ||
============== | ||
analytics-node is a node.js client for [Segment.io](https://segment.io). It's the sister API of the popular [analytics.js](https://github.com/segmentio/analytics.js). | ||
analytics-node is a node.js client for [Segment.io](https://segment.io). If you're using client-side javascript, check out [analytics.js](https://github.com/segmentio/analytics.js). | ||
### Node Analytics Made Simple | ||
[Segment.io](https://segment.io) is the simplest way to integrate analytics into your application. One API allows you to turn on any other analytics service. No more learning new APIs, repeated code, and wasted development time. | ||
[Segment.io](https://segment.io) is the cleanest, simplest API for recording analytics data. | ||
Setting up a new analytics solution can be a real pain. The APIs from each analytics provider are slightly different in odd ways, code gets messy, and developers waste a bunch of time fiddling with long-abandoned client libraries. We want to save you that pain and give you an clean, efficient, extensible analytics setup. | ||
[Segment.io](https://segment.io) wraps all those APIs in one beautiful, simple API. Then we route your analytics data wherever you want, whether it's Google Analytics, Mixpanel, Customer io, Chartbeat, or any of our other integrations. After you set up Segment.io you can swap or add analytics providers at any time with a single click. You won't need to touch code or push to production. You'll save valuable development time so that you can focus on what really matters: your product. | ||
```javascript | ||
@@ -18,5 +22,5 @@ var analytics = require('analytics-node'); | ||
![](http://img62.imageshack.us/img62/892/logosls.png) | ||
![](http://i.imgur.com/YnBWI.png) | ||
... and many more. | ||
More on integrations [here](#integrations). | ||
@@ -29,4 +33,2 @@ ### High Performance | ||
### Feedback | ||
[Feedback is very welcome!](mailto:friends@segment.io) | ||
@@ -49,5 +51,5 @@ | ||
var analytics = require('analytics-node'); | ||
analytics.init({secret: 'MY_API_SECRET'}}); | ||
analytics.init({secret: 'YOUR_API_SECRET'}); | ||
``` | ||
Then whenever you `require('analytics-node')` from any other file your app, you'll have access to the same client. | ||
Then whenever you `require('analytics-node')` from any other file in your app, you'll have access to the same client. | ||
@@ -80,10 +82,9 @@ #### Identify a User | ||
sessionId : 'DKGXt384hFDT82D', | ||
userId : 'ilya@segment.io', | ||
userId : '019mr8mf4r', | ||
traits : { | ||
firstName : 'Ilya', | ||
lastName : 'Volodarsky', | ||
name : 'Achilles', | ||
email : 'achilles@segment.io' | ||
subscriptionPlan : 'Premium', | ||
onMailingList : true | ||
}, | ||
timestamp : new Date('2012-12-02T00:30:08.276Z') | ||
friendCount : 29 | ||
} | ||
}); | ||
@@ -121,11 +122,9 @@ | ||
analytics.track({ | ||
sessionId : 'DKGXt384hFDT82D', | ||
userId : 'ilya@segment.io', | ||
event : 'Listened to a song', | ||
sessionId : 'DKGXt384hFDT82D', | ||
userId : '019mr8mf4r', | ||
event : 'Listened to a song', | ||
properties : { | ||
'Title': 'Eleanor Rigby', | ||
'Artist': 'Beatles', | ||
'Playlist': 'Popular' | ||
}, | ||
timestamp: new Date('2012-12-02T00:30:08.276Z') | ||
revenue : 39.95, | ||
shippingMethod : '2-day' | ||
} | ||
}); | ||
@@ -136,5 +135,21 @@ ``` | ||
## Integrations | ||
There are two main modes of analytics integration: client-side and server-side. You can use just one, or both. | ||
#### Client-side vs. Server-side | ||
* **Client-side analytics** - (via [analytics.js](https://github.com/segmentio/analytics.js)) works by loading in other integrations | ||
in the browser. | ||
* **Server-side analytics** - (via [analytics-node](https://github.com/segmentio/analytics-node) and other server-side libraries) works | ||
by sending the analytics request to [Segment.io](https://segment.io). Our servers then route the message to your desired integrations. | ||
Some analytics services have REST APIs while others only support client-side integrations. | ||
You can learn which integrations are supported server-side vs. client-side on your [project's integrations]((https://segment.io) page. | ||
## Advanced | ||
#### Batching Behavior | ||
### Batching Behavior | ||
@@ -192,3 +207,3 @@ By default, the client will flush: | ||
promise.on('flush', function () { | ||
console.log('I'm 2000 miles away now!') | ||
console.log("I'm 2000 miles away now!"); | ||
}); | ||
@@ -214,3 +229,3 @@ | ||
#### Error Handling | ||
### Error Handling | ||
@@ -228,5 +243,5 @@ In order to handle errors, the node client will emit every time an error occurs. To prevent analytics-node from crashing your server with an unhandled exception, it emits on `err` rather than the more conventional `error`. | ||
#### Other Events | ||
### Events | ||
You may also listen on the following events for more granular information. | ||
You may also listen on `analytics` variable for the following events: | ||
@@ -237,3 +252,3 @@ * **initialize** - when the client is initialized and able to record events. | ||
#### Understanding the Client Options | ||
### Understanding the Client Options | ||
@@ -257,9 +272,9 @@ If you hate defaults, than you'll love how configurable the analytics-node is. | ||
**flushAt** (Number) - Flush after this many messages are in the queue. | ||
**flushAfter** (Number) - Flush after this many milliseconds have passed since the last flush. | ||
**maxQueueSize** (Number) - Stop accepting messages into the queue after this many messages are backlogged in the queue. | ||
**timerInterval** (Number) - Check this many milliseconds to see if there's anything to flush. | ||
**triggers** (Array[Function]) - An array of trigger functions that determine when it's time to flush. | ||
* **flushAt** (Number) - Flush after this many messages are in the queue. | ||
* **flushAfter** (Number) - Flush after this many milliseconds have passed since the last flush. | ||
* **maxQueueSize** (Number) - Stop accepting messages into the queue after this many messages are backlogged in the queue. | ||
* **timerInterval** (Number) - Check this many milliseconds to see if there's anything to flush. | ||
* **triggers** (Array[Function]) - An array of trigger functions that determine when it's time to flush. | ||
#### Multiple Clients | ||
### Multiple Clients | ||
@@ -279,3 +294,3 @@ Different parts of your app may require different types of batching. In that case, you can initialize different `analytic-node` client instances. The API is exactly the same. | ||
#### License | ||
## License | ||
@@ -282,0 +297,0 @@ ``` |
module.exports = { | ||
host : 'https://api2.segment.io', | ||
host : 'https://api.segment.io', | ||
secret : 'testsecret', | ||
@@ -6,0 +6,0 @@ |
33005
567
307