UNPKG

@grafana/faro-web-sdk

Version:

Faro instrumentations, metas, transports for web.

50 lines 2.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NavigationInstrumentation = void 0; const faro_core_1 = require("@grafana/faro-core"); const activityWindowTracker_1 = require("../_internal/activityWindowTracker"); const domMutationMonitor_1 = require("../_internal/monitors/domMutationMonitor"); const httpRequestMonitor_1 = require("../_internal/monitors/httpRequestMonitor"); const interactionMonitor_1 = require("../_internal/monitors/interactionMonitor"); const urlChangeMonitor_1 = require("../_internal/monitors/urlChangeMonitor"); class NavigationInstrumentation extends faro_core_1.BaseInstrumentation { constructor() { super(...arguments); this.name = '@grafana/faro-web-sdk:instrumentation-navigation'; this.version = faro_core_1.VERSION; } initialize() { const httpMonitor = (0, httpRequestMonitor_1.monitorHttpRequests)(); const domMutationsMonitor = (0, domMutationMonitor_1.monitorDomMutations)(); const urlMonitor = (0, urlChangeMonitor_1.monitorUrlChanges)(); const interactionMonitor = (0, interactionMonitor_1.monitorInteractions)(['pointerdown', 'keydown']); const activityWindowTracker = new activityWindowTracker_1.ActivityWindowTracker(new faro_core_1.Observable().merge(httpMonitor, domMutationsMonitor, urlMonitor), { inactivityMs: 100, drainTimeoutMs: 10 * 1000, isOperationStart: (msg) => ((0, activityWindowTracker_1.isRequestStartMessage)(msg) ? msg.request.requestId : undefined), isOperationEnd: (msg) => ((0, activityWindowTracker_1.isRequestEndMessage)(msg) ? msg.request.requestId : undefined), }); activityWindowTracker .filter((msg) => { return msg.message === 'tracking-ended'; }) .subscribe((msg) => { var _a, _b, _c; if (((_a = msg.events) === null || _a === void 0 ? void 0 : _a.some((e) => e.type === 'url-change')) && ((_b = msg.events) === null || _b === void 0 ? void 0 : _b.some((e) => e.type === 'dom-mutation'))) { const urlChange = (_c = msg.events) === null || _c === void 0 ? void 0 : _c.find((e) => e.type === 'url-change'); faro_core_1.faro.api.pushEvent('faro.navigation', { fromUrl: urlChange === null || urlChange === void 0 ? void 0 : urlChange.from, toUrl: urlChange === null || urlChange === void 0 ? void 0 : urlChange.to, sameDocument: String(true), duration: msg.duration, }); } }); interactionMonitor.subscribe(() => { activityWindowTracker.startTracking(); }); } } exports.NavigationInstrumentation = NavigationInstrumentation; //# sourceMappingURL=instrumentation.js.map