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

Increase 404 rum tracking to 10% #2448

Merged
merged 7 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libs/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@
}());

(async function loadPage() {
if (document.head.querySelector('meta[name="template"]')?.content === '404') {
mokimo marked this conversation as resolved.
Show resolved Hide resolved
window.SAMPLE_PAGEVIEWS_AT_RATE = 'high';
}

Check warning on line 166 in libs/scripts/scripts.js

View check run for this annotation

Codecov / codecov/patch

libs/scripts/scripts.js#L165-L166

Added lines #L165 - L166 were not covered by tests
performance.mark('loadpage');
setConfig(config);
loadLana({ clientId: 'milo' });
Expand Down
6 changes: 4 additions & 2 deletions libs/utils/samplerum.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ export function sampleRUM(checkpoint, data = {}) {
try {
window.hlx = window.hlx || {};
if (!window.hlx.rum) {
const usp = new URLSearchParams(window.location.search);
const weight = (usp.get('rum') === 'on') ? 1 : 100; // with parameter, weight is 1. Defaults to 100.
const weight = (window.SAMPLE_PAGEVIEWS_AT_RATE === 'high' && 10)
|| (window.SAMPLE_PAGEVIEWS_AT_RATE === 'low' && 1000)
|| (new URLSearchParams(window.location.search).get('rum') === 'on' && 1)
|| 100;
const id = Array.from({ length: 75 }, (_, i) => String.fromCharCode(48 + i)).filter((a) => /\d|[A-Z]/i.test(a)).filter(() => Math.random() * 75 > 70).join('');
mokimo marked this conversation as resolved.
Show resolved Hide resolved
const random = Math.random();
const isSelected = (random * weight < 1);
Expand Down
Loading