UNPKG

@atlassian/wrm-troubleshooting

Version:

A tool that can help you with troubleshooting the configuration of webpack and Atlassian P2 project.

74 lines 3.17 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.trackEvent = void 0; const Amplitude = __importStar(require("@amplitude/node")); const fs_1 = require("fs"); const os_1 = __importDefault(require("os")); const path_1 = __importDefault(require("path")); // Unique ID for WRM Troubleshooting Tool const AMP_CLIENT_ID = '490d4e87c5c2b9c250de24d48ce09303'; // TODO: Fix me and detect local mode when we are running tool without installing it from NPM const IS_DEV_MODE = process.env.NODE_ENV === 'test'; // Configure Amplitude const client = Amplitude.init(AMP_CLIENT_ID); const isObject = (value) => Object.prototype.toString.call(value) === '[object Object]'; let pkgVersion; async function trackEvent(eventName, customProperties = null) { // Don't send the analytics from within a dev mode if (IS_DEV_MODE) { return; } if (!pkgVersion) { // We need to read the package.json file manually. We can't import the package.json file using ESM syntax since if we do that // TSC would copy the package.json file into "dist" directory. // Having a copy of package.json file under "dist" directory would mess-up with the package distribution. try { const pkg = await fs_1.promises.readFile(path_1.default.join(__dirname, '../../package.json')); const { version } = JSON.parse(pkg.toString()); pkgVersion = version; } catch (e) { // eslint-disable-next-line no-empty pkgVersion = 'unknown'; } } let eventProperties; if (isObject(customProperties)) { eventProperties = Object.assign({}, customProperties); } await client.logEvent({ event_type: eventName, device_id: 'required-but-not-used', event_properties: eventProperties, // Non-required properties // https://developers.amplitude.com/docs/http-api-v2 app_version: pkgVersion, platform: os_1.default.platform(), os_name: os_1.default.type(), os_version: os_1.default.release(), }); } exports.trackEvent = trackEvent; //# sourceMappingURL=analytics.js.map