Skip to content

Commit f1825e8

Browse files
authored
use one segment instance (#10915)
1 parent d97a9e8 commit f1825e8

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

app/scripts/controllers/metametrics.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ export default class MetaMetricsController {
5757
/**
5858
* @param {Object} segment - an instance of analytics-node for tracking
5959
* events that conform to the new MetaMetrics tracking plan.
60-
* @param {Object} segmentLegacy - an instance of analytics-node for
61-
* tracking legacy schema events. Will eventually be phased out
6260
* @param {Object} preferencesStore - The preferences controller store, used
6361
* to access and subscribe to preferences that will be attached to events
6462
* @param {function} onNetworkDidChange - Used to attach a listener to the
@@ -73,7 +71,6 @@ export default class MetaMetricsController {
7371
*/
7472
constructor({
7573
segment,
76-
segmentLegacy,
7774
preferencesStore,
7875
onNetworkDidChange,
7976
getCurrentChainId,
@@ -105,7 +102,6 @@ export default class MetaMetricsController {
105102
this.network = getNetworkIdentifier();
106103
});
107104
this.segment = segment;
108-
this.segmentLegacy = segmentLegacy;
109105
}
110106

111107
generateMetaMetricsId() {
@@ -260,6 +256,12 @@ export default class MetaMetricsController {
260256
}
261257
payload[idType] = idValue;
262258

259+
// If this is an event on the old matomo schema, add a key to the payload
260+
// to designate it as such
261+
if (matomoEvent === true) {
262+
payload.properties.legacy_event = true;
263+
}
264+
263265
// Promises will only resolve when the event is sent to segment. For any
264266
// event that relies on this promise being fulfilled before performing UI
265267
// updates, or otherwise delaying user interaction, supply the
@@ -278,11 +280,9 @@ export default class MetaMetricsController {
278280
return resolve();
279281
};
280282

281-
const target = matomoEvent === true ? this.segmentLegacy : this.segment;
282-
283-
target.track(payload, callback);
283+
this.segment.track(payload, callback);
284284
if (flushImmediately) {
285-
target.flush();
285+
this.segment.flush();
286286
}
287287
});
288288
}

app/scripts/controllers/metametrics.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import MetaMetricsController from './metametrics';
1111
import { NETWORK_EVENTS } from './network';
1212

1313
const segment = createSegmentMock(2, 10000);
14-
const segmentLegacy = createSegmentMock(2, 10000);
1514

1615
const VERSION = '0.0.1-test';
1716
const NETWORK = 'Mainnet';
@@ -91,7 +90,6 @@ function getMetaMetricsController({
9190
} = {}) {
9291
return new MetaMetricsController({
9392
segment,
94-
segmentLegacy,
9593
getNetworkIdentifier: networkController.getNetworkIdentifier.bind(
9694
networkController,
9795
),
@@ -286,7 +284,7 @@ describe('MetaMetricsController', function () {
286284
});
287285

288286
it('should track a legacy event', function () {
289-
const mock = sinon.mock(segmentLegacy);
287+
const mock = sinon.mock(segment);
290288
const metaMetricsController = getMetaMetricsController();
291289
mock
292290
.expects('track')
@@ -297,6 +295,7 @@ describe('MetaMetricsController', function () {
297295
context: DEFAULT_TEST_CONTEXT,
298296
properties: {
299297
test: 1,
298+
legacy_event: true,
300299
...DEFAULT_EVENT_PROPERTIES,
301300
},
302301
});
@@ -544,7 +543,6 @@ describe('MetaMetricsController', function () {
544543
afterEach(function () {
545544
// flush the queues manually after each test
546545
segment.flush();
547-
segmentLegacy.flush();
548546
sinon.restore();
549547
});
550548
});

app/scripts/lib/segment.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const isDevOrTestEnvironment = Boolean(
44
process.env.METAMASK_DEBUG || process.env.IN_TEST,
55
);
66
const SEGMENT_WRITE_KEY = process.env.SEGMENT_WRITE_KEY ?? null;
7-
const SEGMENT_LEGACY_WRITE_KEY = process.env.SEGMENT_LEGACY_WRITE_KEY ?? null;
87
const SEGMENT_HOST = process.env.SEGMENT_HOST ?? null;
98

109
// flushAt controls how many events are sent to segment at once. Segment will
@@ -90,12 +89,3 @@ export const segment =
9089
flushAt: SEGMENT_FLUSH_AT,
9190
flushInterval: SEGMENT_FLUSH_INTERVAL,
9291
});
93-
94-
export const segmentLegacy =
95-
!SEGMENT_LEGACY_WRITE_KEY || (isDevOrTestEnvironment && !SEGMENT_HOST)
96-
? createSegmentMock(SEGMENT_FLUSH_AT, SEGMENT_FLUSH_INTERVAL)
97-
: new Analytics(SEGMENT_LEGACY_WRITE_KEY, {
98-
host: SEGMENT_HOST,
99-
flushAt: SEGMENT_FLUSH_AT,
100-
flushInterval: SEGMENT_FLUSH_INTERVAL,
101-
});

app/scripts/metamask-controller.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import nodeify from './lib/nodeify';
5858
import accountImporter from './account-import-strategies';
5959
import seedPhraseVerifier from './lib/seed-phrase-verifier';
6060
import MetaMetricsController from './controllers/metametrics';
61-
import { segment, segmentLegacy } from './lib/segment';
61+
import { segment } from './lib/segment';
6262
import createMetaRPCHandler from './lib/createMetaRPCHandler';
6363

6464
export const METAMASK_CONTROLLER_EVENTS = {
@@ -128,7 +128,6 @@ export default class MetamaskController extends EventEmitter {
128128

129129
this.metaMetricsController = new MetaMetricsController({
130130
segment,
131-
segmentLegacy,
132131
preferencesStore: this.preferencesController.store,
133132
onNetworkDidChange: this.networkController.on.bind(
134133
this.networkController,

0 commit comments

Comments
 (0)