mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-10 06:52:05 +01:00
Add analytic events
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
(function() {
|
||||
|
||||
var SEND_ANALYTICS_FOR_NON_PROD = false;
|
||||
|
||||
window.bitwiseCmdAnalyticsHandler = function() {return false};
|
||||
|
||||
var key = 'TrackAnalytics';
|
||||
var disableAnalytics = localStorage.getItem(key) === 'false' || window.location.hash.indexOf('-notrack') > -1
|
||||
|
||||
@@ -9,7 +13,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if(window.location.host !== 'bitwisecmd.com') {
|
||||
if(window.location.host !== 'bitwisecmd.com' && !SEND_ANALYTICS_FOR_NON_PROD) {
|
||||
console.log("Analytics not tracked. Non-prod host")
|
||||
return;
|
||||
}
|
||||
@@ -21,4 +25,9 @@
|
||||
|
||||
ga('create', 'UA-61569164-1', 'auto');
|
||||
ga('send', 'pageview');
|
||||
|
||||
window.bitwiseCmdAnalyticsHandler = function(evt) {
|
||||
ga('send', Object.assign({hitType: 'event'}, evt));
|
||||
return true;
|
||||
}
|
||||
})();
|
||||
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