@kiwicom/smart-faq
Version:
Smart FAQ
68 lines (61 loc) • 1.36 kB
JavaScript
// @flow
/* eslint-disable no-console */
import type {
CuckooAction,
CuckooEvent,
CuckooErrorEvent,
CuckooError,
CuckooProps,
Subcategory,
CuckooLogger,
} from './cuckooTypes';
const printEventInfo = (event, props) => {
if (process.env.NODE_ENV === 'test') return;
console.info(event.subcategory, event.action, props);
};
let tracker = {
track: (event: CuckooEvent, props: ?CuckooProps) => {
printEventInfo(event, props);
},
warning: (event: CuckooEvent, props: ?CuckooProps) => {
printEventInfo(event, props);
},
error: (event: CuckooErrorEvent, props: ?CuckooProps) => {
printEventInfo(event, props);
},
};
export const setTracker = (cuckoo: CuckooLogger) => {
tracker = cuckoo;
};
export const error = (
errorType: CuckooError,
error: ?Error,
props: ?CuckooProps,
) =>
tracker.error(
{
category: 'smartFAQ',
subcategory: 'Error',
action: errorType,
destinations: { logmole: true, exponea: false, ga: false },
},
{
...(props || {}),
originalError: error,
},
);
export const track = (
subcategory: Subcategory,
action: CuckooAction,
props: ?CuckooProps,
) => {
tracker.track(
{
category: 'smartFAQ',
subcategory,
action,
destinations: { logmole: false, exponea: true, ga: false },
},
props,
);
};