'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(['../../../features/dashboard/segment/api/impl/Segment'], function (Segment) { return function () { function InstrumentationUtil() { _classCallCheck(this, InstrumentationUtil); } /** * Calls the glass service directly to track a user action * * @param {object} The glass context * @param {string} The action to track * @param {object} Contains the context to track */ InstrumentationUtil.track = function track(glassContext, action) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var instrumentationSvc = glassContext.getCoreSvc('.Instrumentation'); if (instrumentationSvc && instrumentationSvc.enabled) { var widgetsCount = {}; var datasourcesCount = {}; if (options.sources && options.sources.length > 0) { var dataSourceList = options.sources.map(function (source) { if (source.getType) { return source; } else { return { getType: function getType() { return source.type; } }; } }); datasourcesCount = Segment.getDataSourcesTypeCount(dataSourceList); } if (options.widgets && options.widgets.length > 0) { var widgetList = options.widgets.map(function (widget) { if (widget.getType) { return widget; } else { return { getType: function getType() { return widget.type; } }; } }); widgetsCount = Segment.getWidgetsTypeCount(widgetList); } var payload = _extends({ type: options.type, objectType: options.objectType, action: action, milestoneName: action + '_' + options.objectType }, datasourcesCount, widgetsCount); if (options.object) { payload.object = options.object; } instrumentationSvc.track(payload); } }; InstrumentationUtil.trackWidget = function trackWidget(action, dashboardApi) { var widgetSpec = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var widgetId = arguments[3]; var widgetType = void 0; var trackType = void 0; var widgetSource = void 0; if (action === 'deleted') { var canvasAPI = dashboardApi.getCanvas(); var contentAPI = canvasAPI.getContent(widgetId); if (contentAPI) { if (contentAPI.getType() === 'widget.live') { trackType = 'data_widget'; var stringResources = dashboardApi.getDashboardCoreSvc('.StringResources'); var visualization = contentAPI.getFeature('Visualization'); var error = contentAPI.getFeature('state').getError() || null; var params = error ? error.getParams() : null; var errorInfo = params ? params.errorInfo : null; widgetType = errorInfo ? errorInfo.id : visualization.getDefinition() ? visualization.getDefinition().getLabel() : stringResources.get('one_unknown_live'); } else { trackType = 'nonData_widget'; widgetType = contentAPI.getType(); } } } else { var getWidgetSource = function getWidgetSource() { return widgetSpec && widgetSpec.data && widgetSpec.data.dataViews && widgetSpec.data.dataViews.length ? 'fromRecommendation' : 'manual'; }; widgetSource = getWidgetSource(); //Recommendation is being tracked from another component if (widgetSource !== 'fromRecommendation') { trackType = widgetSpec.type === 'live' ? 'data_widget' : 'nonData_widget'; widgetType = widgetSpec.name || widgetSpec.type; } } if (widgetType) { var callback = function callback() { var payload = { details: { widgetType: widgetType, assetType: dashboardApi.getApplicationName() }, type: action === 'deleted' ? 'Deleted Object' : 'Created Object', trackType: trackType, widgetType: widgetType }; if (widgetId) { payload.object = widgetId; } var assetId = dashboardApi.getDashboardInfo().boardId; if (assetId) { payload.details['assetId'] = assetId; } if (widgetSource) { payload.widgetSource = widgetSource; //'created' payload.details.widgetSource = widgetSource; //'created' } return payload; }; var segment = dashboardApi.getFeature('segment'); segment.track(action, callback); } }; return InstrumentationUtil; }(); }); //# sourceMappingURL=InstrumentationUtil.js.map