1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-19 13:30:32 +09:00
namae/web/src/util/analytics.ts

48 lines
1.1 KiB
TypeScript
Raw Normal View History

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);
});
}
});
}