-
Notifications
You must be signed in to change notification settings - Fork 15
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,10 +34,16 @@ const blocksMO = window.MutationObserver ? new MutationObserver(blocksMCB) | |
// eslint-disable-next-line no-use-before-define, max-len | ||
const mediaMO = window.MutationObserver ? new MutationObserver(mediaMCB) | ||
/* c8 ignore next */ : {}; | ||
/** | ||
* Maximum number of events. The first call will be made by rum-js, | ||
* leaving 1023 events for the enhancer to track | ||
*/ | ||
let maxEvents = 1023; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would document why 1023... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments are removed thus all good. |
||
|
||
function trackCheckpoint(checkpoint, data, t) { | ||
const { weight, id } = window.hlx.rum; | ||
if (isSelected) { | ||
if (isSelected && maxEvents) { | ||
maxEvents -= 1; | ||
const sendPing = (pdata = data) => { | ||
// eslint-disable-next-line object-curly-newline, max-len | ||
const body = JSON.stringify({ weight, id, referer: urlSanitizers[window.hlx.RUM_MASK_URL || 'path'](), checkpoint, t, ...data }, KNOWN_PROPERTIES); | ||
|
@@ -301,17 +307,10 @@ function mediaMCB(mutations) { | |
} | ||
|
||
function addTrackingFromConfig() { | ||
let lastSource; | ||
let lastTarget; | ||
document.addEventListener('click', (event) => { | ||
const source = sourceSelector(event.target); | ||
const target = targetSelector(event.target); | ||
if (source !== lastSource || target !== lastTarget) { | ||
sampleRUM('click', { target, source }); | ||
lastSource = source; | ||
lastTarget = target; | ||
} | ||
sampleRUM('click', { target: targetSelector(event.target), source: sourceSelector(event.target) }); | ||
}); | ||
|
||
addCWVTracking(); | ||
addFormTracking(window.document.body); | ||
addNavigationTracking(); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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 ofMAX_EVENTS
. If using const is recommended, then I'll do something likePlease let me know if this way is preferred.