Browse files

handle the special property ip correctly when setting it on people pr…

…ofiles
  • Loading branch information...
1 parent 602eea9 commit 1d21231de6032664a3c1b6085f97aa5d9f1915ef @rgabo rgabo committed Mar 23, 2013
Showing with 24 additions and 0 deletions.
  1. +5 −0 lib/mixpanel-node.js
  2. +19 −0 test/people.js
View
5 lib/mixpanel-node.js
@@ -183,6 +183,11 @@ var create_client = function(token, config) {
'$distinct_id': distinct_id
}
+ if($set['ip']) {
+ data['$ip'] = $set['ip'];
+ delete $set['ip'];
+ }
+
if(metrics.config.debug) {
console.log("Sending the following data to Mixpanel (Engage):");
console.log(data);
View
19 test/people.js
@@ -54,6 +54,25 @@ exports.people = {
);
test.done();
+ },
+
+ "handles the ip property in a property object properly": function(test) {
+ var prop = { ip: '1.2.3.4', key1: 'val1', key2: 'val2' },
+ expected_data = {
+ $set: { key1: 'val1', key2: 'val2' },
+ $token: this.token,
+ $distinct_id: this.distinct_id,
+ $ip: '1.2.3.4'
+ };
+
+ this.mixpanel.people.set(this.distinct_id, prop);
+
+ test.ok(
+ this.mixpanel.send_request.calledWithMatch(this.endpoint, expected_data),
+ "people.set didn't call send_request with correct arguments"
+ );
+
+ test.done();
}
},

2 comments on commit 1d21231

@joeydong

I found it confusing that it uses ip rather than $ip as the documentation says. Maybe support both? https://mixpanel.com/docs/people-analytics/special-properties

In any case, it wasn't a big deal.

@carlsverre

Thanks for the comment DarkMeId. You raise a good point. I have basically 0 time to dedicate to this project right now, but if you or @rgabo is willing to create a patch I will happily merge it in and release a new version.

Please sign in to comment.