Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@segment/analytics.js-core

Package Overview
Dependencies
Maintainers
72
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@segment/analytics.js-core - npm Package Compare versions

Comparing version 3.5.2 to 3.6.0-alpha

.npmignore

5

HISTORY.md
3.6.0-alpha / 2018-05-09
==================
* Add support for disabling integrations at runtime (#70).
3.5.2 / 2018-05-01

@@ -3,0 +8,0 @@ ==================

74

lib/analytics.js

@@ -121,2 +121,12 @@ 'use strict';

each(function(opts, name) {
// Don't load disabled integrations
if (options.integrations) {
if (
options.integrations[name] === false
|| options.integrations.All === false && !options.integrations[name]
) {
return;
}
}
var Integration = self.Integrations[name];

@@ -235,2 +245,7 @@ var clonedOpts = {};

// Add the initialize integrations so the server-side ones can be disabled too
if (this.options.integrations) {
defaults(msg.integrations, this.options.integrations);
}
this._invoke('identify', new Identify(msg));

@@ -283,2 +298,7 @@

// Add the initialize integrations so the server-side ones can be disabled too
if (this.options.integrations) {
defaults(msg.integrations, this.options.integrations);
}
this._invoke('group', new Group(msg));

@@ -311,2 +331,3 @@

var events = plan.track || {};
var planIntegrationOptions = {};

@@ -326,5 +347,5 @@ // normalize

// Disabled events should always be sent to Segment.
defaults(msg.integrations, { All: false, 'Segment.io': true });
planIntegrationOptions = { All: false, 'Segment.io': true };
} else {
defaults(msg.integrations, plan.integrations || {});
planIntegrationOptions = plan.integrations || {};
}

@@ -335,6 +356,9 @@ } else {

// Disabled events should always be sent to Segment.
defaults(msg.integrations, { All: false, 'Segment.io': true });
planIntegrationOptions = { All: false, 'Segment.io': true };
}
}
// Add the initialize integrations so the server-side ones can be disabled too
defaults(msg.integrations, this._mergeInitializeAndPlanIntegrations(planIntegrationOptions));
this._invoke('track', new Track(msg));

@@ -484,2 +508,7 @@

// Add the initialize integrations so the server-side ones can be disabled too
if (this.options.integrations) {
defaults(msg.integrations, this.options.integrations);
}
this._invoke('page', new Page(msg));

@@ -531,2 +560,7 @@

// Add the initialize integrations so the server-side ones can be disabled too
if (this.options.integrations) {
defaults(msg.integrations, this.options.integrations);
}
this._invoke('alias', new Alias(msg));

@@ -744,2 +778,36 @@

/**
* Merges the tracking plan and initialization integration options.
*
* @param {Object} planIntegrations Tracking plan integrations.
* @return {Object} The merged integrations.
*/
Analytics.prototype._mergeInitializeAndPlanIntegrations = function(planIntegrations) {
// Do nothing if there are no initialization integrations
if (!this.options.integrations) {
return planIntegrations;
}
// Clone the initialization integrations
var integrations = extend({}, this.options.integrations);
var integrationName;
// Allow the tracking plan to disable integrations that were explicitly
// enabled on initialization
if (planIntegrations.All === false) {
integrations = {};
}
for (integrationName in planIntegrations) {
if (planIntegrations.hasOwnProperty(integrationName)) {
// Don't allow the tracking plan to re-enable disabled integrations
if (this.options.integrations[integrationName] !== false) {
integrations[integrationName] = planIntegrations[integrationName];
}
}
}
return integrations;
};
/**
* No conflict support.

@@ -746,0 +814,0 @@ */

2

