1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

use one segment instance (#10915)

This commit is contained in:
Brad Decker 2021-04-26 11:05:43 -05:00 committed by GitHub
parent d97a9e8acc
commit f1825e850d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 24 deletions

View File

@ -57,8 +57,6 @@ export default class MetaMetricsController {
/**
* @param {Object} segment - an instance of analytics-node for tracking
* events that conform to the new MetaMetrics tracking plan.
* @param {Object} segmentLegacy - an instance of analytics-node for
* tracking legacy schema events. Will eventually be phased out
* @param {Object} preferencesStore - The preferences controller store, used
* to access and subscribe to preferences that will be attached to events
* @param {function} onNetworkDidChange - Used to attach a listener to the
@ -73,7 +71,6 @@ export default class MetaMetricsController {
*/
constructor({
segment,
segmentLegacy,
preferencesStore,
onNetworkDidChange,
getCurrentChainId,
@ -105,7 +102,6 @@ export default class MetaMetricsController {
this.network = getNetworkIdentifier();
});
this.segment = segment;
this.segmentLegacy = segmentLegacy;
}
generateMetaMetricsId() {
@ -260,6 +256,12 @@ export default class MetaMetricsController {
}
payload[idType] = idValue;
// If this is an event on the old matomo schema, add a key to the payload
// to designate it as such
if (matomoEvent === true) {
payload.properties.legacy_event = true;
}
// Promises will only resolve when the event is sent to segment. For any
// event that relies on this promise being fulfilled before performing UI
// updates, or otherwise delaying user interaction, supply the
@ -278,11 +280,9 @@ export default class MetaMetricsController {
return resolve();
};
const target = matomoEvent === true ? this.segmentLegacy : this.segment;
target.track(payload, callback);
this.segment.track(payload, callback);
if (flushImmediately) {
target.flush();
this.segment.flush();
}
});
}

View File

@ -11,7 +11,6 @@ import MetaMetricsController from './metametrics';
import { NETWORK_EVENTS } from './network';
const segment = createSegmentMock(2, 10000);
const segmentLegacy = createSegmentMock(2, 10000);
const VERSION = '0.0.1-test';
const NETWORK = 'Mainnet';
@ -91,7 +90,6 @@ function getMetaMetricsController({
} = {}) {
return new MetaMetricsController({
segment,
segmentLegacy,
getNetworkIdentifier: networkController.getNetworkIdentifier.bind(
networkController,
),
@ -286,7 +284,7 @@ describe('MetaMetricsController', function () {
});
it('should track a legacy event', function () {
const mock = sinon.mock(segmentLegacy);
const mock = sinon.mock(segment);
const metaMetricsController = getMetaMetricsController();
mock
.expects('track')
@ -297,6 +295,7 @@ describe('MetaMetricsController', function () {
context: DEFAULT_TEST_CONTEXT,
properties: {
test: 1,
legacy_event: true,
...DEFAULT_EVENT_PROPERTIES,
},
});
@ -544,7 +543,6 @@ describe('MetaMetricsController', function () {
afterEach(function () {
// flush the queues manually after each test
segment.flush();
segmentLegacy.flush();
sinon.restore();
});
});

View File

@ -4,7 +4,6 @@ const isDevOrTestEnvironment = Boolean(
process.env.METAMASK_DEBUG || process.env.IN_TEST,
);
const SEGMENT_WRITE_KEY = process.env.SEGMENT_WRITE_KEY ?? null;
const SEGMENT_LEGACY_WRITE_KEY = process.env.SEGMENT_LEGACY_WRITE_KEY ?? null;
const SEGMENT_HOST = process.env.SEGMENT_HOST ?? null;
// flushAt controls how many events are sent to segment at once. Segment will
@ -90,12 +89,3 @@ export const segment =
flushAt: SEGMENT_FLUSH_AT,
flushInterval: SEGMENT_FLUSH_INTERVAL,
});
export const segmentLegacy =
!SEGMENT_LEGACY_WRITE_KEY || (isDevOrTestEnvironment && !SEGMENT_HOST)
? createSegmentMock(SEGMENT_FLUSH_AT, SEGMENT_FLUSH_INTERVAL)
: new Analytics(SEGMENT_LEGACY_WRITE_KEY, {
host: SEGMENT_HOST,
flushAt: SEGMENT_FLUSH_AT,
flushInterval: SEGMENT_FLUSH_INTERVAL,
});

View File

@ -58,7 +58,7 @@ import nodeify from './lib/nodeify';
import accountImporter from './account-import-strategies';
import seedPhraseVerifier from './lib/seed-phrase-verifier';
import MetaMetricsController from './controllers/metametrics';
import { segment, segmentLegacy } from './lib/segment';
import { segment } from './lib/segment';
import createMetaRPCHandler from './lib/createMetaRPCHandler';
export const METAMASK_CONTROLLER_EVENTS = {
@ -128,7 +128,6 @@ export default class MetamaskController extends EventEmitter {
this.metaMetricsController = new MetaMetricsController({
segment,
segmentLegacy,
preferencesStore: this.preferencesController.store,
onNetworkDidChange: this.networkController.on.bind(
this.networkController,