1
0
mirror of https://github.com/uetchy/namae.git synced 2025-08-20 18:08:11 +09:00

feat: add sentry

This commit is contained in:
2019-09-24 13:55:07 +09:00
parent 85520b2417
commit a7efe886ab
7 changed files with 141 additions and 46 deletions

41
web/src/util/analytics.ts Normal file
View File

@@ -0,0 +1,41 @@
import ReactGA from 'react-ga';
import * as Sentry from '@sentry/browser';
const isProduction = process.env.NODE_ENV !== 'development';
export function initGA() {
if (isProduction) {
ReactGA.initialize('UA-28919359-15');
ReactGA.pageview(window.location.pathname + window.location.search);
}
}
export function sendQueryStatistics(queryLength: number) {
if (isProduction) {
ReactGA.event({
category: 'Search',
action: 'New search invoked',
value: queryLength,
});
}
}
export function initSentry() {
if (isProduction) {
Sentry.init({
dsn: 'https://7ab2df74aead499b950ebef190cc40b7@sentry.io/1759299',
});
}
}
export function sendError(error: Error, errorInfo: any): Promise<string> {
return new Promise((resolve) => {
if (isProduction) {
Sentry.withScope((scope) => {
scope.setExtras(errorInfo);
const eventId = Sentry.captureException(error);
resolve(eventId);
});
}
});
}