From ba1b34b2d54fa15dbf3117e6a1b8a3218147242c Mon Sep 17 00:00:00 2001 From: gelzis Date: Tue, 11 Nov 2014 17:17:51 +0200 Subject: [PATCH 1/4] add $ignore_time property to track_charge --- lib/mixpanel-node.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/mixpanel-node.js b/lib/mixpanel-node.js index d3403df..02001c8 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 (typeof(properties.$ignore_time) !== 'undefined') { + 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); From 4a50c7187dc9ef30016a100f5436e1a54227ac71 Mon Sep 17 00:00:00 2001 From: gelzis Date: Tue, 11 Nov 2014 17:20:12 +0200 Subject: [PATCH 2/4] add $ignore_time property to unset --- lib/mixpanel-node.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/mixpanel-node.js b/lib/mixpanel-node.js index 02001c8..24b3cd2 100644 --- a/lib/mixpanel-node.js +++ b/lib/mixpanel-node.js @@ -486,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"); @@ -499,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); From ba61c17449ac72f1b4aff969d2efc82aff3542b2 Mon Sep 17 00:00:00 2001 From: gelzis Date: Tue, 11 Nov 2014 17:46:29 +0200 Subject: [PATCH 3/4] fix for consistency --- lib/mixpanel-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mixpanel-node.js b/lib/mixpanel-node.js index 24b3cd2..f53605b 100644 --- a/lib/mixpanel-node.js +++ b/lib/mixpanel-node.js @@ -414,7 +414,7 @@ var create_client = function(token, config) { '$distinct_id': distinct_id }; - if (typeof(properties.$ignore_time) !== 'undefined') { + if (properties.$ignore_time) { data.$ignore_time = properties.$ignore_time; delete properties.$ignore_time; } From 17658ae553b43bdb40cdb40c51888b45a3c33695 Mon Sep 17 00:00:00 2001 From: gelzis Date: Tue, 11 Nov 2014 18:05:40 +0200 Subject: [PATCH 4/4] fix for tests --- test/people.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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(