UNPKG

@google/dscc-gen

Version:

Create component & connector projects with sane defaults.

53 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkForOptOut = exports.trackEvent = exports.Action = exports.Category = void 0; const bluebird = require("bluebird"); const Insight = require("insight"); const terminal_link_1 = require("terminal-link"); const uuid4 = require("uuid/v4"); const util_1 = require("./util"); const executionId = uuid4(); const packageName = process.env.npm_package_name !== undefined ? process.env.npm_package_name : 'this tool'; const insight = new Insight({ // Google Analytics tracking code trackingCode: 'UA-41425441-15', pkg: { name: packageName, }, }); // Give enough time to actually read our link. insight._permissionTimeout = 60 * 5; const askPermission = bluebird.promisify(insight.askPermission, { context: insight, }); var Category; (function (Category) { Category["EXECUTION"] = "execution"; })(Category = exports.Category || (exports.Category = {})); var Action; (function (Action) { Action["START"] = "start"; Action["STOP"] = "stop"; Action["ERROR_STOP"] = "error_stop"; Action["GSUTIL_NOT_INSTALLED"] = "gsutil_not_installed"; Action["SIGINT_STOP"] = "sigint_stop"; })(Action = exports.Action || (exports.Action = {})); exports.trackEvent = (category, action) => { insight.trackEvent({ category, action, label: executionId, }); }; exports.checkForOptOut = async () => { if (insight.optOut === undefined) { const name = util_1.format.blue(packageName); const link = util_1.format.green(terminal_link_1.default('What we collect', 'https://github.com/googledatastudio/dscc-gen#what-we-collect')); const insightMessage = `May ${name} anonymously report usage statistics to improve over time? ${link}`; await askPermission(insightMessage); } return insight.optOut; }; //# sourceMappingURL=analytics.js.map