Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.
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
21 changes: 20 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ Vero.prototype.track = function(track) {
var regex = /[uU]nsubscribe/;

if (track.event().match(regex)) {
push('unsubscribe', { id: track.properties().id });
var id = this.analytics.user().id();
if (id) {
push('unsubscribe', id);
}
} else {
push('track', track.event(), track.properties(), { source: 'segment' });
}
Expand All @@ -119,3 +122,19 @@ Vero.prototype.alias = function(alias) {
push('reidentify', to);
}
};

Vero.prototype.group = function(group) {
var user = this.analytics.user();
var traits = {
group: group.traits()
};
if (user.id()) {
traits.id = user.id();
}
if (user.traits().email) {
traits.email = user.traits().email;
}
if (traits.id || traits.email) {
push('user', traits);
}
};
26 changes: 24 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ describe('Vero', function() {
});

it('should send an unsubscribe event in the correct format', function() {
analytics.track('unsubscribe', { id: 'id' });
analytics.called(window._veroq.push, ['unsubscribe', { id: 'id' }]);
analytics.identify('id');
window._veroq.push.reset();
analytics.track('unsubscribe');
analytics.called(window._veroq.push, ['unsubscribe', 'id']);
});
});

Expand All @@ -159,5 +161,25 @@ describe('Vero', function() {
analytics.called(window._veroq.push, ['reidentify', 'new', 'old']);
});
});

describe('#group', function() {
beforeEach(function() {
analytics.stub(window._veroq, 'push');
});

it('should send an id and group traits', function() {
analytics.identify('id');
window._veroq.push.reset();
analytics.group('group', { number: 4 });
analytics.called(window._veroq.push, ['user', { id: 'id', group: { id: 'group', number: 4 } }]);
});

it('should send an email and group traits', function() {
analytics.identify({ email: 'e@ma.il' });
window._veroq.push.reset();
analytics.group('group', { number: 4 });
analytics.called(window._veroq.push, ['user', { email: 'e@ma.il', group: { id: 'group', number: 4 } }]);
});
});
});
});