Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

analytics-node

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

analytics-node - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

61

lib/client.js

@@ -183,3 +183,3 @@ var _ = require('underscore'),

if (context && !_.isObject(context))
throw new Error('[analytics]#context: options.context ' +
throw new Error('[analytics]#track: options.context ' +
'must be an object.');

@@ -206,3 +206,62 @@

/**
* Whenever a user triggers an event, you’ll want to track it.
*
* @param {Object} options
* @param {String} from - the anonymous user's id before they are logged in
* @param {String} to - the identified user's id after they're logged in
* @param {Date} timestamp - the Date object representing when the alias occurred
* @param {Object} context - app provided context (optional)
* @return {events.EventEmitter} Promise event emitter that emits 'flush' once
* the message has been flushed, and 'err' when an error has occured.
*
*/
Client.prototype.alias = function (options) {
this._checkInitialized();
if (!_.isObject(options)) {
throw new Error('[analytics]#alias: options must be an object');
}
var to = options.to,
from = options.from,
context = options.context || {},
timestamp = options.timestamp;
if (!_.isString(from))
throw new Error('[analytics]#alias: options.from is a required string.');
if (!_.isString(to))
throw new Error('[analytics]#alias: options.to must be a non-empty string.');
if (timestamp && !_.isDate(timestamp))
throw new Error('[analytics]#alias: options.timestamp ' +
'must be provided as a date.');
if (context && !_.isObject(context))
throw new Error('[analytics]#alias: options.context ' +
'must be an object.');
var promise = new events.EventEmitter();
var message = {
action : 'alias',
from : from,
to : to,
context : _.extend(context, {library: 'analytics-node'}),
promise : promise
};
if (timestamp) message.timestamp = timestamp.toISOString();
this._enqueue(message);
return promise;
};
/**
* Enqueues a message into the internal queue.

@@ -209,0 +268,0 @@ * @param {Object} message Message to send to the server

@@ -23,2 +23,3 @@

track : '/v1/track',
alias : '/v1/alias',
batch : '/v1/import'

@@ -25,0 +26,0 @@ },

2

lib/index.js

@@ -14,3 +14,3 @@

var api = ['init', 'track', 'identify', 'flush'];
var api = ['init', 'track', 'identify', 'flush', 'alias'];

@@ -17,0 +17,0 @@ /**

{
"name": "analytics-node",
"version": "0.3.0",
"version": "0.4.0",
"description": "The hassle-free way to integrate analytics into any node application.",

@@ -5,0 +5,0 @@ "repository": "git://github.com/segmentio/analytics-node",

@@ -31,3 +31,3 @@ analytics-node

Copyright (c) 2012 Segment.io Inc. <friends@segment.io>
Copyright (c) 2013 Segment.io Inc. <friends@segment.io>

@@ -34,0 +34,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

@@ -39,5 +39,14 @@ var should = require('should'),

it('should properly alias', function (done) {
var promise = analytics.alias({
from : 'from',
to : 'to' });
check(promise, done);
});
it('should properly flush', analytics.flush);
});

@@ -125,2 +125,63 @@

describe('#alias', function () {
var client = new Client(options);
it('should not alias with bad data', function () {
(function () {
client.alias('Not an object');
}).should.throw();
});
it('should not alias without any user info', function () {
(function () {
client.alias({});
}).should.throw();
});
it('should not alias without a from', function () {
(function () {
client.alias({ to : 'test@segment.io' });
}).should.throw();
});
it('should not alias without a to', function () {
(function () {
client.alias({ from : 'test@segment.io' });
}).should.throw();
});
it('should not alias with bad timestamp', function () {
(function () {
client.alias({ from : 'from', to: 'to', timestamp: 12298383 });
}).should.throw();
});
it('should alias successfully', function () {
client.alias({ from : 'from',
to : 'test@segment.io'});
});
});
describe('#identify', function () {

@@ -127,0 +188,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc