Skip to content

Implement a public collectMetadata function for telemetry #2036

@paulkaplan

Description

@paulkaplan

There is a standard set of project metadata that is sent with telemetry events which is currently created manually, we should move it to the VM where it belongs. Currently this is done on the gui/scratch-desktop branch since only the offline editor uses it. Here is that implementation:

https://github.com/LLK/scratch-gui/compare/scratch-desktop#diff-2e0062a7e2f44684af5a0ef1cf858c52R7

/**
 * Report a telemetry event.
 * @param {string} event - one of `projectWasCreated`, `projectDidLoad`, `projectDidSave`, `projectWasUploaded`
 */
//TODO make a telemetry HOC and move this stuff there
const collectMetadata = function (vm, projectName = '', locale = '') {
    //TODO move most or all of this into a collectMetadata() method on the VM/Runtime
    const metadata = {
        projectName: projectName,
        language: locale,
        spriteCount: 0,
        blocksCount: 0,
        costumesCount: 0,
        listsCount: 0,
        scriptCount: 0,
        soundsCount: 0,
        variablesCount: 0
    };

    for (const target of vm.runtime.targets) {
        ++metadata.spriteCount;
        metadata.blocksCount += Object.keys(target.sprite.blocks._blocks).length;
        metadata.costumesCount += target.sprite.costumes_.length;
        metadata.scriptCount += target.sprite.blocks._scripts.length;
        metadata.soundsCount += target.sprite.sounds.length;
        for (const variableName in target.variables) {
            const variable = target.variables[variableName];
            if (variable.type === 'list') {
                ++metadata.listsCount;
            } else {
                ++metadata.variablesCount;
            }
        }
    }

    return metadata;
};

export default collectMetadata;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions