'use strict'; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019, 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore'], function (_) { var TRACK_TYPE_APPLICATION = 'application'; var WIDGET_CATEGORY = 'InProduct'; var WIDGET_DETAILS_PREFIX = 'custom.'; var dataSourceInfoMap = { uploadedFile: 'custom.counts.uploadedFile', module: 'custom.counts.dataModule', package: 'custom.counts.fmPackage' }; var widgetTypeMap = { data: 'custom.counts.data_widget', nondata: 'custom.counts.nondata_widget' }; return function () { function Segment(options) { _classCallCheck(this, Segment); this.dashboardApi = options.dashboardApi; this.instrumentationSvc = options.instrumentationSvc; this.logger = options.logger; this.infoCallback = undefined; } Segment.prototype.registerInfoCallback = function registerInfoCallback(cb) { this.infoCallback = cb; }; Segment.prototype.unregisterInfoCallback = function unregisterInfoCallback() { this.infoCallback = null; }; Segment.prototype.track = function track(action, getInfoCallback) { try { var globalInfo = this.infoCallback ? this.infoCallback() : {}; var suppliedInfo = getInfoCallback ? getInfoCallback() : {}; suppliedInfo = _extends({}, globalInfo, suppliedInfo); suppliedInfo.action = action; var trackType = suppliedInfo.trackType || TRACK_TYPE_APPLICATION; delete suppliedInfo.trackType; if (this._canTrack(trackType)) { var payload = this.getInfo(suppliedInfo, trackType); payload.action = action; payload.milestoneName = payload.milestoneName ? payload.milestoneName : action + '_' + payload.objectType; this.instrumentationSvc.track(payload); } } catch (e) { this.logger.error(e); } }; Segment.prototype._canTrack = function _canTrack(trackType) { return trackType === TRACK_TYPE_APPLICATION || this.dashboardApi.getApplicationName() !== 'explore'; }; Segment.prototype.getInfo = function getInfo() { var suppliedInfo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var trackType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TRACK_TYPE_APPLICATION; return trackType === TRACK_TYPE_APPLICATION ? this._getApplicationInfo(suppliedInfo) : this._getWidgetInfo(suppliedInfo, trackType); }; Segment.prototype._getApplicationInfo = function _getApplicationInfo() { var suppliedInfo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var detailsInfo = this._getApplicationDetailsInfo(); return _extends({ type: suppliedInfo.type, objectType: this.dashboardApi.getApplicationName(), object: this._getBoardId() }, detailsInfo, suppliedInfo); }; Segment.prototype._getWidgetInfo = function _getWidgetInfo() { var suppliedInfo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var trackType = arguments[1]; var details = {}; if (suppliedInfo.details) { _.each(suppliedInfo.details, function (value, name) { details[WIDGET_DETAILS_PREFIX + name] = value; }); } var payload = _extends({ type: suppliedInfo.type, objectType: trackType, category: WIDGET_CATEGORY }, details); if (suppliedInfo.object) { payload.object = suppliedInfo.object; } payload.milestoneName = suppliedInfo.action + '_' + trackType + '_in_' + this.dashboardApi.getApplicationName(); return payload; }; Segment.prototype._getBoardId = function _getBoardId() { return this.dashboardApi.getDashboardInfo().boardId; }; Segment.prototype._getApplicationDetailsInfo = function _getApplicationDetailsInfo() { var dataSourcesInfo = this._getApplicationDataSourcesInfo(); var widgetsInfo = this._getApplicationWidgetsInfo(); return _extends({}, dataSourcesInfo, widgetsInfo, { 'custom.counts.tabs': this._getApplicationTabsCount() }); }; Segment.prototype._getApplicationDataSourcesInfo = function _getApplicationDataSourcesInfo() { var dataSourceList = this.dashboardApi.getFeature('DataSources').getDataSourceList(); return Segment.getDataSourcesTypeCount(dataSourceList); }; Segment.prototype._getApplicationWidgetsInfo = function _getApplicationWidgetsInfo() { var widgets = this.dashboardApi.getCanvas().findContent({ type: 'widget' }); return Segment.getWidgetsTypeCount(widgets); }; Segment.prototype._getApplicationTabsCount = function _getApplicationTabsCount() { var tabs = this.dashboardApi.getCanvas().findContent({ type: 'container' }); return tabs.length; }; Segment.prototype.destroy = function destroy() { this.dashboardApi = null; this.glassContext = null; this.instrumentationSvc = null; }; Segment.getDataSourcesTypeCount = function getDataSourcesTypeCount() { var dataSourceList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var info = dataSourceList.reduce(function (acc, dataSource) { var _extends2; var type = dataSource.getType(); return _extends({}, acc, (_extends2 = {}, _extends2[dataSourceInfoMap[type]] = (acc[dataSourceInfoMap[type]] || 0) + 1, _extends2)); }, {}); return info; }; Segment.getWidgetsTypeCount = function getWidgetsTypeCount() { var widgets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var info = widgets.reduce(function (acc, widget) { var _extends3; var type = widget.getType() === 'live' || widget.getType() === 'widget.live' ? 'data' : 'nondata'; return _extends({}, acc, (_extends3 = {}, _extends3[widgetTypeMap[type]] = (acc[widgetTypeMap[type]] || 0) + 1, _extends3)); }, {}); return info; }; return Segment; }(); }); //# sourceMappingURL=Segment.js.map