@grafana/faro-react
Version:
Faro package that enables easier integration in projects built with React.
35 lines • 1.56 kB
JavaScript
import hoistNonReactStatics from 'hoist-non-react-statics';
import { globalObject } from '@grafana/faro-web-sdk';
import { NavigationType, ReactRouterVersion } from '../types';
import { createNewActiveEvent, sendActiveEvent } from './activeEvent';
import { FaroRoute } from './FaroRoute';
import { setReactRouterV4V5Dependencies } from './routerDependencies';
export function initializeReactRouterV4V5Instrumentation(dependencies) {
var _a, _b, _c, _d;
const Route = dependencies.Route;
const componentDisplayName = (_a = Route.displayName) !== null && _a !== void 0 ? _a : Route.name;
FaroRoute.displayName = `faroRoute(${componentDisplayName})`;
hoistNonReactStatics(FaroRoute, Route);
setReactRouterV4V5Dependencies(dependencies);
createNewActiveEvent((_b = globalObject.location) === null || _b === void 0 ? void 0 : _b.href);
(_d = (_c = dependencies.history).listen) === null || _d === void 0 ? void 0 : _d.call(_c, (_location, action) => {
var _a;
if (action === NavigationType.Push || action === NavigationType.Pop) {
sendActiveEvent();
createNewActiveEvent((_a = globalObject.location) === null || _a === void 0 ? void 0 : _a.href);
}
});
}
export function createReactRouterV4Options(dependencies) {
return {
version: ReactRouterVersion.V4,
dependencies,
};
}
export function createReactRouterV5Options(dependencies) {
return {
version: ReactRouterVersion.V5,
dependencies,
};
}
//# sourceMappingURL=initialize.js.map