UNPKG

@grafana/faro-web-sdk

Version:

Faro instrumentations, metas, transports for web.

68 lines 3.98 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.NavigationInstrumentation = void 0; var faro_core_1 = require("@grafana/faro-core"); var activityWindowTracker_1 = require("../_internal/activityWindowTracker"); var domMutationMonitor_1 = require("../_internal/monitors/domMutationMonitor"); var httpRequestMonitor_1 = require("../_internal/monitors/httpRequestMonitor"); var interactionMonitor_1 = require("../_internal/monitors/interactionMonitor"); var urlChangeMonitor_1 = require("../_internal/monitors/urlChangeMonitor"); var NavigationInstrumentation = /** @class */ (function (_super) { __extends(NavigationInstrumentation, _super); function NavigationInstrumentation() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.name = '@grafana/faro-web-sdk:instrumentation-navigation'; _this.version = faro_core_1.VERSION; return _this; } NavigationInstrumentation.prototype.initialize = function () { var httpMonitor = (0, httpRequestMonitor_1.monitorHttpRequests)(); var domMutationsMonitor = (0, domMutationMonitor_1.monitorDomMutations)(); var urlMonitor = (0, urlChangeMonitor_1.monitorUrlChanges)(); var interactionMonitor = (0, interactionMonitor_1.monitorInteractions)(['pointerdown', 'keydown']); var activityWindowTracker = new activityWindowTracker_1.ActivityWindowTracker(new faro_core_1.Observable().merge(httpMonitor, domMutationsMonitor, urlMonitor), { inactivityMs: 100, drainTimeoutMs: 10 * 1000, isOperationStart: function (msg) { return ((0, activityWindowTracker_1.isRequestStartMessage)(msg) ? msg.request.requestId : undefined); }, isOperationEnd: function (msg) { return ((0, activityWindowTracker_1.isRequestEndMessage)(msg) ? msg.request.requestId : undefined); }, }); activityWindowTracker .filter(function (msg) { return msg.message === 'tracking-ended'; }) .subscribe(function (msg) { var _a, _b, _c; if (((_a = msg.events) === null || _a === void 0 ? void 0 : _a.some(function (e) { return e.type === 'url-change'; })) && ((_b = msg.events) === null || _b === void 0 ? void 0 : _b.some(function (e) { return e.type === 'dom-mutation'; }))) { var urlChange = (_c = msg.events) === null || _c === void 0 ? void 0 : _c.find(function (e) { return 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(function () { activityWindowTracker.startTracking(); }); }; return NavigationInstrumentation; }(faro_core_1.BaseInstrumentation)); exports.NavigationInstrumentation = NavigationInstrumentation; //# sourceMappingURL=instrumentation.js.map