Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.
Merged
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
1 change: 0 additions & 1 deletion analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -18893,7 +18893,6 @@ var toplevel = [
'context',
'groupId',
'userId',
'traits',
'event',
'name'
];
Expand Down
1 change: 0 additions & 1 deletion lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var toplevel = [
'context',
'groupId',
'userId',
'traits',
'event',
'name'
];
Expand Down
37 changes: 36 additions & 1 deletion test/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,14 @@ describe('Analytics', function () {
assert.equal('id', page.obj.anonymousId);
});

it('should accept context.traits', function(){
analytics.page({ prop: true }, { traits: { trait: true } });
var page = analytics._invoke.args[0][1];
assert.deepEqual(page.context(), {
traits: { trait: true }
});
});

it('should emit page', function (done) {
defaults.category = 'category';
defaults.name = 'name';
Expand Down Expand Up @@ -746,6 +754,15 @@ describe('Analytics', function () {
var identify = analytics._invoke.args[0][1];
assert.deepEqual(app, identify.obj.context.app);
});

it('should accept context.traits', function(){
analytics.identify(1, { trait: 1 }, { traits: { trait: true } });
var identify = analytics._invoke.args[0][1];
assert.deepEqual(identify.traits(), { trait: 1, id: 1 });
assert.deepEqual(identify.context(), {
traits: { trait: true }
});
});
});

describe('#user', function () {
Expand Down Expand Up @@ -910,6 +927,15 @@ describe('Analytics', function () {
var group = analytics._invoke.args[0][1];
assert.deepEqual(app, group.obj.context.app);
});

it('should accept context.traits', function(){
analytics.group(1, { trait: 1 }, { traits: { trait: true } });
var group = analytics._invoke.args[0][1];
assert.deepEqual(group.traits(), { trait: 1, id: 1 });
assert.deepEqual(group.context(), {
traits: { trait: true }
});
});
});

describe('#track', function () {
Expand Down Expand Up @@ -1060,7 +1086,16 @@ describe('Analytics', function () {
analytics.track('event', {}, { campaign: {} });
var msg = analytics._invoke.args[0][1];
assert.deepEqual({}, msg.proxy('context.campaign'));
})
});

it('should accept context.traits', function(){
analytics.track('event', { prop: 1 }, { traits: { trait: true } });
var track = analytics._invoke.args[0][1];
assert.deepEqual(track.properties(), { prop: 1 });
assert.deepEqual(track.context(), {
traits: { trait: true }
});
});
});

describe('#trackLink', function () {
Expand Down
4 changes: 2 additions & 2 deletions test/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('normalize', function(){
opts.groupId = 'group-id';
opts.integrations = { foo: 1 };
opts.properties = { prop: 1 };
opts.traits = { trait: 1 };
opts.previousId = 'previous-id';
opts.context = { context: 1 };

Expand All @@ -50,7 +49,6 @@ describe('normalize', function(){
assert.equal(out.groupId, 'group-id');
assert.deepEqual(out.integrations, { foo: 1 });
assert.deepEqual(out.properties, { prop: 1 });
assert.deepEqual(out.traits, { trait: 1 });
assert.equal(out.previousId, 'previous-id');
assert.deepEqual(out.context, { context: 1 });
});
Expand All @@ -59,11 +57,13 @@ describe('normalize', function(){
opts.context = { foo: 1 };
opts.campaign = { name: 'campaign-name' };
opts.library = 'analytics-wordpress';
opts.traits = { trait: true };
assert.deepEqual(normalize(msg, list), {
integrations: {},
context: {
campaign: { name: 'campaign-name' },
library: 'analytics-wordpress',
traits: { trait: true },
foo: 1
}
});
Expand Down