diff --git a/src/browser/rvm/rvm_message_bus.ts b/src/browser/rvm/rvm_message_bus.ts index fa64b838e..db6003fee 100644 --- a/src/browser/rvm/rvm_message_bus.ts +++ b/src/browser/rvm/rvm_message_bus.ts @@ -2,9 +2,10 @@ import { WMCopyData } from '../transport'; import { EventEmitter } from 'events'; import * as log from '../log'; import route from '../../common/route'; -import { argo } from '../core_state'; +import { argo, getConfigUrlByUuid } from '../core_state'; import { app } from 'electron'; +import { Identity } from '../api_protocol/transport_strategy/api_transport_base'; const _ = require('underscore'); const processVersions = process.versions; @@ -173,6 +174,7 @@ export interface Cleanup extends RvmMsgBase { // topic: system ----- type systemTopic = 'system'; type getRvmInfoAction = 'get-rvm-info'; +type sendCoreAnalyticsEvent = 'send-core-analytics-event'; export interface System extends RvmMsgBase { topic: systemTopic; @@ -180,6 +182,19 @@ export interface System extends RvmMsgBase { sourceUrl: string; } +interface CoreAnalytics extends RvmMsgBase { + topic: systemTopic; + action: sendCoreAnalyticsEvent; + sourceUrl: string; + diagnosticsEvent: AnalyticsEvent; +} + +interface AnalyticsEvent { + topic: string; + event: string; + createdAt: string; + payload?: any; +} // topic: application-events ----- type EventType = 'started'| 'closed' | 'ready' | 'run-requested' | 'crashed' | 'error' | 'not-responding'; @@ -415,6 +430,35 @@ export class RVMMessageBus extends EventEmitter { }; this.publish(rvmPayload, callback); } + + public sendCoreAnalyticsEvent(event: string, payload: any, identity?: Identity): Promise { + let sourceUrl = ''; + let uuid: string; + if (typeof identity === 'object' && identity.uuid) { + sourceUrl = getConfigUrlByUuid(identity.uuid); + uuid = identity.uuid; + } + + return new Promise((resolve, reject) => { + try { + const rvmMsg: CoreAnalytics = { + topic: 'system', + action: 'send-core-analytics-event', + sourceUrl, + ...uuid ? { uuid } : {}, + diagnosticsEvent: { + event, + topic: 'analytics.core.event', + createdAt: new Date().toISOString(), + payload + } + }; + this.publish(rvmMsg, resolve); + } catch (err) { + reject(err); + } + }); + } } const rvmMessageBus = new RVMMessageBus(); export {rvmMessageBus};