Skip to content

Commit 44866f4

Browse files
author
rosinbum
committed
add merge Identities functionality mixpanel#208
1 parent c093a6b commit 44866f4

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

lib/mixpanel-node.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ declare namespace mixpanel {
6464

6565
alias(distinctId: string, alias: string, callback?: Callback): void;
6666

67+
merge(distinctIds: string, distinctId2: string, callback?: Callback): void;
68+
6769
people: People;
6870

6971
groups: Groups;

lib/mixpanel-node.js

+19
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,25 @@ var create_client = function(token, config) {
434434
metrics.track('$create_alias', properties, callback);
435435
};
436436

437+
/**
438+
merge(distinct_id_1, distinct_id_2)
439+
---
440+
This function merges 2 distinct_id s
441+
442+
For more information look at:
443+
https://developer.mixpanel.com/reference/identity-merge
444+
445+
distinct_id_1:string one distinct id
446+
distinct_id_2:string a second distinct id
447+
*/
448+
metrics.merge = function(distinct_id_1, distinct_id_2, callback) {
449+
var properties = {
450+
distinct_ids: [distinct_id_1, distinct_id_2]
451+
};
452+
453+
metrics.import('$merge', new Date().getDate(), properties, callback);
454+
};
455+
437456
metrics.groups = new MixpanelGroups(metrics);
438457
metrics.people = new MixpanelPeople(metrics);
439458

test/merge.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var Mixpanel = require('../lib/mixpanel-node'),
2+
Sinon = require('sinon');
3+
4+
exports.merge = {
5+
setUp: function(next) {
6+
this.mixpanel = Mixpanel.init('token', { key: 'key' });
7+
8+
Sinon.stub(this.mixpanel, 'send_request');
9+
10+
next();
11+
},
12+
13+
tearDown: function(next) {
14+
this.mixpanel.send_request.restore();
15+
16+
next();
17+
},
18+
19+
"calls send_request with correct endpoint and data": function(test) {
20+
var distinct_id_1 = "distinct_id1",
21+
distinct_id_2 = "distinct_id2",
22+
expected_endpoint = "/import",
23+
expected_data = {
24+
event: '$merge',
25+
properties: {
26+
distinct_ids: [distinct_id_1, distinct_id_2],
27+
token: 'token'
28+
}
29+
};
30+
31+
this.mixpanel.merge(distinct_id_1, distinct_id_2);
32+
test.ok(
33+
this.mixpanel.send_request.calledWithMatch({ endpoint: expected_endpoint, data: expected_data }),
34+
"merge didn't call send_request with correct arguments"
35+
);
36+
37+
test.done();
38+
}
39+
};

0 commit comments

Comments
 (0)