2019-09-24 13:55:07 +09:00
|
|
|
import ReactGA from 'react-ga';
|
|
|
|
import * as Sentry from '@sentry/browser';
|
|
|
|
|
|
|
|
const isProduction = process.env.NODE_ENV !== 'development';
|
|
|
|
|
2019-12-24 01:57:07 +09:00
|
|
|
export function initGA(): void {
|
2019-09-24 13:55:07 +09:00
|
|
|
if (isProduction) {
|
|
|
|
ReactGA.initialize('UA-28919359-15');
|
|
|
|
ReactGA.pageview(window.location.pathname + window.location.search);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-24 01:57:07 +09:00
|
|
|
export function sendQueryStatistics(queryLength: number): void {
|
2019-09-24 13:55:07 +09:00
|
|
|
if (isProduction) {
|
|
|
|
ReactGA.event({
|
|
|
|
category: 'Search',
|
|
|
|
action: 'New search invoked',
|
|
|
|
value: queryLength,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-24 01:57:07 +09:00
|
|
|
export function initSentry(): void {
|
2019-09-24 13:55:07 +09:00
|
|
|
if (isProduction) {
|
|
|
|
Sentry.init({
|
|
|
|
dsn: 'https://7ab2df74aead499b950ebef190cc40b7@sentry.io/1759299',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-24 01:57:07 +09:00
|
|
|
export function sendError(
|
|
|
|
error: Error,
|
|
|
|
errorInfo: {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
[key: string]: any;
|
|
|
|
},
|
|
|
|
): Promise<string> {
|
2019-09-24 13:55:07 +09:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
if (isProduction) {
|
|
|
|
Sentry.withScope((scope) => {
|
|
|
|
scope.setExtras(errorInfo);
|
|
|
|
const eventId = Sentry.captureException(error);
|
|
|
|
resolve(eventId);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|