diff --git a/lib/mixpanel-node.js b/lib/mixpanel-node.js index d3403df..f53605b 100644 --- a/lib/mixpanel-node.js +++ b/lib/mixpanel-node.js @@ -414,6 +414,11 @@ var create_client = function(token, config) { '$distinct_id': distinct_id }; + if (properties.$ignore_time) { + data.$ignore_time = properties.$ignore_time; + delete properties.$ignore_time; + } + if(metrics.config.debug) { console.log("Sending the following data to Mixpanel (Engage):"); console.log(data); @@ -481,11 +486,15 @@ var create_client = function(token, config) { */ unset: function(distinct_id, prop, callback) { var $unset = []; + var settings = {}; if (util.isArray(prop)) { $unset = prop; } else if (typeof(prop) === 'string') { $unset = [prop]; + } else if (typeof(prop) === 'object') { + $unset = prop.properties; + settings = prop.settings; } else { if (metrics.config.debug) { console.error("Invalid argument passed to mixpanel.people.unset - must be a string or array"); @@ -494,12 +503,16 @@ var create_client = function(token, config) { return; } - data = { + var data = { '$unset': $unset, '$token': metrics.token, '$distinct_id': distinct_id }; + if (settings.$ignore_time) { + data.$ignore_time = settings.$ignore_time; + } + if(metrics.config.debug) { console.log("Sending the following data to Mixpanel (Engage):"); console.log(data); diff --git a/test/people.js b/test/people.js index 1d4682b..58194df 100644 --- a/test/people.js +++ b/test/people.js @@ -361,8 +361,29 @@ exports.people = { test.done(); }, + + "supports being called with a property object": function(test) { + + var prop = {properties : ['Downgraded', 'test1'], + settings : {'$ignore_time' : true}}, + expected_data = { + $unset: prop.properties, + $token: this.token, + $distinct_id: this.distinct_id, + $ignore_time: prop.settings.$ignore_time + }; + + this.mixpanel.people.unset(this.distinct_id, prop); + + test.ok( + this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data), + "people.unset didn't call send_request with correct arguments" + ); + + test.done(); + }, + "errors on other argument types": function(test) { - this.mixpanel.people.unset(this.distinct_id, { key1:'val1', key2:'val2' }); this.mixpanel.people.unset(this.distinct_id, 1231241.123); test.ok(