package.json
{
"name": "@segment/analytics.js-core",
"author": "Segment <friends@segment.com>",
"version": "3.5.2",
"version": "3.6.0-alpha",
"description": "The hassle-free way to integrate analytics into any web application.",

@@ -6,0 +6,0 @@ "keywords": [

@@ -269,2 +269,45 @@ 'use strict';

it('should not load disabled integrations', function(done) {
Test.readyOnInitialize();
analytics.addIntegration(Test);
analytics.ready(function() {
assert(!analytics._integrations.Test);
done();
});
analytics.initialize(settings, {
integrations: {
Test: false
}
});
});
it('should not load any integrations when integrations.All === false', function(done) {
Test.readyOnInitialize();
analytics.addIntegration(Test);
analytics.ready(function() {
assert(!analytics._integrations.Test);
done();
});
analytics.initialize(settings, {
integrations: {
All: false
}
});
});
it('should load explicitly enabled integrations when integrations.All === false', function(done) {
Test.readyOnInitialize();
analytics.addIntegration(Test);
analytics.ready(function() {
assert(analytics._integrations.Test);
done();
});
analytics.initialize(settings, {
integrations: {
All: false,
Test: {}
}
});
});
it('should send settings to an integration', function(done) {

@@ -685,2 +728,28 @@ Test = function(options) {

it('should use the initialize .integrations option', function() {
analytics.initialize(settings, {
integrations: {
Test: false
}
});
analytics.page({ prop: true });
var page = analytics._invoke.args[0][1];
assert.deepEqual(page.obj.integrations, { Test: false });
});
it('should be able to override the initialize .integrations option', function() {
analytics.initialize(settings, {
integrations: {
Test: false
}
});
analytics.page({ prop: true }, {
integrations: {
Test: true
}
});
var page = analytics._invoke.args[0][1];
assert.deepEqual(page.obj.integrations, { Test: true });
});
it('should accept top level option .context', function() {

@@ -914,2 +983,28 @@ var app = { name: 'segment' };

it('should use the initialize .integrations option', function() {
analytics.initialize(settings, {
integrations: {
Test: false
}
});
analytics.identify(1, { trait: true });
var identify = analytics._invoke.args[0][1];
assert.deepEqual(identify.obj.integrations, { Test: false });
});
it('should be able to override the initialize .integrations option', function() {
analytics.initialize(settings, {
integrations: {
Test: false
}
});
analytics.identify(1, { trait: true }, {
integrations: {
Test: true
}
});
var identify = analytics._invoke.args[0][1];
assert.deepEqual(identify.obj.integrations, { Test: true });
});
it('should accept top level option .context', function() {

@@ -1094,2 +1189,28 @@ analytics.identify(1, { trait: true }, { context: { app: { name: 'segment' } } });

it('should use the initialize .integrations option', function() {
analytics.initialize(settings, {
integrations: {
Test: false
}
});
analytics.group(1, { trait: true });
var group = analytics._invoke.args[0][1];
assert.deepEqual(group.obj.integrations, { Test: false });
});
it('should be able to override the initialize .integrations option', function() {
analytics.initialize(settings, {
integrations: {
Test: false
}
});
analytics.group(1, { trait: true }, {
integrations: {
Test: true
}
});
var group = analytics._invoke.args[0][1];
assert.deepEqual(group.obj.integrations, { Test: true });
});
it('should accept top level option .context', function() {

@@ -1208,2 +1329,78 @@ var app = { name: 'segment' };

it('should use the initialize .integrations option', function() {
analytics.initialize(settings, {
integrations: {
Test: false
}
});
analytics.track('event', { prop: true });
var track = analytics._invoke.args[0][1];
assert.deepEqual(track.obj.integrations, { Test: false });
});
it('should be able to override the initialize .integrations option', function() {
analytics.initialize(settings, {
integrations: {
Test: false
}
});
analytics.track('event', { prop: true }, {
integrations: {
Test: true
}
});
var track = analytics._invoke.args[0][1];
assert.deepEqual(track.obj.integrations, { Test: true });
});
it('should allow tracking plan to disable integrations explicitly enabled via initialize .integrations option', function() {
analytics.initialize(settings, {
integrations: {
Test: true
},
plan: {
track: {
event1: { enabled: false },
event2: {
enabled: true,
integrations: { Test: false }
}
}
}
});
analytics.track('event1', { prop: true });
var track = analytics._invoke.args[0][1];
assert.deepEqual(track.obj.integrations, { All: false, 'Segment.io': true });
analytics.track('event2', { prop: true });
var track2 = analytics._invoke.args[1][1];
assert.deepEqual(track2.obj.integrations, { Test: false });
});
it('should prevent tracking plan from enabling integrations disabled via initialize .integrations option', function() {
analytics.initialize(settings, {
integrations: {
Test: false
},
plan: {
track: {
event1: { enabled: true },
event2: {
enabled: true,
integrations: { Test: true }
}
}
}
});
analytics.track('event1', { prop: true });
var track1 = analytics._invoke.args[0][1];
assert.deepEqual(track1.obj.integrations, { Test: false });
analytics.track('event2', { prop: true });
var track2 = analytics._invoke.args[1][1];
assert.deepEqual(track2.obj.integrations, { Test: false });
});
it('should accept top level option .context', function() {

@@ -1642,2 +1839,34 @@ var app = { name: 'segment' };

});
it('should accept top level option .integrations', function() {
analytics.alias('new', 'old', { integrations: { AdRoll: { opt: true } } });
var alias = analytics._invoke.args[0][1];
assert.deepEqual({ opt: true }, alias.options('AdRoll'));
});
it('should use the initialize .integrations option', function() {
analytics.initialize(settings, {
integrations: {
Test: false
}
});
analytics.alias('new', 'old');
var alias = analytics._invoke.args[0][1];
assert.deepEqual(alias.obj.integrations, { Test: false });
});
it('should be able to override the initialize .integrations option', function() {
analytics.initialize(settings, {
integrations: {
Test: false
}
});
analytics.alias('new', 'old', {
integrations: {
Test: true
}
});
var alias = analytics._invoke.args[0][1];
assert.deepEqual(alias.obj.integrations, { Test: true });
});
});

@@ -1644,0 +1873,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc