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

created $ignore_time options for track_charge() and unset() methods #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
15 changes: 14 additions & 1 deletion lib/mixpanel-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down
23 changes: 22 additions & 1 deletion test/people.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down