123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- '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
|