From 2614acdada4aab2d10f896ef627bff882f2bf2b8 Mon Sep 17 00:00:00 2001 From: Okan Sahin <39759830+mokimo@users.noreply.github.com> Date: Thu, 13 Jun 2024 18:08:33 +0200 Subject: [PATCH] Increase 404 rum tracking to 10% (#2448) * 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 --- libs/scripts/scripts.js | 2 ++ libs/utils/samplerum.js | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libs/scripts/scripts.js b/libs/scripts/scripts.js index 154e81967c..3fce88cd92 100644 --- a/libs/scripts/scripts.js +++ b/libs/scripts/scripts.js @@ -14,6 +14,7 @@ import { loadArea, loadLana, setConfig, + getMetadata, } from '../utils/utils.js'; // Production Domain @@ -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' }); diff --git a/libs/utils/samplerum.js b/libs/utils/samplerum.js index 652a13bd06..58f0ec07aa 100644 --- a/libs/utils/samplerum.js +++ b/libs/utils/samplerum.js @@ -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, @@ -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;