change(tracker): add option to disable click maps

This commit is contained in:
nick-delirium 2023-03-21 09:58:05 +01:00
parent 1815d7b6be
commit 74d8f91367
2 changed files with 12 additions and 4 deletions

View file

@ -34,6 +34,8 @@ import type { Options as InputOptions } from './modules/input.js'
import type { Options as PerformanceOptions } from './modules/performance.js'
import type { Options as TimingOptions } from './modules/timing.js'
import type { Options as NetworkOptions } from './modules/network.js'
import type { MouseHandlerOptions } from './modules/mouse.js'
import type { StartOptions } from './app/index.js'
//TODO: unique options init
import type { StartPromiseReturn } from './app/index.js'
@ -47,6 +49,7 @@ export type Options = Partial<
respectDoNotTrack?: boolean
autoResetOnWindowOpen?: boolean
network?: NetworkOptions
mouse?: MouseHandlerOptions
// dev only
__DISABLE_SECURE_MODE?: boolean
}
@ -125,7 +128,7 @@ export default class API {
Exception(app, options)
Img(app)
Input(app, options)
Mouse(app)
Mouse(app, options.mouse)
Timing(app, options)
Performance(app, options)
Scroll(app)

View file

@ -5,7 +5,7 @@ import { MouseMove, MouseClick, MouseThrashing } from '../app/messages.gen.js'
import { getInputLabel } from './input.js'
import { finder } from '@medv/finder'
function _getSelector(target: Element, document: Document): string {
function _getSelector(target: Element, document: Document) {
const selector = finder(target, {
root: document.body,
seedMinLength: 3,
@ -73,7 +73,12 @@ function _getTarget(target: Element, document: Document): Element | null {
return target === document.documentElement ? null : target
}
export default function (app: App): void {
export interface MouseHandlerOptions {
disableClickmaps?: boolean
}
export default function (app: App, options?: MouseHandlerOptions): void {
const { disableClickmaps = false } = options || {}
function getTargetLabel(target: Element): string {
const dl = getLabelAttribute(target)
if (dl !== null) {
@ -197,7 +202,7 @@ export default function (app: App): void {
id,
mouseTarget === target ? Math.round(performance.now() - mouseTargetTime) : 0,
getTargetLabel(target),
isClickable(target) ? getSelector(id, target) : '',
isClickable(target) && !disableClickmaps ? getSelector(id, target) : '',
),
true,
)