Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow track endpoint to be called with a time. #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions lib/mixpanel-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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)
---
Expand Down Expand Up @@ -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);
};

/**
Expand Down