Skip to content
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
2 changes: 2 additions & 0 deletions lib/mixpanel-node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ declare namespace mixpanel {

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

merge(distinctIds: string, distinctId2: string, callback?: Callback): void;

people: People;

groups: Groups;
Expand Down
19 changes: 19 additions & 0 deletions lib/mixpanel-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,25 @@ var create_client = function(token, config) {
metrics.track('$create_alias', properties, callback);
};

/**
merge(distinct_id_1, distinct_id_2)
---
This function merges 2 distinct_id s

For more information look at:
https://developer.mixpanel.com/reference/identity-merge

distinct_id_1:string one distinct id
distinct_id_2:string a second distinct id
*/
metrics.merge = function(distinct_id_1, distinct_id_2, callback) {
var properties = {
distinct_ids: [distinct_id_1, distinct_id_2]
};

metrics.import('$merge', new Date().getDate(), properties, callback);
};

metrics.groups = new MixpanelGroups(metrics);
metrics.people = new MixpanelPeople(metrics);

Expand Down
39 changes: 39 additions & 0 deletions test/merge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var Mixpanel = require('../lib/mixpanel-node'),
Sinon = require('sinon');

exports.merge = {
setUp: function(next) {
this.mixpanel = Mixpanel.init('token', { key: 'key' });

Sinon.stub(this.mixpanel, 'send_request');

next();
},

tearDown: function(next) {
this.mixpanel.send_request.restore();

next();
},

"calls send_request with correct endpoint and data": function(test) {
var distinct_id_1 = "distinct_id1",
distinct_id_2 = "distinct_id2",
expected_endpoint = "/import",
expected_data = {
event: '$merge',
properties: {
distinct_ids: [distinct_id_1, distinct_id_2],
token: 'token'
}
};

this.mixpanel.merge(distinct_id_1, distinct_id_2);
test.ok(
this.mixpanel.send_request.calledWithMatch({ endpoint: expected_endpoint, data: expected_data }),
"merge didn't call send_request with correct arguments"
);

test.done();
}
};