From 7768f21df39d1f3adfd6f95144948d5c653859d0 Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Fri, 7 Nov 2014 16:39:23 +1100 Subject: [PATCH] track means track, import means import. --- lib/mixpanel-node.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/mixpanel-node.js b/lib/mixpanel-node.js index d3403df..1446ce0 100644 --- a/lib/mixpanel-node.js +++ b/lib/mixpanel-node.js @@ -97,25 +97,12 @@ var create_client = function(token, config) { }); }; - /** - track(event, properties, callback) - --- - this function sends an event to mixpanel. - - event:string the event name - properties:object additional event properties to send - callback:function(err:Error) callback is called when the request is - finished or an error occurs - */ - metrics.track = function(event, properties, callback) { + metrics.track_or_import = function(endpoint, event, properties, callback) { if (typeof(properties) === 'function' || !properties) { callback = properties; properties = {}; } - // if properties.time exists, use import endpoint - var endpoint = (typeof(properties.time) === 'number') ? '/import' : '/track'; - properties.token = metrics.token; properties.mp_lib = "node"; @@ -132,6 +119,18 @@ var create_client = function(token, config) { metrics.send_request(endpoint, data, callback); }; + /** + track(event, properties, callback) + --- + this function sends an event to mixpanel. + + event:string the event name + properties:object additional event properties to send + callback:function(err:Error) callback is called when the request is + finished or an error occurs + */ + metrics.track = metrics.track_or_import.bind(null, '/track'); + /** import(event, properties, callback) --- @@ -166,7 +165,7 @@ var create_client = function(token, config) { properties.time = time; - metrics.track(event, properties, callback); + metrics.track_or_import('/import', event, properties, callback); }; /**