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