Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mokimo committed Aug 6, 2024
1 parent c7353cb commit a0316b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
8 changes: 3 additions & 5 deletions libs/utils/logWebVitals.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const LANA_CLIENT_ID = 'pageperf';

let lanaSent = false;
let lanaSent;

function sendToLana(lanaData) {
if (lanaSent) return;
const ua = window.navigator.userAgent;

Object.assign(lanaData, {
chromeVer: (ua.match(/Chrome\/(\d+\.\d+\.\d+\.\d+)/) || [])[1] || '',
chromeVer: ua.match(/Chrome\/(\d+\.\d+\.\d+\.\d+)/)?.[1] || '',
country: sessionStorage.getItem('akamai') || '',
// eslint-disable-next-line compat/compat
downlink: window.navigator?.connection?.downlink || '',
Expand Down Expand Up @@ -41,9 +41,7 @@ function observeCLS(lanaData) {
/* c8 ignore start */
new PerformanceObserver((entryList) => {
for (const entry of entryList.getEntries()) {
if (!entry.hadRecentInput) {
cls += entry.value;
}
if (!entry.hadRecentInput) cls += entry.value;
}
lanaData.cls = cls.toPrecision(4);
}).observe({ type: 'layout-shift', buffered: true });
Expand Down
13 changes: 5 additions & 8 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,18 +999,15 @@ export function scrollToHashedElement(hash) {
}

function logPagePerf() {
if (getMetadata('pageperf') !== 'on') return;
const isChrome = () => {
const nav = window.navigator;
return nav.userAgent.includes('Chrome') && nav.vendor.includes('Google');
};

if (getMetadata('pageperf') === 'on' && isChrome()) {
const sampleRate = parseInt(getMetadata('pageperf-rate'), 10) || 50;
if (Math.random() * 100 <= sampleRate) {
import('./logWebVitals.js')
.then((mod) => mod.default(getConfig().mep, getMetadata('pageperf-delay') || 1000));
}
}
const sampleRate = parseInt(getMetadata('pageperf-rate'), 10) || 50;
if (!isChrome() || Math.random() * 100 > sampleRate) return;
import('./logWebVitals.js')
.then((mod) => mod.default(getConfig().mep, getMetadata('pageperf-delay') || 1000));
}

export async function loadDeferred(area, blocks, config) {
Expand Down

0 comments on commit a0316b4

Please sign in to comment.