Skip to content

Commit 2debf99

Browse files
Add people properties
1 parent 67461f9 commit 2debf99

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

MixpanelEventForwarder.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@
125125
attr[key] = value;
126126

127127
try {
128-
mixpanel.mparticle.register(attr);
128+
if (forwarderSettings.useMixpanelPeople) {
129+
mixpanel.mparticle.people.set(attr);
130+
} else {
131+
mixpanel.mparticle.register(attr);
132+
}
129133
}
130134
catch(e) {
131135
return 'Can\'t call register on forwarder: ' + name + ': ' + e;
@@ -134,7 +138,11 @@
134138

135139
function removeUserAttribute(attribute) {
136140
try {
137-
mixpanel.mparticle.unregister(attribute);
141+
if (forwarderSettings.useMixpanelPeople) {
142+
mixpanel.mparticle.people.unset(attribute);
143+
} else {
144+
mixpanel.mparticle.unregister(attribute);
145+
}
138146
}
139147
catch(e) {
140148
return 'Can\'t call unregister on forwarder: ' + name + ': ' + e;

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"description": "mParticle integration sdk for Mixpanel",
44
"repository": "https://github.com/mParticle/integration-mixpanel",
55
"devDependencies": {
6-
"blanket": "1.1.7",
7-
"should": "7.1.0",
8-
"mocha": "2.3.2"
6+
"should": "13.2.3",
7+
"mocha": "^5.2.0"
98
}
109
}

test/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
<script src="../node_modules/mocha/mocha.js"></script>
1111
<script src="../node_modules/should/should.js"></script>
12-
<script src="../node_modules/blanket/dist/mocha/blanket_mocha.js"></script>
1312
<script src="mockhttprequest.js"></script>
1413
<script>
1514
var mp = function () {

test/tests.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ describe('Mixpanel Forwarder', function () {
108108
setCalledAttributes(data, 'unregisterCalled');
109109
};
110110

111+
this.mparticle.people.set = function (data) {
112+
setCalledAttributes(data, 'setCalled');
113+
};
114+
115+
this.mparticle.people.unset = function (data) {
116+
setCalledAttributes(data, 'unsetCalled');
117+
};
118+
111119
this.mparticle.people.track_charge = function (data) {
112120
setCalledAttributes(data, 'trackChargeCalled');
113121
};
@@ -151,7 +159,7 @@ describe('Mixpanel Forwarder', function () {
151159
window.mixpanel.mparticle.data[1].should.be.instanceof(Object);
152160

153161
window.mixpanel.mparticle.data[0].should.be.equal('Test Page Event');
154-
Should(window.mixpanel.mparticle.data[1]).eql({});
162+
window.mixpanel.mparticle.data[1].should.be.an.Object().and.be.empty();
155163

156164
done();
157165
});
@@ -169,7 +177,7 @@ describe('Mixpanel Forwarder', function () {
169177
window.mixpanel.mparticle.data[1].should.be.instanceof(Object);
170178

171179
window.mixpanel.mparticle.data[0].should.be.equal('Viewed Test Page Event');
172-
Should(window.mixpanel.mparticle.data[1]).eql({});
180+
window.mixpanel.mparticle.data[1].should.be.an.Object().and.be.empty();
173181

174182
done();
175183
});
@@ -211,6 +219,32 @@ describe('Mixpanel Forwarder', function () {
211219

212220
});
213221

222+
describe('People Properties', function () {
223+
it('should set a user property', function(done) {
224+
mParticle.forwarder.init({
225+
useMixpanelPeople : 'True'
226+
}, reportService.cb, true);
227+
228+
mParticle.forwarder.setUserAttribute('email', '[email protected]');
229+
window.mixpanel.mparticle.should.have.property('setCalled', true);
230+
window.mixpanel.mparticle.data.should.be.an.instanceof(Object).and.have.property('email', '[email protected]');
231+
232+
done();
233+
});
234+
235+
it('should unset a user property', function(done) {
236+
mParticle.forwarder.init({
237+
useMixpanelPeople : 'True'
238+
}, reportService.cb, true)
239+
240+
mParticle.forwarder.removeUserAttribute('email', '[email protected]');
241+
window.mixpanel.mparticle.should.have.property('unsetCalled', true);
242+
window.mixpanel.mparticle.data.should.be.an.instanceof(Object).and.not.have.property('email', '[email protected]');
243+
244+
done();
245+
});
246+
});
247+
214248
describe('Transaction events', function() {
215249
it('should track charge event', function(done) {
216250
mParticle.forwarder.init({

0 commit comments

Comments
 (0)