@segment/analytics.js-core
Advanced tools
Comparing version 3.3.0 to 3.4.0
3.4.0 / 2018-03-05 | ||
================== | ||
* Revert "[SCH-297][SCH-298] Add tracking plan support to identify and group traits" (#63) | ||
3.3.0 / 2018-03-01 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -215,29 +215,6 @@ 'use strict'; | ||
var plan = this.options.plan || {}; | ||
var traitPlans = plan.identify || {}; | ||
var filteredTraits = extend({}, traits); | ||
for (var trait in filteredTraits) { | ||
if (filteredTraits.hasOwnProperty(trait)) { | ||
var traitPlan = traitPlans[trait]; | ||
if (traitPlan) { | ||
this.log('identify plan %o - %o', trait, traitPlan); | ||
if (traitPlan.enabled === false) { | ||
delete filteredTraits[trait]; | ||
} | ||
} else if (traitPlans.__default) { | ||
this.log('identify default plan %o - %o', trait, traitPlans.__default); | ||
if (!traitPlans.__default.enabled) { | ||
delete filteredTraits[trait]; | ||
} | ||
} | ||
} | ||
} | ||
// clone traits before we manipulate so we don't do anything uncouth, and take | ||
// from `user` so that we carryover anonymous traits | ||
user.identify(id, filteredTraits); | ||
user.identify(id, traits); | ||
// Send allowed traits to all integrations except Segment | ||
var msg = this.normalize({ | ||
@@ -248,17 +225,7 @@ options: options, | ||
}); | ||
extend(msg.integrations, { 'Segment.io': false }); | ||
this._invoke('identify', new Identify(msg), true); | ||
// Send all traits to the Segment, including the blocked ones | ||
// (so the blocked counts get incremented) | ||
var segmentMsg = this.normalize({ | ||
options: options, | ||
traits: traits, | ||
userId: user.id() | ||
}); | ||
extend(segmentMsg.integrations, { All: false, 'Segment.io': true }); | ||
this._invoke('identify', new Identify(segmentMsg), false); | ||
this._invoke('identify', new Identify(msg)); | ||
// emit | ||
this.emit('identify', id, filteredTraits, options); | ||
this.emit('identify', id, traits, options); | ||
this._callback(fn); | ||
@@ -297,28 +264,6 @@ return this; | ||
var plan = this.options.plan || {}; | ||
var traitPlans = plan.group || {}; | ||
var filteredTraits = extend({}, traits); | ||
for (var trait in filteredTraits) { | ||
if (filteredTraits.hasOwnProperty(trait)) { | ||
var traitPlan = traitPlans[trait]; | ||
if (traitPlan) { | ||
this.log('group plan %o - %o', trait, traitPlan); | ||
if (traitPlan.enabled === false) { | ||
delete filteredTraits[trait]; | ||
} | ||
} else if (traitPlans.__default) { | ||
this.log('group default plan %o - %o', trait, traitPlans.__default); | ||
if (!traitPlans.__default.enabled) { | ||
delete filteredTraits[trait]; | ||
} | ||
} | ||
} | ||
} | ||
// grab from group again to make sure we're taking from the source | ||
group.identify(id, filteredTraits); | ||
group.identify(id, traits); | ||
// Send allowed traits to all integrations except Segment | ||
var msg = this.normalize({ | ||
@@ -329,16 +274,6 @@ options: options, | ||
}); | ||
extend(msg.integrations, { 'Segment.io': false }); | ||
this._invoke('group', new Group(msg), true); | ||
// Send all traits to the Segment, including the blocked ones | ||
// (so the blocked counts get incremented) | ||
var segmentMsg = this.normalize({ | ||
options: options, | ||
traits: traits, | ||
groupId: group.id() | ||
}); | ||
extend(segmentMsg.integrations, { All: false, 'Segment.io': true }); | ||
this._invoke('group', new Group(segmentMsg), false); | ||
this._invoke('group', new Group(msg)); | ||
this.emit('group', id, filteredTraits, options); | ||
this.emit('group', id, traits, options); | ||
this._callback(fn); | ||
@@ -367,3 +302,3 @@ return this; | ||
var plan = this.options.plan || {}; | ||
var trackPlans = plan.track || {}; | ||
var events = plan.track || {}; | ||
@@ -378,14 +313,14 @@ // normalize | ||
// plan. | ||
var trackPlan = trackPlans[event]; | ||
if (trackPlan) { | ||
this.log('track plan %o - %o', event, trackPlan); | ||
if (trackPlan.enabled === false) { | ||
plan = events[event]; | ||
if (plan) { | ||
this.log('plan %o - %o', event, plan); | ||
if (plan.enabled === false) { | ||
// Disabled events should always be sent to Segment. | ||
defaults(msg.integrations, { All: false, 'Segment.io': true }); | ||
} else { | ||
defaults(msg.integrations, trackPlan.integrations || {}); | ||
defaults(msg.integrations, plan.integrations || {}); | ||
} | ||
} else if (trackPlans.__default) { | ||
this.log('track default plan %o - %o', event, trackPlans.__default); | ||
if (!trackPlans.__default.enabled) { | ||
} else { | ||
var defaultPlan = events.__default || { enabled: true }; | ||
if (!defaultPlan.enabled) { | ||
// Disabled events should always be sent to Segment. | ||
@@ -673,3 +608,2 @@ defaults(msg.integrations, { All: false, 'Segment.io': true }); | ||
* @param {Facade} facade | ||
* @param {boolean} skipEmit | ||
* @return {Analytics} | ||
@@ -679,10 +613,6 @@ * @api private | ||
Analytics.prototype._invoke = function(method, facade, skipEmit) { | ||
// Default skipEmit to falsey for backwards compatibility | ||
Analytics.prototype._invoke = function(method, facade) { | ||
var self = this; | ||
this.emit('invoke', facade); | ||
// Workaround to allow the Segment.io integration to be disabled due to it's non-standard setup. | ||
// Used in identify() and group() for schema | ||
if (!skipEmit) this.emit('invoke', facade); | ||
var failedInitializations = self.failedInitializations || []; | ||
@@ -689,0 +619,0 @@ each(function(integration, name) { |
{ | ||
"name": "@segment/analytics.js-core", | ||
"author": "Segment <friends@segment.com>", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "The hassle-free way to integrate analytics into any web application.", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -331,21 +331,12 @@ 'use strict'; | ||
it('should emit "invoke" with facade', function() { | ||
it('should emit "invoke" with facade', function(done) { | ||
var opts = { All: false }; | ||
var identify = new Identify({ options: opts }); | ||
var invoke = sinon.spy(); | ||
analytics.once('invoke', invoke); | ||
analytics.on('invoke', function(msg) { | ||
assert(msg === identify); | ||
assert(msg.action() === 'identify'); | ||
done(); | ||
}); | ||
analytics._invoke('identify', identify); | ||
assert(invoke.called); | ||
assert(invoke.args[0][0] === identify); | ||
assert(invoke.args[0][0].action() === 'identify'); | ||
}); | ||
it('should allow emitting "invoke" to be disabled with facade', function() { | ||
var opts = { All: false }; | ||
var identify = new Identify({ options: opts }); | ||
var invoke = sinon.spy(); | ||
analytics.once('invoke', invoke); | ||
analytics._invoke('identify', identify, true); | ||
assert(!invoke.called); | ||
}); | ||
}); | ||
@@ -844,170 +835,2 @@ | ||
it('should strip disabled traits for all integrations except Segment', function() { | ||
analytics.options.plan = { | ||
identify: { | ||
name: { enabled: false } | ||
} | ||
}; | ||
analytics.identify( | ||
'123', | ||
{ name: 'Joe Bloggs' }, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var identify1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ Mixpanel: true, 'Segment.io': false }, identify1.obj.integrations); | ||
assert.deepEqual({}, identify1.obj.traits); | ||
var identify2 = analytics._invoke.args[1][1]; | ||
assert.deepEqual({ Mixpanel: true, All: false, 'Segment.io': true }, identify2.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, identify2.obj.traits); | ||
}); | ||
it('should not strip enabled traits', function() { | ||
analytics.options.plan = { | ||
identify: { | ||
name: { enabled: true } | ||
} | ||
}; | ||
analytics.identify( | ||
'123', | ||
{ name: 'Joe Bloggs' }, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var identify1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ Mixpanel: true, 'Segment.io': false }, identify1.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, identify1.obj.traits); | ||
var identify2 = analytics._invoke.args[1][1]; | ||
assert.deepEqual({ Mixpanel: true, All: false, 'Segment.io': true }, identify2.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, identify2.obj.traits); | ||
}); | ||
it('should not strip new traits when default is enabled', function() { | ||
analytics.options.plan = { | ||
identify: { | ||
__default: { enabled: true } | ||
} | ||
}; | ||
analytics.identify( | ||
'123', | ||
{ name: 'Joe Bloggs' }, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var identify1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ Mixpanel: true, 'Segment.io': false }, identify1.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, identify1.obj.traits); | ||
var identify2 = analytics._invoke.args[1][1]; | ||
assert.deepEqual({ Mixpanel: true, All: false, 'Segment.io': true }, identify2.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, identify2.obj.traits); | ||
}); | ||
it('should strip new traits when default is disabled', function() { | ||
analytics.options.plan = { | ||
identify: { | ||
__default: { enabled: false } | ||
} | ||
}; | ||
analytics.identify( | ||
'123', | ||
{ name: 'Joe Bloggs' }, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var identify1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ Mixpanel: true, 'Segment.io': false }, identify1.obj.integrations); | ||
assert.deepEqual({}, identify1.obj.traits); | ||
var identify2 = analytics._invoke.args[1][1]; | ||
assert.deepEqual({ Mixpanel: true, All: false, 'Segment.io': true }, identify2.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, identify2.obj.traits); | ||
}); | ||
it('should not strip enabled traits when default is disabled', function() { | ||
analytics.options.plan = { | ||
identify: { | ||
name: { enabled: true }, | ||
__default: { enabled: false } | ||
} | ||
}; | ||
analytics.identify( | ||
'123', | ||
{ name: 'Joe Bloggs', email: 'joe@example.com' }, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var identify1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ Mixpanel: true, 'Segment.io': false }, identify1.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, identify1.obj.traits); | ||
var identify2 = analytics._invoke.args[1][1]; | ||
assert.deepEqual({ Mixpanel: true, All: false, 'Segment.io': true }, identify2.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs', email: 'joe@example.com' }, identify2.obj.traits); | ||
}); | ||
it('should strip disabled traits when default is enabled', function() { | ||
analytics.options.plan = { | ||
identify: { | ||
name: { enabled: false }, | ||
__default: { enabled: true } | ||
} | ||
}; | ||
analytics.identify( | ||
'123', | ||
{ name: 'Joe Bloggs', email: 'joe@example.com' }, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var identify1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ Mixpanel: true, 'Segment.io': false }, identify1.obj.integrations); | ||
assert.deepEqual({ email: 'joe@example.com' }, identify1.obj.traits); | ||
var identify2 = analytics._invoke.args[1][1]; | ||
assert.deepEqual({ Mixpanel: true, All: false, 'Segment.io': true }, identify2.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs', email: 'joe@example.com' }, identify2.obj.traits); | ||
}); | ||
it('should not modify the original traits object', function() { | ||
analytics.options.plan = { | ||
identify: { | ||
name: { enabled: false } | ||
} | ||
}; | ||
var traits = { name: 'Joe Bloggs', email: 'joe@example.com' }; | ||
analytics.identify( | ||
'123', | ||
traits, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var identify1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ email: 'joe@example.com' }, identify1.obj.traits); | ||
assert.deepEqual({ name: 'Joe Bloggs', email: 'joe@example.com' }, traits); | ||
}); | ||
it('should include context.page', function() { | ||
@@ -1193,170 +1016,2 @@ analytics.identify(1); | ||
it('should strip disabled traits for all integrations except Segment', function() { | ||
analytics.options.plan = { | ||
group: { | ||
name: { enabled: false } | ||
} | ||
}; | ||
analytics.group( | ||
'123', | ||
{ name: 'Joe Bloggs' }, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var group1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ Mixpanel: true, 'Segment.io': false }, group1.obj.integrations); | ||
assert.deepEqual({}, group1.obj.traits); | ||
var group2 = analytics._invoke.args[1][1]; | ||
assert.deepEqual({ Mixpanel: true, All: false, 'Segment.io': true }, group2.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, group2.obj.traits); | ||
}); | ||
it('should not strip enabled traits', function() { | ||
analytics.options.plan = { | ||
group: { | ||
name: { enabled: true } | ||
} | ||
}; | ||
analytics.group( | ||
'123', | ||
{ name: 'Joe Bloggs' }, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var group1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ Mixpanel: true, 'Segment.io': false }, group1.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, group1.obj.traits); | ||
var group2 = analytics._invoke.args[1][1]; | ||
assert.deepEqual({ Mixpanel: true, All: false, 'Segment.io': true }, group2.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, group2.obj.traits); | ||
}); | ||
it('should not strip new traits when default is enabled', function() { | ||
analytics.options.plan = { | ||
group: { | ||
__default: { enabled: true } | ||
} | ||
}; | ||
analytics.group( | ||
'123', | ||
{ name: 'Joe Bloggs' }, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var group1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ Mixpanel: true, 'Segment.io': false }, group1.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, group1.obj.traits); | ||
var group2 = analytics._invoke.args[1][1]; | ||
assert.deepEqual({ Mixpanel: true, All: false, 'Segment.io': true }, group2.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, group2.obj.traits); | ||
}); | ||
it('should strip new traits when default is disabled', function() { | ||
analytics.options.plan = { | ||
group: { | ||
__default: { enabled: false } | ||
} | ||
}; | ||
analytics.group( | ||
'123', | ||
{ name: 'Joe Bloggs' }, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var group1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ Mixpanel: true, 'Segment.io': false }, group1.obj.integrations); | ||
assert.deepEqual({}, group1.obj.traits); | ||
var group2 = analytics._invoke.args[1][1]; | ||
assert.deepEqual({ Mixpanel: true, All: false, 'Segment.io': true }, group2.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, group2.obj.traits); | ||
}); | ||
it('should not strip enabled traits when default is disabled', function() { | ||
analytics.options.plan = { | ||
group: { | ||
name: { enabled: true }, | ||
__default: { enabled: false } | ||
} | ||
}; | ||
analytics.group( | ||
'123', | ||
{ name: 'Joe Bloggs', email: 'joe@example.com' }, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var group1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ Mixpanel: true, 'Segment.io': false }, group1.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs' }, group1.obj.traits); | ||
var group2 = analytics._invoke.args[1][1]; | ||
assert.deepEqual({ Mixpanel: true, All: false, 'Segment.io': true }, group2.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs', email: 'joe@example.com' }, group2.obj.traits); | ||
}); | ||
it('should strip disabled traits when default is enabled', function() { | ||
analytics.options.plan = { | ||
group: { | ||
name: { enabled: false }, | ||
__default: { enabled: true } | ||
} | ||
}; | ||
analytics.group( | ||
'123', | ||
{ name: 'Joe Bloggs', email: 'joe@example.com' }, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var group1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ Mixpanel: true, 'Segment.io': false }, group1.obj.integrations); | ||
assert.deepEqual({ email: 'joe@example.com' }, group1.obj.traits); | ||
var group2 = analytics._invoke.args[1][1]; | ||
assert.deepEqual({ Mixpanel: true, All: false, 'Segment.io': true }, group2.obj.integrations); | ||
assert.deepEqual({ name: 'Joe Bloggs', email: 'joe@example.com' }, group2.obj.traits); | ||
}); | ||
it('should not modify the original traits object', function() { | ||
analytics.options.plan = { | ||
group: { | ||
name: { enabled: false } | ||
} | ||
}; | ||
var traits = { name: 'Joe Bloggs', email: 'joe@example.com' }; | ||
analytics.group( | ||
'123', | ||
traits, | ||
{ integrations: { Mixpanel: true } } | ||
); | ||
assert(analytics._invoke.calledTwice); | ||
var group1 = analytics._invoke.args[0][1]; | ||
assert.deepEqual({ email: 'joe@example.com' }, group1.obj.traits); | ||
assert.deepEqual({ name: 'Joe Bloggs', email: 'joe@example.com' }, traits); | ||
}); | ||
it('should include context.page', function() { | ||
@@ -1363,0 +1018,0 @@ analytics.group(1); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
175665
3959