Skip to content

Commit

Permalink
Increase 404 rum tracking to 10% (#2448)
Browse files Browse the repository at this point in the history
* Increase 404 rum tracking to 10%

* Address feedback

* Address feedback

* Increase the general tracking weight for 404 pages

* Increase tracking for 404s

* Improve ID creation

* Use getMetadata
  • Loading branch information
mokimo authored Jun 13, 2024
1 parent 3d61c97 commit 2614acd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
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

0 comments on commit 2614acd

Please sign in to comment.