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

fix: Implement flood control with 1024 max events #359

Merged
merged 4 commits into from
Feb 3, 2025

Conversation

rpapani
Copy link
Collaborator

@rpapani rpapani commented Jan 18, 2025

If the end users are clicking on an element repetitively, it typically indicates a problem like broken experience, confusing UI etc. #339 introduced to not to track the repeating clicks, because of which we won't be able to find some of the issues faced by users.

Currently, PSS considers if the user is clicking 10 times on the same selector with in the same session, we'll record as a rageclick (naming is little different in PSS) and based on such instances, we'll create an opportunity for our customers to fix. For PSS to continue to find these blind clicks and help our customers, we'd like to have the repeating clicks collected as valid RUM checkpoints.

This PR will introduce the flood control to limit the max events collection to 1024.

Related PRs - #339

@kptdobe
Copy link
Contributor

kptdobe commented Jan 20, 2025

#339 has been introduced because we saw quite a lot of "clicks go crazy" where several hundreds or even thousands were collected on some random elements. I agree that the fix provided back then is pretty limiting (only one click per element is tracked) and I agree with your potential fix.

I am not sure that you will be able to deduct a rageclick: because of these unreproducible and completely random "clicks go crazy" (my suspicion is browser bug or a bug in some 3rd party injected JS code), you will only be able to report "too many (frequent) clicks on this element" which will require investigations. At least, it will give you a start point to investigate.

Let's see what this gives us.

@rpapani rpapani changed the title fix: collect repeating clicks upto max configuration fix: Implement flood control with 1024 max events Jan 30, 2025
@@ -35,9 +35,12 @@ const blocksMO = window.MutationObserver ? new MutationObserver(blocksMCB)
const mediaMO = window.MutationObserver ? new MutationObserver(mediaMCB)
/* c8 ignore next */ : {};

let maxEvents = 1023;
Copy link
Collaborator Author

@rpapani rpapani Jan 30, 2025

Choose a reason for hiding this comment

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

@trieloff Since I'm decrementing this, using maxEvents instead of MAX_EVENTS. If using const is recommended, then I'll do something like

const MAX_EVENTS = 1023;
let maxEvents = MAX_EVENTS;

Please let me know if this way is preferred.

@trieloff trieloff requested a review from kptdobe January 31, 2025 08:43
Copy link
Contributor

@trieloff trieloff left a comment

Choose a reason for hiding this comment

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

looks good so far.

modules/index.js Outdated
function trackCheckpoint(checkpoint, data, t) {
const { weight, id } = window.hlx.rum;
if (isSelected) {
if (isSelected && maxEvents > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (isSelected && maxEvents > 0) {
if (isSelected && --maxEvents > 0) {

If ESLint doesn't complain, then I'd one-liner this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (isSelected && maxEvents > 0) {
if (isSelected && --maxEvents) {

every byte counts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, lint is complaining for no-plusplus, so, either we need to add the eslint-disable or avoid --, I'll be using the latter.

a.click();
await new Promise((resolve) => setTimeout(resolve, 1));
}
assert(window.events.length === 1024 , '1024th event should not trigger new checkpoint');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert(window.events.length === 1024 , '1024th event should not trigger new checkpoint');
assert(window.events.length === 1024 , '1025th event should not trigger new checkpoint');

Copy link
Contributor

@kptdobe kptdobe left a comment

Choose a reason for hiding this comment

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

This still has an impact: if the click goes crazy, we might not track the rest. Probably an edge case but once live, we should look at data and see how frequent it is we hit the limit and what's the impact of those crazy clicks.

@@ -35,9 +35,12 @@ const blocksMO = window.MutationObserver ? new MutationObserver(blocksMCB)
const mediaMO = window.MutationObserver ? new MutationObserver(mediaMCB)
/* c8 ignore next */ : {};

let maxEvents = 1023;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would document why 1023...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like we've a byte limit, so adding the documentation may take more. Is it ok to add that in the commit?
@trieloff WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Comments are removed thus all good.

@rpapani rpapani merged commit ddfdb1e into adobe:main Feb 3, 2025
7 checks passed
@rpapani rpapani deleted the blind-clicks branch February 3, 2025 17:18
@adobe-bot
Copy link
Collaborator

🎉 This PR is included in version 2.30.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@adobe-bot
Copy link
Collaborator

🎉 This PR is included in version 2.31.0-beta.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants