@grafana/faro-web-sdk
Version:
Faro instrumentations, metas, transports for web.
28 lines • 1.14 kB
JavaScript
import { BaseInstrumentation, faro, userActionsMessageBus, VERSION } from '@grafana/faro-core';
import { getUserEventHandler } from './processUserActionEventHandler';
export class UserActionInstrumentation extends BaseInstrumentation {
constructor() {
super(...arguments);
this.name = '@grafana/faro-web-sdk:instrumentation-user-action';
this.version = VERSION;
}
initialize() {
const { processUserEvent, processUserActionStarted } = getUserEventHandler(faro);
window.addEventListener('pointerdown', processUserEvent);
window.addEventListener('keydown', (ev) => {
if ([' ', 'Enter'].includes(ev.key)) {
processUserEvent(ev);
}
});
this._userActionSub = userActionsMessageBus.subscribe(({ type, userAction }) => {
if (type === 'user_action_start') {
processUserActionStarted(userAction);
}
});
}
destroy() {
var _a;
(_a = this._userActionSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
}
}
//# sourceMappingURL=instrumentation.js.map