Skip to content

Commit 663461d

Browse files
committed
Add element
1 parent d36a31e commit 663461d

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,14 @@ interface INPAttribution {
902902
*/
903903
interactionTarget: string;
904904

905+
/**
906+
* A node identifying the element that the user first interacted with
907+
* as part of the frame where the INP candidate interaction occurred.
908+
* If `interactionTargetElement` is null, that generally means the
909+
* element was removed from the DOM after the interaction.
910+
*/
911+
interactionTargetElement?: Node;
912+
905913
/**
906914
* The time when the user first interacted during the frame where the INP
907915
* candidate interaction occurred (if more than one interaction occurred

src/attribution/onINP.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,10 @@ const attributeINP = (metric: INPMetric): INPMetricWithAttribution => {
236236
// https://bugs.chromium.org/p/chromium/issues/detail?id=1367329
237237
// We also fallback to interactionTargetMap for when target removed from DOM
238238
const firstEntryWithTarget = metric.entries.find((entry) => entry.target);
239-
const interactionTarget = firstEntryWithTarget
240-
? getSelector(firstEntryWithTarget.target)
241-
: getSelector(interactionTargetMap.get(firstEntry.interactionId)) || '';
239+
const interactionTargetElement =
240+
firstEntryWithTarget?.target ||
241+
interactionTargetMap.get(firstEntry.interactionId);
242+
const interactionTarget = getSelector(interactionTargetElement);
242243

243244
// Since entry durations are rounded to the nearest 8ms, we need to clamp
244245
// the `nextPaintTime` value to be higher than the `processingEnd` or
@@ -254,6 +255,7 @@ const attributeINP = (metric: INPMetric): INPMetricWithAttribution => {
254255

255256
const attribution: INPAttribution = {
256257
interactionTarget: interactionTarget,
258+
interactionTargetElement: interactionTargetElement,
257259
interactionType: firstEntry.name.startsWith('key') ? 'keyboard' : 'pointer',
258260
interactionTime: firstEntry.startTime,
259261
nextPaintTime: nextPaintTime,

src/types/inp.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ export interface INPAttribution {
3838
*/
3939
interactionTarget: string;
4040

41+
/**
42+
* A node identifying the element that the user first interacted with
43+
* as part of the frame where the INP candidate interaction occurred.
44+
* If `interactionTargetElement` is null, that generally means the
45+
* element was removed from the DOM after the interaction.
46+
*/
47+
interactionTargetElement?: Node;
48+
4149
/**
4250
* The time when the user first interacted during the frame where the INP
4351
* candidate interaction occurred (if more than one interaction occurred

test/e2e/onINP-test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,11 @@ describe('onINP()', async function () {
668668
await stubVisibilityChange('hidden');
669669
await beaconCountIs(1);
670670

671-
const [inp1] = await getBeacons();
671+
const [inp] = await getBeacons();
672672

673-
assert.equal(inp1.attribution.interactionType, 'pointer');
674-
assert.equal(inp1.attribution.interactionTarget, '#reset');
673+
assert.equal(inp.attribution.interactionType, 'pointer');
674+
assert.equal(inp.attribution.interactionTarget, '#reset');
675+
assert(inp.attribution.interactionTargetElement);
675676
});
676677

677678
it('includes LoAF entries if the browser supports it', async function () {

0 commit comments

Comments
 (0)