Skip to content

Commit 5b028a1

Browse files
author
Christopher Willis-Ford
committed
correctly format code metadata in telemetry events
1 parent 414a1f0 commit 5b028a1

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"eslint-plugin-import": "^2.18.0",
4646
"eslint-plugin-react": "^7.14.2",
4747
"intl": "1.2.5",
48+
"lodash.defaultsdeep": "^4.6.1",
4849
"mkdirp": "^0.5.1",
4950
"nets": "^3.2.0",
5051
"react": "16.2.0",

src/main/ScratchDesktopTelemetry.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import {app, ipcMain} from 'electron';
2+
import defaultsDeep from 'lodash.defaultsdeep';
23

34
import TelemetryClient from './telemetry/TelemetryClient';
45

56
const EVENT_TEMPLATE = {
67
version: '3.0.0',
78
projectName: '',
89
language: '',
9-
scriptCount: -1,
10-
spriteCount: -1,
11-
variablesCount: -1,
12-
blocksCount: -1,
13-
costumesCount: -1,
14-
listsCount: -1,
15-
soundsCount: -1
10+
metadata: {
11+
scriptCount: -1,
12+
spriteCount: -1,
13+
variablesCount: -1,
14+
blocksCount: -1,
15+
costumesCount: -1,
16+
listsCount: -1,
17+
soundsCount: -1
18+
}
1619
};
1720

1821
const APP_ID = 'scratch-desktop';
@@ -42,19 +45,28 @@ class ScratchDesktopTelemetry {
4245
}
4346

4447
projectDidLoad (metadata = {}) {
45-
this._telemetryClient.addEvent('project::load', {...EVENT_TEMPLATE, ...metadata});
48+
this._telemetryClient.addEvent('project::load', this._buildMetadata(metadata));
4649
}
4750

4851
projectDidSave (metadata = {}) {
49-
this._telemetryClient.addEvent('project::save', {...EVENT_TEMPLATE, ...metadata});
52+
this._telemetryClient.addEvent('project::save', this._buildMetadata(metadata));
5053
}
5154

5255
projectWasCreated (metadata = {}) {
53-
this._telemetryClient.addEvent('project::create', {...EVENT_TEMPLATE, ...metadata});
56+
this._telemetryClient.addEvent('project::create', this._buildMetadata(metadata));
5457
}
5558

5659
projectWasUploaded (metadata = {}) {
57-
this._telemetryClient.addEvent('project::upload', {...EVENT_TEMPLATE, ...metadata});
60+
this._telemetryClient.addEvent('project::upload', this._buildMetadata(metadata));
61+
}
62+
63+
_buildMetadata (metadata) {
64+
const { projectName, language, ...codeMetadata } = metadata;
65+
return defaultsDeep({
66+
projectName,
67+
language,
68+
metadata: codeMetadata
69+
}, EVENT_TEMPLATE);
5870
}
5971
}
6072

0 commit comments

Comments
 (0)