UNPKG

@embrace-io/web-sdk

Version:
42 lines (41 loc) 1.62 kB
import { EmbraceInstrumentationBase } from "../../EmbraceInstrumentationBase/EmbraceInstrumentationBase.js"; import { getHTMLElementFriendlyName } from "./utils.js"; //#region src/instrumentations/clicks/ClicksInstrumentation/ClicksInstrumentation.ts var ClicksInstrumentation = class extends EmbraceInstrumentationBase { _onClickHandler; constructor({ diag, perf, shouldTrack, innerTextForElement } = {}) { super({ instrumentationName: "ClicksInstrumentation", instrumentationVersion: "1.0.0", diag, perf, config: {} }); this._onClickHandler = (event) => { const element = event.target; if (!(element instanceof HTMLElement)) return; if (element.hasAttribute("disabled")) return; if (shouldTrack && !shouldTrack(element)) return; try { const currentSessionPartSpan = this.userSessionManager.getSessionPartSpan(); if (currentSessionPartSpan) currentSessionPartSpan.addEvent("click", { "emb.type": "ux.tap", "view.name": getHTMLElementFriendlyName(element, innerTextForElement ? innerTextForElement(element) : element.innerText), "tap.coords": `${event.x.toString()},${event.y.toString()}` }, this.perf.epochMillisFromOrigin(event.timeStamp)); } catch (e) { this._diag.error("failed to create new user interaction span event", e); } }; if (this._config.enabled) this.enable(); } onDisable() { document.removeEventListener("click", this._onClickHandler); } onEnable() { document.addEventListener("click", this._onClickHandler); } }; //#endregion export { ClicksInstrumentation }; //# sourceMappingURL=ClicksInstrumentation.js.map