mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2026-01-16 17:02:38 +01:00
Add analytic events
This commit is contained in:
21
src/shell/analytics.ts
Normal file
21
src/shell/analytics.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import log from 'loglevel';
|
||||
|
||||
export type AnalyticsEvent = {
|
||||
eventCategory: string,
|
||||
eventAction: string,
|
||||
eventLabel?: string
|
||||
};
|
||||
|
||||
export type AnalyticsHandler = (evt: AnalyticsEvent) => boolean;
|
||||
|
||||
function sendAnalyticsEvent(evt : AnalyticsEvent) {
|
||||
const handler = (window as any).bitwiseCmdAnalyticsHandler;
|
||||
if(handler == null) {
|
||||
log.debug('ERROR!!!: Analytics event was not sent. Handler not found');
|
||||
}
|
||||
|
||||
const delivered = (handler as AnalyticsHandler)(evt);
|
||||
log.debug('Analytics event sent. Delivery response: ' + delivered, evt)
|
||||
}
|
||||
|
||||
export {sendAnalyticsEvent};
|
||||
@@ -1,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import uuid from 'uuid';
|
||||
import { sendAnalyticsEvent } from './analytics';
|
||||
import AppState from './AppState';
|
||||
import { CmdShell, CommandInput } from './cmd';
|
||||
import AboutResultView from './components/AboutResultView';
|
||||
@@ -30,6 +31,13 @@ const shellModule = {
|
||||
appState.addCommandResult(c.input, <TextResultView text={`Debug Mode: ${appState.debugMode}`}/>);
|
||||
});
|
||||
|
||||
cmd.command("track", (c:CommandInput) => {
|
||||
sendAnalyticsEvent({
|
||||
eventCategory: 'General',
|
||||
eventAction: 'AnalyticsTest'
|
||||
});
|
||||
});
|
||||
|
||||
if(appState.env !== 'prod') {
|
||||
|
||||
// Default command for development purposes
|
||||
|
||||
Reference in New Issue
Block a user