analytics-node
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -141,3 +141,43 @@ var _ = require('underscore'), | ||
/** | ||
* Identify a group. | ||
* | ||
* @param {Object} options | ||
*/ | ||
Client.prototype.group = function(options){ | ||
this._checkInitialized(); | ||
if (!_.isObject(options)) throw new TypeError('[analytics]#group: group must be an object'); | ||
if (!options.groupId) throw new Error('[analytics]#group: options.groupId is required'); | ||
if (!(options.userId || options.sessionId)) throw new Error('[analytics]#group: .userId or .sessionId is required'); | ||
if (options.timestamp && !_.isDate(options.timestamp)) { | ||
throw new Error('[analytics]#group: .timestamp must be provided as a date'); | ||
} | ||
var groupId = options.groupId; | ||
var userId = options.userId; | ||
var sessionId = options.sessionId; | ||
var traits = options.traits || {}; | ||
var context = options.context || {}; | ||
var timestamp = options.timestamp; | ||
var emitter = new events.EventEmitter; | ||
var message = { | ||
action: 'group', | ||
groupId: groupId, | ||
traits: traits, | ||
context: _.extend(context, { library: 'analytics-node' }), | ||
promise: emitter | ||
}; | ||
if (userId) message.userId = userId; | ||
if (sessionId) message.sessionId = sessionId; | ||
if (timestamp) message.timestamp = timestamp.toISOString(); | ||
this._enqueue(message); | ||
return emitter; | ||
}; | ||
/** | ||
@@ -144,0 +184,0 @@ * Whenever a user triggers an event, you’ll want to track it. |
@@ -14,3 +14,3 @@ | ||
var api = ['init', 'track', 'identify', 'flush', 'alias']; | ||
var api = ['init', 'track', 'identify', 'flush', 'alias', 'group']; | ||
@@ -39,2 +39,2 @@ /** | ||
exports.triggers = require('./triggers'); | ||
exports.Client = Client; | ||
exports.Client = Client; |
{ | ||
"name": "analytics-node", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "The hassle-free way to integrate analytics into any node application.", | ||
@@ -30,2 +30,2 @@ "repository": "git://github.com/segmentio/analytics-node", | ||
} | ||
} | ||
} |
@@ -38,1 +38,5 @@ analytics-node | ||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/segmentio/analytics-node/trend.png)](https://bitdeli.com/free "Bitdeli Badge") | ||
@@ -48,5 +48,15 @@ var should = require('should'), | ||
it('should properly group', function (done) { | ||
var promise = analytics.group({ | ||
userId : 'id', | ||
groupId : 'id', | ||
traits : {} }); | ||
check(promise, done); | ||
}); | ||
it('should properly flush', analytics.flush); | ||
}); | ||
}); |
@@ -220,2 +220,31 @@ | ||
describe('#group', function () { | ||
var client = new Client(options); | ||
it('should not group without options', function () { | ||
client.group.bind(client).should.throw(); | ||
}); | ||
it('should not identify without groupId', function () { | ||
client.group.bind(client, { userId: 12 }).should.throw(); | ||
}); | ||
it('should not identify without userId or sessionId', function () { | ||
client.group.bind(client, { groupId: 12 }).should.throw(); | ||
}); | ||
it('should not identify with bad timestamp', function () { | ||
client.group.bind(client, { groupId: 12, userId: 12, timestamp: 500 }).should.throw(); | ||
}); | ||
it('should identify successfully', function () { | ||
client.group({ | ||
userId: 12, | ||
groupId: 10, | ||
timestamp: new Date | ||
}) | ||
}); | ||
}); | ||
describe('#flush', function () { | ||
@@ -222,0 +251,0 @@ |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
28064
14
726
42
0