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 all 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
2 changes: 2 additions & 0 deletions libs/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
loadArea,
loadLana,
setConfig,
getMetadata,
} from '../utils/utils.js';

// Production Domain
Expand Down Expand Up @@ -161,6 +162,7 @@ const eagerLoad = (img) => {
}());

(async function loadPage() {
if (getMetadata('template') === '404') window.SAMPLE_PAGEVIEWS_AT_RATE = 'high';
performance.mark('loadpage');
setConfig(config);
loadLana({ clientId: 'milo' });
Expand Down
13 changes: 7 additions & 6 deletions libs/utils/samplerum.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ 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 id = Array.from({ length: 75 }, (_, i) => String.fromCharCode(48 + i)).filter((a) => /\d|[A-Z]/i.test(a)).filter(() => Math.random() * 75 > 70).join('');
const random = Math.random();
const isSelected = (random * weight < 1);
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 = Math.random().toString(36).slice(-4);
const isSelected = (Math.random() * weight < 1);
const firstReadTime = Date.now();
const urlSanitizers = {
full: () => window.location.href,
Expand All @@ -44,7 +45,7 @@ export function sampleRUM(checkpoint, data = {}) {
rumSessionStorage.pages = rumSessionStorage.pages ? rumSessionStorage.pages + 1 : 1;
sessionStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(rumSessionStorage));
// eslint-disable-next-line object-curly-newline, max-len
window.hlx.rum = { weight, id, random, isSelected, firstReadTime, sampleRUM, sanitizeURL: urlSanitizers[window.hlx.RUM_MASK_URL || 'path'], rumSessionStorage };
window.hlx.rum = { weight, id, isSelected, firstReadTime, sampleRUM, sanitizeURL: urlSanitizers[window.hlx.RUM_MASK_URL || 'path'], rumSessionStorage };
}

const { weight, id, firstReadTime } = window.hlx.rum;
Expand Down
Loading