Skip to content

Commit c892584

Browse files
committed
[PANA-6072] PoC - add composedPathSelector to click actions target
1 parent ff4b0a9 commit c892584

File tree

8 files changed

+588
-4
lines changed

8 files changed

+588
-4
lines changed

packages/rum-core/src/domain/action/trackClickActions.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ describe('trackClickActions', () => {
133133
selector: '#button',
134134
width: 100,
135135
height: 100,
136+
composed_path_selector: 'BUTTON#button[type="button"]:nth-child(1);',
136137
},
137138
position: { x: 50, y: 50 },
138139
events: [domEvent],

packages/rum-core/src/domain/action/trackClickActions.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type { RumConfiguration } from '../configuration'
1313
import type { RumMutationRecord } from '../../browser/domMutationObservable'
1414
import { startEventTracker } from '../eventTracker'
1515
import type { StoppedEvent, DiscardedEvent, EventTracker } from '../eventTracker'
16+
import { getComposedPathSelector } from '../getComposedPathSelector'
1617
import type { ClickChain } from './clickChain'
1718
import { createClickChain } from './clickChain'
1819
import { getActionNameFromElement } from './getActionNameFromElement'
@@ -36,6 +37,7 @@ export interface ClickAction {
3637
nameSource: ActionNameSource
3738
target?: {
3839
selector: string | undefined
40+
composed_path_selector?: string
3941
width: number
4042
height: number
4143
}
@@ -231,10 +233,16 @@ function computeClickActionBase(
231233
nodePrivacyLevel: NodePrivacyLevel,
232234
configuration: RumConfiguration
233235
): ClickActionBase {
236+
const eventPath = event.composedPath()
237+
234238
const selectorTarget = event.target
235239
const rect = selectorTarget.getBoundingClientRect()
236240
const selector = getSelectorFromElement(selectorTarget, configuration.actionNameAttribute)
237-
241+
const composedPathSelector = getComposedPathSelector(
242+
eventPath,
243+
configuration.actionNameAttribute,
244+
configuration.allowedHtmlAttributes || []
245+
)
238246
if (selector) {
239247
updateInteractionSelector(event.timeStamp, selector)
240248
}
@@ -248,6 +256,7 @@ function computeClickActionBase(
248256
width: Math.round(rect.width),
249257
height: Math.round(rect.height),
250258
selector,
259+
composed_path_selector: composedPathSelector ?? undefined,
251260
},
252261
position: {
253262
// Use clientX and Y because for SVG element offsetX and Y are relatives to the <svg> element

packages/rum-core/src/domain/configuration/configuration.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ describe('serializeRumConfiguration', () => {
631631
profilingSampleRate: 42,
632632
propagateTraceBaggage: true,
633633
betaTrackActionsInShadowDom: true,
634+
allowedHtmlAttributes: ['data-testid'],
634635
}
635636

636637
type MapRumInitConfigurationKey<Key extends string> = Key extends keyof InitConfiguration
@@ -687,6 +688,7 @@ describe('serializeRumConfiguration', () => {
687688
remote_configuration_id: '123',
688689
use_remote_configuration_proxy: true,
689690
profiling_sample_rate: 42,
691+
allowed_html_attributes: ['data-testid'],
690692
})
691693
})
692694
})

packages/rum-core/src/domain/configuration/configuration.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,15 @@ export interface RumInitConfiguration extends InitConfiguration {
281281
* @category Data Collection
282282
*/
283283
allowedGraphQlUrls?: Array<MatchOption | GraphQlUrlOption> | undefined
284+
285+
/**
286+
* A list of HTML attributes allowed to be used in the action selector collection.
287+
* Matches attributes against the event target and its ancestors.
288+
* If not provided, the SDK will use a default list of HTML attributes.
289+
*
290+
* @category Data Collection
291+
*/
292+
allowedHtmlAttributes?: MatchOption[] | undefined
284293
}
285294

286295
export type HybridInitConfiguration = Omit<RumInitConfiguration, 'applicationId' | 'clientToken'>
@@ -321,6 +330,7 @@ export interface RumConfiguration extends Configuration {
321330
profilingSampleRate: number
322331
propagateTraceBaggage: boolean
323332
allowedGraphQlUrls: GraphQlUrlOption[]
333+
allowedHtmlAttributes?: MatchOption[]
324334
}
325335

326336
export function validateAndBuildRumConfiguration(
@@ -400,6 +410,9 @@ export function validateAndBuildRumConfiguration(
400410
profilingSampleRate: initConfiguration.profilingSampleRate ?? 0,
401411
propagateTraceBaggage: !!initConfiguration.propagateTraceBaggage,
402412
allowedGraphQlUrls,
413+
allowedHtmlAttributes: Array.isArray(initConfiguration.allowedHtmlAttributes)
414+
? initConfiguration.allowedHtmlAttributes.filter(isMatchOption)
415+
: [],
403416
...baseConfiguration,
404417
}
405418
}

0 commit comments

Comments
 (0)