Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save INP target after interactions to reduce null values when removed from the DOM #477

Merged
merged 11 commits into from May 10, 2024

Conversation

tunetheweb
Copy link
Member

@tunetheweb tunetheweb commented May 9, 2024

Makes progress on #335

When a target element is removed from the DOM it cannot be looked up to get the CSS selector.

There are instances when the first-input and pointer-down events provide a target element, but the later pointerup and click events do not as the element has been removed. This is even more apparent in v4 where we wait to attribute INP until idle.

This PR saves a target reference for each event with an interaction id, so it can be retrieved later if the target is then null.

This will not help if the element is removed before the first event entry from that interactionId is reported so is not a full solution, but will help in some cases.

Copy link
Member

@mmocny mmocny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change so quick.

src/attribution/onINP.ts Outdated Show resolved Hide resolved
@gilbertococchi
Copy link

Thanks for fixing this Barry!
Lots of Target nulls due to CMP UI Click should go away with this change!

@tunetheweb
Copy link
Member Author

tunetheweb commented May 9, 2024

Don't get too excited just yet. I'm having dropping making this work in the general case. Not sure how it works on your site to be honest :-(

@tunetheweb tunetheweb changed the title Save INP CSS selector early for when target removed from DOM Save INP target early for when removed from DOM May 10, 2024
@tunetheweb tunetheweb requested a review from mmocny May 10, 2024 06:00
@gilbertococchi
Copy link

Don't get too excited just yet. I'm having dropping making this work in the general case. Not sure how it works on your site to be honest :-(

Thanks Barry, you know me well :)

I just did test out this change on few CMP scenarios and it seems work correctly, happy to test out more scenarios as well today.

@tunetheweb
Copy link
Member Author

@philipwalton with the latest change to keep the element, I think it makes sense to expose this as requested in #456 so I added that in 663461d. Technically another change to the API but as it's an addition I don't think we need another release candidate for this. WDYT?

Copy link
Member

@philipwalton philipwalton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tunetheweb LGTM with a few changes from me (that we discussed offline). Feel free to merge if you're happy with my changes.

@tunetheweb tunetheweb merged commit 14d3e1d into v4 May 10, 2024
6 checks passed
@tunetheweb tunetheweb deleted the capture-target-selector-early branch May 10, 2024 20:26
@tunetheweb tunetheweb changed the title Save INP target early for when removed from DOM Save INP target to allow reporting when removed from DOM in more cases May 13, 2024
@philipwalton philipwalton changed the title Save INP target to allow reporting when removed from DOM in more cases Save INP target after interactions to reduce null values when removed from the DOM May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants